mirror of
https://github.com/portainer/portainer.git
synced 2025-08-06 14:25:31 +02:00
refactor(edge/jobs): migrate view to react [EE-2236] (#10661)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
This commit is contained in:
parent
86c4b3059e
commit
66770bebd4
18 changed files with 227 additions and 204 deletions
34
app/react/edge/edge-jobs/ListView/EdgeJobsDatatable.tsx
Normal file
34
app/react/edge/edge-jobs/ListView/EdgeJobsDatatable.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { Clock } from 'lucide-react';
|
||||
|
||||
import { Datatable } from '@@/datatables';
|
||||
import { createPersistedStore } from '@@/datatables/types';
|
||||
import { useTableState } from '@@/datatables/useTableState';
|
||||
|
||||
import { useEdgeJobs } from '../queries/useEdgeJobs';
|
||||
|
||||
import { TableActions } from './TableActions';
|
||||
import { columns } from './columns';
|
||||
|
||||
const tableKey = 'edge-jobs';
|
||||
|
||||
const settingsStore = createPersistedStore(tableKey);
|
||||
|
||||
export function EdgeJobsDatatable() {
|
||||
const jobsQuery = useEdgeJobs();
|
||||
const tableState = useTableState(settingsStore, tableKey);
|
||||
|
||||
return (
|
||||
<Datatable
|
||||
columns={columns}
|
||||
isLoading={jobsQuery.isLoading}
|
||||
dataset={jobsQuery.data || []}
|
||||
settingsManager={tableState}
|
||||
emptyContentLabel="No Edge jobs available."
|
||||
title="Edge Jobs"
|
||||
titleIcon={Clock}
|
||||
renderTableActions={(selectedItems) => (
|
||||
<TableActions selectedItems={selectedItems} />
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
21
app/react/edge/edge-jobs/ListView/ListView.tsx
Normal file
21
app/react/edge/edge-jobs/ListView/ListView.tsx
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { InformationPanel } from '@@/InformationPanel';
|
||||
import { PageHeader } from '@@/PageHeader';
|
||||
|
||||
import { EdgeJobsDatatable } from './EdgeJobsDatatable';
|
||||
|
||||
export function ListView() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="Edge Jobs" breadcrumbs="Edge Jobs" reload />
|
||||
|
||||
<InformationPanel title="Information">
|
||||
<p className="small text-muted">
|
||||
Edge Jobs requires Docker Standalone and a cron implementation that
|
||||
reads jobs from <code>/etc/cron.d</code>
|
||||
</p>
|
||||
</InformationPanel>
|
||||
|
||||
<EdgeJobsDatatable />
|
||||
</>
|
||||
);
|
||||
}
|
37
app/react/edge/edge-jobs/ListView/TableActions.tsx
Normal file
37
app/react/edge/edge-jobs/ListView/TableActions.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { notifySuccess } from '@/portainer/services/notifications';
|
||||
|
||||
import { AddButton } from '@@/buttons';
|
||||
import { DeleteButton } from '@@/buttons/DeleteButton';
|
||||
|
||||
import { EdgeJob } from '../types';
|
||||
|
||||
import { useDeleteEdgeJobsMutation } from './useDeleteEdgeJobsMutation';
|
||||
|
||||
export function TableActions({
|
||||
selectedItems,
|
||||
}: {
|
||||
selectedItems: Array<EdgeJob>;
|
||||
}) {
|
||||
const removeMutation = useDeleteEdgeJobsMutation();
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<DeleteButton
|
||||
confirmMessage="Do you want to remove the selected Edge Job(s)?"
|
||||
disabled={selectedItems.length === 0}
|
||||
onConfirmed={() => handleRemove(selectedItems)}
|
||||
/>
|
||||
|
||||
<AddButton>Add Edge job</AddButton>
|
||||
</div>
|
||||
);
|
||||
|
||||
async function handleRemove(selectedItems: Array<EdgeJob>) {
|
||||
const ids = selectedItems.map((item) => item.Id);
|
||||
removeMutation.mutate(ids, {
|
||||
onSuccess: () => {
|
||||
notifySuccess('Success', 'Edge Job(s) removed');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
20
app/react/edge/edge-jobs/ListView/columns.ts
Normal file
20
app/react/edge/edge-jobs/ListView/columns.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { createColumnHelper } from '@tanstack/react-table';
|
||||
|
||||
import { isoDateFromTimestamp } from '@/portainer/filters/filters';
|
||||
|
||||
import { buildNameColumn } from '@@/datatables/buildNameColumn';
|
||||
|
||||
import { EdgeJob } from '../types';
|
||||
|
||||
const columnHelper = createColumnHelper<EdgeJob>();
|
||||
|
||||
export const columns = [
|
||||
buildNameColumn<EdgeJob>('Name', '.job'),
|
||||
columnHelper.accessor('CronExpression', {
|
||||
header: 'Cron Expression',
|
||||
}),
|
||||
columnHelper.accessor('Created', {
|
||||
header: 'Created',
|
||||
cell: ({ getValue }) => isoDateFromTimestamp(getValue()),
|
||||
}),
|
||||
];
|
1
app/react/edge/edge-jobs/ListView/index.ts
Normal file
1
app/react/edge/edge-jobs/ListView/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { ListView } from './ListView';
|
|
@ -0,0 +1,35 @@
|
|||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import { promiseSequence } from '@/portainer/helpers/promise-utils';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import {
|
||||
mutationOptions,
|
||||
withError,
|
||||
withInvalidate,
|
||||
} from '@/react-tools/react-query';
|
||||
|
||||
import { EdgeJob } from '../types';
|
||||
import { buildUrl } from '../queries/build-url';
|
||||
import { queryKeys } from '../queries/query-keys';
|
||||
|
||||
export function useDeleteEdgeJobsMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(edgeJobIds: Array<EdgeJob['Id']>) =>
|
||||
promiseSequence(
|
||||
edgeJobIds.map((edgeJobId) => () => deleteEdgeJob(edgeJobId))
|
||||
),
|
||||
mutationOptions(
|
||||
withError('Unable to delete Edge job(s)'),
|
||||
withInvalidate(queryClient, [queryKeys.base()])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async function deleteEdgeJob(id: EdgeJob['Id']) {
|
||||
try {
|
||||
await axios.delete(buildUrl({ id }));
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, 'Unable to delete edge job');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue