Skip to content

Commit

Permalink
Merge pull request #1157 from securityscorecard/ajkl2533@UXD-1642
Browse files Browse the repository at this point in the history
fix(DatatableV2): use skeleton for rows counters
  • Loading branch information
ajkl2533 authored Oct 2, 2024
2 parents 6c89b93 + c034c7b commit c3d0ab6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 19 additions & 14 deletions src/components/DatatableV2/toolbar/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DatatableInstance } from '../Datatable.types';
import { useContainerQuery } from '../../../hooks/useContainerQuery';
import IconButton from '../../ButtonV2/IconButton';
import { useSafeTranslation } from '../../../hooks/useSafeTranslation';
import { Skeleton } from '../../Skeleton';

const cq = {
sm: {
Expand Down Expand Up @@ -37,7 +38,7 @@ const Pagination = <D,>({ table }: { table: DatatableInstance<D> }) => {
setPageIndex,
setPageSize,
} = table;
const { pagination } = getState();
const { pagination, isLoading } = getState();
const { pageIndex, pageSize } = pagination;

const currentPage = pageIndex + 1;
Expand All @@ -60,19 +61,23 @@ const Pagination = <D,>({ table }: { table: DatatableInstance<D> }) => {
>
<Inline align="center" gap="md" justify="space-between">
<div className="ds-table-pagination-item-count">
{isLg
? t('sscds|datatable.pagination.itemCounter.full', {
firstRowIndex: (firstRowIndex + 1).toLocaleString(lng),
lastRowIndex: lastRowIndex.toLocaleString(lng),
totalRowCount: abbreviateNumber(totalRowCount, lng),
count: totalRowCount,
})
: t('sscds|datatable.pagination.itemCounter.short', {
firstRowIndex: (firstRowIndex + 1).toLocaleString(lng),
lastRowIndex: lastRowIndex.toLocaleString(lng),
totalRowCount: abbreviateNumber(totalRowCount, lng),
count: totalRowCount,
})}
{isLoading ? (
<Skeleton width={120} />
) : isLg ? (
t('sscds|datatable.pagination.itemCounter.full', {
firstRowIndex: (firstRowIndex + 1).toLocaleString(lng),
lastRowIndex: lastRowIndex.toLocaleString(lng),
totalRowCount: abbreviateNumber(totalRowCount, lng),
count: totalRowCount,
})
) : (
t('sscds|datatable.pagination.itemCounter.short', {
firstRowIndex: (firstRowIndex + 1).toLocaleString(lng),
lastRowIndex: lastRowIndex.toLocaleString(lng),
totalRowCount: abbreviateNumber(totalRowCount, lng),
count: totalRowCount,
})
)}
</div>
<Inline
align="center"
Expand Down
21 changes: 14 additions & 7 deletions src/components/DatatableV2/toolbar/TopToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Text } from '../../Text';
import { DatatableInstance } from '../Datatable.types';
import { abbreviateNumber } from '../../../utils';
import { useSafeTranslation } from '../../../hooks/useSafeTranslation';
import { Skeleton } from '../../Skeleton';

const TopToolbarRoot = styled(Padbox)`
border-bottom: 1px solid var(--sscds-table-color-border);
Expand All @@ -33,7 +34,7 @@ function TopToolbar<D>({ table }: { table: DatatableInstance<D> }) {
setShowColumnSettings,
setIsFullscreenMode,
} = table;
const { isFullscreenMode, columnVisibility } = getState();
const { isFullscreenMode, columnVisibility, isLoading } = getState();
const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
const hiddenColumns = getHiddenColumns(columnVisibility);
const { t, lng } = useSafeTranslation();
Expand All @@ -48,12 +49,18 @@ function TopToolbar<D>({ table }: { table: DatatableInstance<D> }) {
return (
<TopToolbarRoot paddingSize="md" paddingType="squish">
<Inline align="center" gap="2x" stretch="start">
<Text>
{t('sscds|datatable.topToolbar.itemCounter', {
count: totalRowCount,
totalRowCount: abbreviateNumber(totalRowCount, lng),
})}
</Text>
{isLoading ? (
<div>
<Skeleton width={80} />
</div>
) : (
<Text>
{t('sscds|datatable.topToolbar.itemCounter', {
count: totalRowCount,
totalRowCount: abbreviateNumber(totalRowCount, lng),
})}
</Text>
)}
{enableHiding && hiddenColumns > 0 && (
<Text variant="subtle">
{t('sscds|datatable.topToolbar.hiddenColumns', {
Expand Down

0 comments on commit c3d0ab6

Please sign in to comment.