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

fix(DatatableV2): use skeleton for rows counters #1157

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading