Skip to content

Commit

Permalink
Fix logic for loading, error, and dataLoaded cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuje committed Nov 4, 2024
1 parent 013d9cb commit e40b13b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 105 deletions.
52 changes: 4 additions & 48 deletions src/components/Dashboard/dashboard-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const DashboardTable: React.FunctionComponent<DasboardTableProps> = ({ ro

React.useEffect(() => {
setSortedRows(sortedData.slice((page - 1) * perPage, page * perPage));
}, [sortedData, page, perPage]);
}, [sortedData, page, perPage, rows]);

const handleSetPage = (_evt: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => {
setPage(newPage);
Expand Down Expand Up @@ -221,52 +221,6 @@ export const DashboardTable: React.FunctionComponent<DasboardTableProps> = ({ ro
));
};

const EmptyPullRequestState = () => {
return (
<EmptyState>
<EmptyStateHeader
titleText="Welcome to InstructLab"
headingLevel="h4"
icon={<Image src="/InstructLab-LogoFile-RGB-FullColor.svg" alt="InstructLab Logo" width={256} height={256} />}
/>
<EmptyStateBody>
<div style={{ maxWidth: '60ch' }}>
InstructLab is a powerful and accessible tool for advancing generative AI through community collaboration and open-source principles. By
contributing your own data, you can help train and refine the language model. <br />
<br />
To get started, contribute a skill or contribute knowledge.
</div>
</EmptyStateBody>
<EmptyStateFooter>
<EmptyStateActions>
<Button variant="primary" onClick={() => router.push('/contribute/skill')}>
Contribute Skill
</Button>
<Button variant="primary" onClick={() => router.push('/contribute/knowledge')}>
Contribute Knowledge
</Button>
<Button variant="primary" onClick={() => router.push('/playground/chat')}>
Chat with the Models
</Button>
</EmptyStateActions>
<EmptyStateActions>
<Button
variant="link"
icon={<GithubIcon />}
iconPosition="right"
component="a"
href="https://github.com/instructlab"
target="_blank"
rel="noopener noreferrer"
>
View the Project on Github
</Button>
</EmptyStateActions>
</EmptyStateFooter>
</EmptyState>
);
};

const TableData = () => {
if (error) {
return <ErrorState />;
Expand All @@ -279,6 +233,8 @@ export const DashboardTable: React.FunctionComponent<DasboardTableProps> = ({ ro
};

return (
// LEFT OFF HERE
// if FirstPullDone && !error && rows.length === 0 : then render the FirstPR
<Card component="div">
{renderPagination('bottom', false)}
<Table aria-label="Sortable Table" ouiaId="SortableTable">
Expand All @@ -295,7 +251,7 @@ export const DashboardTable: React.FunctionComponent<DasboardTableProps> = ({ ro
columnIndex
}
};
if (columnName === 'Title') {
if (columnName === 'Title' || columnName === 'Status' || columnName === 'Created' || columnName === 'Updated') {
return (
<Th
modifier={columnIndex !== 6 ? 'wrap' : undefined}
Expand Down
74 changes: 17 additions & 57 deletions src/components/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ const Index: React.FunctionComponent = () => {

console.log({ pullRequests, isFirstPullDone, error });

function sleep(delay: number) {
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, delay);
});
}

const fetchAndSetPullRequests = React.useCallback(async () => {
if (session?.accessToken) {
try {
Expand All @@ -110,8 +118,11 @@ const Index: React.FunctionComponent = () => {
} catch (error) {
setError(error as string);
}

// Jz: for testing only
await sleep(5000);

setIsFirstPullDone(true);
setIsLoading(false);
}
}, [session?.accessToken]);

Expand Down Expand Up @@ -222,72 +233,21 @@ const Index: React.FunctionComponent = () => {
</PageSection>
<PageSection>
<div style={{ marginBottom: '20px' }} />
<DashboardTable isFirstPullDone={isFirstPullDone} error={error} rows={pullRequests} />
{/* {!isFirstPullDone && (
<Modal variant={ModalVariant.large} title="Retrieving your submissions" isOpen={isLoading} onClose={() => handleOnClose()}>
<div>
<Spinner size="lg" />
Loading
</div>
</Modal>
)}
)} */}
{pullRequests.length === 0 ? (
<EmptyState>
<EmptyStateHeader
titleText="Welcome to InstructLab"
headingLevel="h4"
icon={
<div>
<Image src="/InstructLab-LogoFile-RGB-FullColor.svg" alt="InstructLab Logo" width={256} height={256} />
</div>
}
/>
<EmptyStateBody>
<div style={{ maxWidth: '60ch' }}>
InstructLab is a powerful and accessible tool for advancing generative AI through community collaboration and open-source principles.
By contributing your own data, you can help train and refine the language model. <br />
<br />
To get started, contribute a skill or contribute knowledge.
</div>
</EmptyStateBody>
<EmptyStateFooter>
<EmptyStateActions>
<Button variant="primary" onClick={() => router.push('/contribute/skill')}>
Contribute Skill
</Button>
<Button variant="primary" onClick={() => router.push('/contribute/knowledge')}>
Contribute Knowledge
</Button>
<Button variant="primary" onClick={() => router.push('/playground/chat')}>
Chat with the Models
</Button>
</EmptyStateActions>
<EmptyStateActions>
<Button
variant="link"
icon={<GithubIcon />}
iconPosition="right"
component="a"
href="https://github.com/instructlab"
target="_blank"
rel="noopener noreferrer"
>
View the Project on Github
</Button>
</EmptyStateActions>
</EmptyStateFooter>
</EmptyState>
<EmptyPullRequestState />
) : (
<Stack hasGutter>
{error ? (
<ErrorState
errorTitle="Unable to Connect"
errorDescription="There was an error retrieving data. Check your connection and reload the page"
/>
) : (
<DashboardTable isFirstPullDone={isFirstPullDone} isLoading={isLoading} error={error} rows={pullRequests} />
)}
</Stack> */}
<DashboardTable isFirstPullDone={isFirstPullDone} error={error} rows={pullRequests} />
</Stack>
)}
</PageSection>
</div>
);
Expand Down

0 comments on commit e40b13b

Please sign in to comment.