Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bai 1456 fix model and datacard tab loading #1796

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

IR96334
Copy link
Member

@IR96334 IR96334 commented Jan 28, 2025

No description provided.

{!dataCard || isDataCardLoading || isCurrentUserLoading || isUiConfigLoading ? (
<Loading />
) : (
dataCard && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nesting additional conditional logic within a ternary is generally considered something to avoid, simply for the fact that it becomes difficult to read.

In this case it's unnecessary to include the dataCard && condition due to the fact that if the first check (which includes the condition !dataCard) returns false, then dataCard must be truthy (i.e. not undefined in this case).

Also, and this is my fault, the loading condition for data cards is simpler than models. That's my mistake for not clarifying in the ticket.

In short, you can do the following:

      {!dataCard || isDataCardLoading ? (
        <Loading />
      ) : (
        <PageWithTabs
          title={dataCard.name}
          subheading={`ID: ${dataCard.id}`}
          tabs={tabs}
          requiredUrlParams={{ dataCardId: dataCard.id }}
          titleToCopy={dataCard.name}
          subheadingToCopy={dataCard.id}
        />
      )}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense as the and operator is doing the same thing as my ternary operator so its redundant.

{!model || isModelLoading || isCurrentUserLoading || isUiConfigLoading ? (
<Loading />
) : (
model && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we don't need this second condition to check the model exists. If it fails the first check then we know the model exists.

      {!model || isModelLoading || isCurrentUserLoading || isUiConfigLoading ? (
        <Loading />
      ) : (
        <PageWithTabs
          title={model.name}
          subheading={`ID: ${model.id}`}
          additionalInfo={model.description}
          tabs={tabs}
          displayActionButton={model.card !== undefined}
          actionButtonTitle='Request access'
          actionButtonOnClick={requestAccess}
          requiredUrlParams={{ modelId: model.id }}
          titleToCopy={model.name}
          subheadingToCopy={model.id}
          sourceModelId={model.settings.mirror?.sourceModelId}
        />
      )}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -18,6 +20,8 @@ export default function DataCard() {
isModelLoading: isDataCardLoading,
isModelError: isDataCardError,
} = useGetModel(dataCardId, EntryKind.DATA_CARD)
const { isCurrentUserLoading } = useGetCurrentUser()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two hooks aren't needed for data cards. Apologies for the ticket being unclear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@IR96334 IR96334 requested a review from ARADDCC012 January 29, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants