2024-04-02 19:10:22 +00:00
|
|
|
import { Database } from 'lucide-react';
|
|
|
|
|
2024-10-01 01:15:51 +00:00
|
|
|
import { Authorized, useAuthorizations } from '@/react/hooks/useUser';
|
2024-04-02 19:10:22 +00:00
|
|
|
import KubernetesVolumeHelper from '@/kubernetes/helpers/volumeHelper';
|
|
|
|
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
|
|
|
|
|
|
|
|
import { refreshableSettings } from '@@/datatables/types';
|
|
|
|
import { Datatable, TableSettingsMenu } from '@@/datatables';
|
|
|
|
import { useTableStateWithStorage } from '@@/datatables/useTableState';
|
|
|
|
import { DeleteButton } from '@@/buttons/DeleteButton';
|
|
|
|
|
|
|
|
import { systemResourcesSettings } from '../../datatables/SystemResourcesSettings';
|
|
|
|
import { CreateFromManifestButton } from '../../components/CreateFromManifestButton';
|
|
|
|
import {
|
|
|
|
DefaultDatatableSettings,
|
|
|
|
TableSettings,
|
|
|
|
} from '../../datatables/DefaultDatatableSettings';
|
|
|
|
import { SystemResourceDescription } from '../../datatables/SystemResourceDescription';
|
|
|
|
import { useNamespacesQuery } from '../../namespaces/queries/useNamespacesQuery';
|
2024-10-01 01:15:51 +00:00
|
|
|
import { useAllVolumesQuery } from '../queries/useVolumesQuery';
|
|
|
|
import { isSystemNamespace } from '../../namespaces/queries/useIsSystemNamespace';
|
|
|
|
import { useDeleteVolumes } from '../queries/useDeleteVolumes';
|
2024-04-02 19:10:22 +00:00
|
|
|
|
|
|
|
import { columns } from './columns';
|
|
|
|
|
2024-10-01 01:15:51 +00:00
|
|
|
export function VolumesDatatable() {
|
2024-04-02 19:10:22 +00:00
|
|
|
const tableState = useTableStateWithStorage<TableSettings>(
|
|
|
|
'kube-volumes',
|
|
|
|
'Name',
|
|
|
|
(set) => ({
|
|
|
|
...systemResourcesSettings(set),
|
|
|
|
...refreshableSettings(set),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2024-10-01 01:15:51 +00:00
|
|
|
const { authorized: hasWriteAuth } = useAuthorizations(
|
|
|
|
'K8sVolumesW',
|
|
|
|
undefined,
|
|
|
|
true
|
|
|
|
);
|
2024-04-02 19:10:22 +00:00
|
|
|
|
|
|
|
const envId = useEnvironmentId();
|
2024-10-01 01:15:51 +00:00
|
|
|
const deleteVolumesMutation = useDeleteVolumes(envId);
|
2024-04-02 19:10:22 +00:00
|
|
|
const namespaceListQuery = useNamespacesQuery(envId);
|
2024-10-01 01:15:51 +00:00
|
|
|
const namespaces = namespaceListQuery.data ?? [];
|
|
|
|
const volumesQuery = useAllVolumesQuery(envId, {
|
|
|
|
refetchInterval: tableState.autoRefreshRate * 1000,
|
|
|
|
});
|
|
|
|
const volumes = volumesQuery.data ?? [];
|
2024-04-02 19:10:22 +00:00
|
|
|
|
2024-10-01 01:15:51 +00:00
|
|
|
const filteredVolumes = tableState.showSystemResources
|
|
|
|
? volumes
|
|
|
|
: volumes.filter(
|
|
|
|
(volume) =>
|
|
|
|
!isSystemNamespace(volume.ResourcePool.Namespace.Name, namespaces)
|
|
|
|
);
|
2024-04-02 19:10:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Datatable
|
|
|
|
data-cy="k8s-volumes-datatable"
|
2024-10-01 01:15:51 +00:00
|
|
|
isLoading={volumesQuery.isLoading || namespaceListQuery.isLoading}
|
|
|
|
dataset={filteredVolumes}
|
2024-04-02 19:10:22 +00:00
|
|
|
columns={columns}
|
|
|
|
settingsManager={tableState}
|
|
|
|
title="Volumes"
|
|
|
|
titleIcon={Database}
|
2024-10-01 01:15:51 +00:00
|
|
|
getRowId={(row) => row.PersistentVolumeClaim.Name}
|
|
|
|
disableSelect={!hasWriteAuth}
|
|
|
|
isRowSelectable={({ original: volume }) =>
|
|
|
|
!isSystemNamespace(volume.ResourcePool.Namespace.Name, namespaces) &&
|
|
|
|
!KubernetesVolumeHelper.isUsed(volume)
|
2024-04-02 19:10:22 +00:00
|
|
|
}
|
|
|
|
renderTableActions={(selectedItems) => (
|
2024-10-01 01:15:51 +00:00
|
|
|
<Authorized authorizations="K8sVolumesW">
|
2024-04-02 19:10:22 +00:00
|
|
|
<DeleteButton
|
|
|
|
confirmMessage="Do you want to remove the selected volume(s)?"
|
2024-10-01 01:15:51 +00:00
|
|
|
onConfirmed={() => deleteVolumesMutation.mutate(selectedItems)}
|
2024-04-02 19:10:22 +00:00
|
|
|
disabled={selectedItems.length === 0}
|
2024-10-01 01:15:51 +00:00
|
|
|
isLoading={deleteVolumesMutation.isLoading}
|
2024-04-11 00:11:38 +00:00
|
|
|
data-cy="k8s-volumes-delete-button"
|
2024-04-02 19:10:22 +00:00
|
|
|
/>
|
2024-04-11 00:11:38 +00:00
|
|
|
<CreateFromManifestButton data-cy="k8s-volumes-deploy-button" />
|
2024-10-01 01:15:51 +00:00
|
|
|
</Authorized>
|
2024-04-02 19:10:22 +00:00
|
|
|
)}
|
|
|
|
renderTableSettings={() => (
|
|
|
|
<TableSettingsMenu>
|
|
|
|
<DefaultDatatableSettings settings={tableState} />
|
|
|
|
</TableSettingsMenu>
|
|
|
|
)}
|
|
|
|
description={
|
|
|
|
<SystemResourceDescription
|
|
|
|
showSystemResources={tableState.showSystemResources}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|