2022-11-28 02:00:28 +00:00
|
|
|
import { Box } from 'lucide-react';
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
import { DockerContainer } from '@/react/docker/containers/types';
|
2022-10-23 06:53:25 +00:00
|
|
|
import { Environment } from '@/react/portainer/environments/types';
|
2022-08-11 04:33:29 +00:00
|
|
|
import { createStore } from '@/react/docker/containers/ListView/ContainersDatatable/datatable-store';
|
|
|
|
import { useColumns } from '@/react/docker/containers/ListView/ContainersDatatable/columns';
|
|
|
|
import { ContainersDatatableActions } from '@/react/docker/containers/ListView/ContainersDatatable/ContainersDatatableActions';
|
|
|
|
import { ContainersDatatableSettings } from '@/react/docker/containers/ListView/ContainersDatatable/ContainersDatatableSettings';
|
2022-08-24 22:27:02 +00:00
|
|
|
import { useShowGPUsColumn } from '@/react/docker/containers/utils';
|
2022-08-11 04:33:29 +00:00
|
|
|
|
2023-05-02 06:42:16 +00:00
|
|
|
import { Datatable, Table } from '@@/datatables';
|
2022-08-11 04:33:29 +00:00
|
|
|
import {
|
|
|
|
buildAction,
|
|
|
|
QuickActionsSettings,
|
|
|
|
} from '@@/datatables/QuickActionsSettings';
|
|
|
|
import { ColumnVisibilityMenu } from '@@/datatables/ColumnVisibilityMenu';
|
2022-11-22 12:16:34 +00:00
|
|
|
import { TableSettingsProvider } from '@@/datatables/useTableSettings';
|
2023-05-02 06:42:16 +00:00
|
|
|
import { useTableState } from '@@/datatables/useTableState';
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
import { useContainers } from '../../containers/queries/containers';
|
2023-05-16 03:30:34 +00:00
|
|
|
import { RowProvider } from '../../containers/ListView/ContainersDatatable/RowContext';
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
const storageKey = 'stack-containers';
|
2022-11-22 12:16:34 +00:00
|
|
|
const settingsStore = createStore(storageKey);
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
const actions = [
|
|
|
|
buildAction('logs', 'Logs'),
|
|
|
|
buildAction('inspect', 'Inspect'),
|
|
|
|
buildAction('stats', 'Stats'),
|
|
|
|
buildAction('exec', 'Console'),
|
|
|
|
buildAction('attach', 'Attach'),
|
|
|
|
];
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
environment: Environment;
|
|
|
|
stackName: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function StackContainersDatatable({ environment, stackName }: Props) {
|
2023-05-02 06:42:16 +00:00
|
|
|
const tableState = useTableState(settingsStore, storageKey);
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2022-08-24 22:27:02 +00:00
|
|
|
const isGPUsColumnVisible = useShowGPUsColumn(environment.Id);
|
|
|
|
const columns = useColumns(false, isGPUsColumnVisible);
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2023-05-18 05:53:34 +00:00
|
|
|
const containersQuery = useContainers(environment.Id, {
|
|
|
|
filters: {
|
2022-08-11 04:33:29 +00:00
|
|
|
label: [`com.docker.compose.project=${stackName}`],
|
|
|
|
},
|
2023-05-18 05:53:34 +00:00
|
|
|
autoRefreshRate: tableState.autoRefreshRate * 1000,
|
|
|
|
});
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
return (
|
2023-05-16 03:30:34 +00:00
|
|
|
<RowProvider context={{ environment }}>
|
|
|
|
<TableSettingsProvider settings={settingsStore}>
|
|
|
|
<Datatable
|
|
|
|
title="Containers"
|
|
|
|
titleIcon={Box}
|
|
|
|
settingsManager={tableState}
|
|
|
|
columns={columns}
|
|
|
|
renderTableActions={(selectedRows) => (
|
|
|
|
<ContainersDatatableActions
|
|
|
|
selectedItems={selectedRows}
|
|
|
|
isAddActionVisible={false}
|
|
|
|
endpointId={environment.Id}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
initialTableState={{
|
|
|
|
columnVisibility: Object.fromEntries(
|
|
|
|
tableState.hiddenColumns.map((col) => [col, false])
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
renderTableSettings={(tableInstance) => {
|
|
|
|
const columnsToHide = tableInstance
|
|
|
|
.getAllColumns()
|
|
|
|
.filter((col) => col.getCanHide());
|
2022-08-11 04:33:29 +00:00
|
|
|
|
2023-05-16 03:30:34 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ColumnVisibilityMenu<DockerContainer>
|
|
|
|
columns={columnsToHide}
|
|
|
|
onChange={(hiddenColumns) => {
|
|
|
|
tableState.setHiddenColumns(hiddenColumns);
|
|
|
|
tableInstance.setColumnVisibility(
|
|
|
|
Object.fromEntries(
|
|
|
|
hiddenColumns.map((col) => [col, false])
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
value={tableState.hiddenColumns}
|
|
|
|
/>
|
|
|
|
<Table.SettingsMenu
|
|
|
|
quickActions={<QuickActionsSettings actions={actions} />}
|
|
|
|
>
|
|
|
|
<ContainersDatatableSettings settings={tableState} />
|
|
|
|
</Table.SettingsMenu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
dataset={containersQuery.data || []}
|
|
|
|
isLoading={containersQuery.isLoading}
|
|
|
|
emptyContentLabel="No containers found"
|
|
|
|
/>
|
|
|
|
</TableSettingsProvider>
|
|
|
|
</RowProvider>
|
2022-08-11 04:33:29 +00:00
|
|
|
);
|
|
|
|
}
|