You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/docker/containers/StatsView/ProcessesDatatable.tsx

59 lines
1.3 KiB

import { ColumnDef } from '@tanstack/react-table';
import { List } from 'lucide-react';
import { useMemo } from 'react';
import { Datatable } from '@@/datatables';
import { createPersistedStore } from '@@/datatables/types';
import { useTableState } from '@@/datatables/useTableState';
const tableKey = 'container-processes';
const store = createPersistedStore(tableKey);
export function ProcessesDatatable({
dataset,
headers,
}: {
dataset?: Array<Array<string | number>>;
headers?: Array<string>;
}) {
const tableState = useTableState(store, tableKey);
const rows = useMemo(() => {
if (!dataset || !headers) {
return [];
}
return dataset.map((row, index) => ({
id: index,
...Object.fromEntries(
headers.map((header, index) => [header, row[index]])
),
}));
}, [dataset, headers]);
const columns = useMemo(
() =>
headers
? headers.map(
(header) =>
({ header, accessorKey: header }) satisfies ColumnDef<{
[k: string]: string;
}>
)
: [],
[headers]
);
return (
<Datatable
title="Processes"
titleIcon={List}
dataset={rows}
columns={columns}
settingsManager={tableState}
disableSelect
isLoading={!dataset}
emptyContentLabel="No processes found."
/>
);
}