2022-08-11 04:33:29 +00:00
|
|
|
import _ from 'lodash';
|
2022-11-22 12:16:34 +00:00
|
|
|
import { useStore } from 'zustand';
|
|
|
|
import { Box } from 'react-feather';
|
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
|
|
|
|
|
|
|
import { Datatable, TableSettingsMenu } from '@@/datatables';
|
|
|
|
import {
|
|
|
|
buildAction,
|
|
|
|
QuickActionsSettings,
|
|
|
|
} from '@@/datatables/QuickActionsSettings';
|
|
|
|
import { ColumnVisibilityMenu } from '@@/datatables/ColumnVisibilityMenu';
|
2022-11-22 12:16:34 +00:00
|
|
|
import { useSearchBarState } from '@@/datatables/SearchBar';
|
|
|
|
import { TableSettingsProvider } from '@@/datatables/useTableSettings';
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
import { useContainers } from '../../containers/queries/containers';
|
|
|
|
import { RowProvider } from '../../containers/ListView/ContainersDatatable/RowContext';
|
|
|
|
|
|
|
|
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) {
|
2022-11-22 12:16:34 +00:00
|
|
|
const settings = useStore(settingsStore);
|
|
|
|
const [search, setSearch] = useSearchBarState(storageKey);
|
|
|
|
|
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
|
|
|
|
2022-08-11 04:33:29 +00:00
|
|
|
const hidableColumns = _.compact(
|
|
|
|
columns.filter((col) => col.canHide).map((col) => col.id)
|
|
|
|
);
|
|
|
|
|
|
|
|
const containersQuery = useContainers(
|
|
|
|
environment.Id,
|
|
|
|
true,
|
|
|
|
{
|
|
|
|
label: [`com.docker.compose.project=${stackName}`],
|
|
|
|
},
|
|
|
|
settings.autoRefreshRate * 1000
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<RowProvider context={{ environment }}>
|
2022-11-22 12:16:34 +00:00
|
|
|
<TableSettingsProvider settings={settingsStore}>
|
|
|
|
<Datatable
|
|
|
|
title="Containers"
|
|
|
|
titleIcon={Box}
|
|
|
|
initialPageSize={settings.pageSize}
|
|
|
|
onPageSizeChange={settings.setPageSize}
|
|
|
|
initialSortBy={settings.sortBy}
|
|
|
|
onSortByChange={settings.setSortBy}
|
|
|
|
searchValue={search}
|
|
|
|
onSearchChange={setSearch}
|
|
|
|
columns={columns}
|
|
|
|
renderTableActions={(selectedRows) => (
|
|
|
|
<ContainersDatatableActions
|
|
|
|
selectedItems={selectedRows}
|
|
|
|
isAddActionVisible={false}
|
|
|
|
endpointId={environment.Id}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
initialTableState={{ hiddenColumns: settings.hiddenColumns }}
|
|
|
|
renderTableSettings={(tableInstance) => {
|
|
|
|
const columnsToHide = tableInstance.allColumns.filter(
|
|
|
|
(colInstance) => hidableColumns?.includes(colInstance.id)
|
|
|
|
);
|
2022-08-11 04:33:29 +00:00
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ColumnVisibilityMenu<DockerContainer>
|
|
|
|
columns={columnsToHide}
|
|
|
|
onChange={(hiddenColumns) => {
|
|
|
|
settings.setHiddenColumns(hiddenColumns);
|
|
|
|
tableInstance.setHiddenColumns(hiddenColumns);
|
|
|
|
}}
|
|
|
|
value={settings.hiddenColumns}
|
|
|
|
/>
|
|
|
|
<TableSettingsMenu
|
|
|
|
quickActions={<QuickActionsSettings actions={actions} />}
|
|
|
|
>
|
|
|
|
<ContainersDatatableSettings settings={settings} />
|
|
|
|
</TableSettingsMenu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
dataset={containersQuery.data || []}
|
|
|
|
isLoading={containersQuery.isLoading}
|
|
|
|
emptyContentLabel="No containers found"
|
|
|
|
/>
|
|
|
|
</TableSettingsProvider>
|
2022-08-11 04:33:29 +00:00
|
|
|
</RowProvider>
|
|
|
|
);
|
|
|
|
}
|