2022-11-22 12:16:34 +00:00
|
|
|
import { useStore } from 'zustand';
|
2022-04-19 18:43:36 +00:00
|
|
|
|
2022-10-23 06:53:25 +00:00
|
|
|
import { Environment } from '@/react/portainer/environments/types';
|
2022-04-19 18:43:36 +00:00
|
|
|
import { notifySuccess } from '@/portainer/services/notifications';
|
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
import { Datatable as GenericDatatable } from '@@/datatables';
|
2022-06-17 16:18:42 +00:00
|
|
|
import { Button } from '@@/buttons';
|
2022-11-22 12:16:34 +00:00
|
|
|
import { TextTip } from '@@/Tip/TextTip';
|
|
|
|
import { createPersistedStore } from '@@/datatables/types';
|
|
|
|
import { useSearchBarState } from '@@/datatables/SearchBar';
|
2022-06-17 16:18:42 +00:00
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
import { useAssociateDeviceMutation, useLicenseOverused } from '../queries';
|
2022-04-19 18:43:36 +00:00
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
import { columns } from './columns';
|
2022-04-19 18:43:36 +00:00
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
const storageKey = 'edge-devices-waiting-room';
|
|
|
|
|
|
|
|
const settingsStore = createPersistedStore(storageKey, 'Name');
|
2022-04-19 18:43:36 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
devices: Environment[];
|
|
|
|
isLoading: boolean;
|
|
|
|
totalCount: number;
|
|
|
|
}
|
|
|
|
|
2022-11-22 12:16:34 +00:00
|
|
|
export function Datatable({ devices, isLoading, totalCount }: Props) {
|
2022-04-19 18:43:36 +00:00
|
|
|
const associateMutation = useAssociateDeviceMutation();
|
2022-11-22 12:16:34 +00:00
|
|
|
const licenseOverused = useLicenseOverused();
|
|
|
|
const settings = useStore(settingsStore);
|
|
|
|
const [search, setSearch] = useSearchBarState(storageKey);
|
2022-04-19 18:43:36 +00:00
|
|
|
|
|
|
|
return (
|
2022-11-22 12:16:34 +00:00
|
|
|
<GenericDatatable
|
|
|
|
columns={columns}
|
|
|
|
dataset={devices}
|
|
|
|
initialPageSize={settings.pageSize}
|
|
|
|
onPageSizeChange={settings.setPageSize}
|
|
|
|
initialSortBy={settings.sortBy}
|
|
|
|
onSortByChange={settings.setSortBy}
|
|
|
|
searchValue={search}
|
|
|
|
onSearchChange={setSearch}
|
|
|
|
title="Edge Devices Waiting Room"
|
|
|
|
emptyContentLabel="No Edge Devices found"
|
|
|
|
renderTableActions={(selectedRows) => (
|
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
onClick={() => handleAssociateDevice(selectedRows)}
|
|
|
|
disabled={selectedRows.length === 0}
|
2022-04-19 18:43:36 +00:00
|
|
|
>
|
2022-11-22 12:16:34 +00:00
|
|
|
Associate Device
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
{licenseOverused ? (
|
|
|
|
<div className="ml-2 mt-2">
|
|
|
|
<TextTip color="orange">
|
|
|
|
Associating devices is disabled as your node count exceeds your
|
|
|
|
license limit
|
|
|
|
</TextTip>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
isLoading={isLoading}
|
|
|
|
totalCount={totalCount}
|
|
|
|
/>
|
2022-04-19 18:43:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function handleAssociateDevice(devices: Environment[]) {
|
|
|
|
associateMutation.mutate(
|
|
|
|
devices.map((d) => d.Id),
|
|
|
|
{
|
|
|
|
onSuccess() {
|
2022-08-10 05:07:35 +00:00
|
|
|
notifySuccess('Success', 'Edge devices associated successfully');
|
2022-04-19 18:43:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|