catalog: refactor CatalogTable
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
@@ -123,7 +123,6 @@ const defaultColumnsFunc: CatalogTableColumnsFunc = ({ filters, entities }) => {
|
||||
export const CatalogTable = (props: CatalogTableProps) => {
|
||||
const {
|
||||
columns = defaultColumnsFunc,
|
||||
actions,
|
||||
tableOptions,
|
||||
subtitle,
|
||||
emptyContent,
|
||||
@@ -217,16 +216,26 @@ export const CatalogTable = (props: CatalogTableProps) => {
|
||||
.filter(s => s)
|
||||
.join(' ');
|
||||
|
||||
const title = `${titleDisplay} (${entities.length})`;
|
||||
const actions = props.actions || defaultActions;
|
||||
const options = {
|
||||
actionsColumnIndex: -1,
|
||||
loadingType: 'linear' as const,
|
||||
showEmptyDataSourceMessage: !loading,
|
||||
padding: 'dense' as const,
|
||||
...tableOptions,
|
||||
};
|
||||
|
||||
if (enablePagination) {
|
||||
return (
|
||||
<PaginatedCatalogTable
|
||||
columns={tableColumns}
|
||||
emptyContent={emptyContent}
|
||||
isLoading={loading}
|
||||
title={`${titleDisplay} (${entities.length})`}
|
||||
actions={actions || defaultActions}
|
||||
title={title}
|
||||
actions={actions}
|
||||
subtitle={subtitle}
|
||||
options={tableOptions}
|
||||
options={options}
|
||||
data={entities.map(toEntityRow)}
|
||||
next={pageInfo.next}
|
||||
prev={pageInfo.prev}
|
||||
@@ -234,67 +243,28 @@ export const CatalogTable = (props: CatalogTableProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<LegacyCatalogTable
|
||||
columns={tableColumns}
|
||||
emptyContent={emptyContent}
|
||||
isLoading={loading}
|
||||
title={`${titleDisplay} (${entities.length})`}
|
||||
actions={actions || defaultActions}
|
||||
subtitle={subtitle}
|
||||
data={entities}
|
||||
options={tableOptions}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
function LegacyCatalogTable(props: {
|
||||
actions?: TableProps<CatalogTableRow>['actions'];
|
||||
columns: TableColumn<CatalogTableRow>[];
|
||||
emptyContent: React.ReactNode;
|
||||
data: Entity[];
|
||||
isLoading: boolean;
|
||||
options?: TableProps<CatalogTableRow>['options'];
|
||||
subtitle?: string;
|
||||
title: string;
|
||||
}) {
|
||||
const {
|
||||
actions,
|
||||
columns,
|
||||
emptyContent,
|
||||
data,
|
||||
isLoading,
|
||||
subtitle,
|
||||
options,
|
||||
title,
|
||||
} = props;
|
||||
|
||||
const rows = data.sort(refCompare).map(toEntityRow);
|
||||
const showPagination = rows.length > 20;
|
||||
const rows = entities.sort(refCompare).map(toEntityRow);
|
||||
const pageSize = 20;
|
||||
const showPagination = rows.length > pageSize;
|
||||
|
||||
return (
|
||||
<Table<CatalogTableRow>
|
||||
isLoading={isLoading}
|
||||
columns={columns}
|
||||
isLoading={loading}
|
||||
columns={tableColumns}
|
||||
options={{
|
||||
paging: showPagination,
|
||||
pageSize: 20,
|
||||
actionsColumnIndex: -1,
|
||||
loadingType: 'linear',
|
||||
showEmptyDataSourceMessage: !isLoading,
|
||||
padding: 'dense',
|
||||
pageSize: pageSize,
|
||||
pageSizeOptions: [20, 50, 100],
|
||||
...options,
|
||||
}}
|
||||
title={title}
|
||||
title={`${titleDisplay} (${entities.length})`}
|
||||
data={rows}
|
||||
actions={actions}
|
||||
subtitle={subtitle}
|
||||
emptyContent={emptyContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
CatalogTable.columns = columnFactories;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user