Skip to content

Commit

Permalink
Regression: Users Table loading state (#26079)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Jun 30, 2022
1 parent b03d848 commit cb7c9a9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 67 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/client/components/GenericModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getButtonProps = (variant: VariantType): ComponentProps<typeof Button> =>
case 'danger':
return { danger: true };
case 'warning':
return { warning: true };
return { primary: true };
default:
return {};
}
Expand Down
126 changes: 60 additions & 66 deletions apps/meteor/client/views/admin/users/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,90 +70,84 @@ const UsersTable = ({ reload }: UsersTableProps): ReactElement | null => {
}),
);

const headers = useMemo(
() => [
<GenericTableHeaderCell w='x200' key='name' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name'>
{t('Name')}
</GenericTableHeaderCell>,
mediaQuery && (
<GenericTableHeaderCell
w='x140'
key='username'
direction={sortDirection}
active={sortBy === 'username'}
onClick={setSort}
sort='username'
>
{t('Username')}
</GenericTableHeaderCell>
),
<GenericTableHeaderCell
w='x120'
key='email'
direction={sortDirection}
active={sortBy === 'emails.address'}
onClick={setSort}
sort='emails.address'
>
{t('Email')}
</GenericTableHeaderCell>,
mediaQuery && (
<GenericTableHeaderCell w='x120' key='roles' onClick={setSort}>
{t('Roles')}
</GenericTableHeaderCell>
),
<GenericTableHeaderCell w='x100' key='status' direction={sortDirection} active={sortBy === 'status'} onClick={setSort} sort='status'>
{t('Status')}
</GenericTableHeaderCell>,
],
[mediaQuery, setSort, sortBy, sortDirection, t],
);

if (phase === AsyncStatePhase.REJECTED) {
return null;
}

return (
<>
<FilterByText placeholder={t('Search_Users')} onChange={({ text }): void => setText(text)} />
{value?.users.length === 0 && (
<States>
<StatesIcon name='magnifier' />
<StatesTitle>{t('No_results_found')}</StatesTitle>
</States>
{phase === AsyncStatePhase.LOADING && (
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>{phase === AsyncStatePhase.LOADING && <GenericTableLoadingTable headerCells={5} />}</GenericTableBody>
</GenericTable>
)}
{value?.users && value.users.length > 0 && (
{value?.users && value.users.length > 0 && phase === AsyncStatePhase.RESOLVED && (
<>
<GenericTable>
<GenericTableHeader>
<GenericTableHeaderCell
w='x200'
key='name'
direction={sortDirection}
active={sortBy === 'name'}
onClick={setSort}
sort='name'
>
{t('Name')}
</GenericTableHeaderCell>
{mediaQuery && (
<GenericTableHeaderCell
w='x140'
key='username'
direction={sortDirection}
active={sortBy === 'username'}
onClick={setSort}
sort='username'
>
{t('Username')}
</GenericTableHeaderCell>
)}
<GenericTableHeaderCell
w='x120'
key='email'
direction={sortDirection}
active={sortBy === 'emails.address'}
onClick={setSort}
sort='emails.address'
>
{t('Email')}
</GenericTableHeaderCell>
{mediaQuery && (
<GenericTableHeaderCell w='x120' key='roles' onClick={setSort}>
{t('Roles')}
</GenericTableHeaderCell>
)}
<GenericTableHeaderCell
w='x100'
key='status'
direction={sortDirection}
active={sortBy === 'status'}
onClick={setSort}
sort='status'
>
{t('Status')}
</GenericTableHeaderCell>
</GenericTableHeader>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{phase === AsyncStatePhase.LOADING && <GenericTableLoadingTable headerCells={5} />}
{value?.users.map((user) => (
<UsersTableRow key={user._id} onClick={handleClick} mediaQuery={mediaQuery} user={user} />
))}
</GenericTableBody>
</GenericTable>
{phase === AsyncStatePhase.RESOLVED && (
<Pagination
current={current}
itemsPerPage={itemsPerPage}
count={value?.total || 0}
onSetItemsPerPage={onSetItemsPerPage}
onSetCurrent={onSetCurrent}
{...paginationProps}
/>
)}
<Pagination
current={current}
itemsPerPage={itemsPerPage}
count={value?.total || 0}
onSetItemsPerPage={onSetItemsPerPage}
onSetCurrent={onSetCurrent}
{...paginationProps}
/>
</>
)}
{phase === AsyncStatePhase.RESOLVED && value?.users.length === 0 && (
<States>
<StatesIcon name='magnifier' />
<StatesTitle>{t('No_results_found')}</StatesTitle>
</States>
)}
</>
);
};
Expand Down

0 comments on commit cb7c9a9

Please sign in to comment.