mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
refactor(docker/containers): migrate networks table to react [EE-4665] (#10069)
This commit is contained in:
parent
776f6a62c3
commit
b15812a74d
28 changed files with 632 additions and 259 deletions
|
@ -0,0 +1,60 @@
|
|||
import { CellContext } from '@tanstack/react-table';
|
||||
import { useRouter } from '@uirouter/react';
|
||||
|
||||
import { Authorized } from '@/react/hooks/useUser';
|
||||
import { useDisconnectContainer } from '@/react/docker/networks/queries';
|
||||
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
|
||||
|
||||
import { LoadingButton } from '@@/buttons';
|
||||
|
||||
import { TableNetwork, isContainerNetworkTableMeta } from './types';
|
||||
import { columnHelper } from './helper';
|
||||
|
||||
export const actions = columnHelper.display({
|
||||
header: 'Actions',
|
||||
cell: Cell,
|
||||
});
|
||||
|
||||
function Cell({
|
||||
row,
|
||||
table: {
|
||||
options: { meta },
|
||||
},
|
||||
}: CellContext<TableNetwork, unknown>) {
|
||||
const router = useRouter();
|
||||
const environmentId = useEnvironmentId();
|
||||
const disconnectMutation = useDisconnectContainer();
|
||||
|
||||
return (
|
||||
<Authorized authorizations="DockerNetworkDisconnect">
|
||||
<LoadingButton
|
||||
color="dangerlight"
|
||||
isLoading={disconnectMutation.isLoading}
|
||||
loadingText="Leaving network..."
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
Leave network
|
||||
</LoadingButton>
|
||||
</Authorized>
|
||||
);
|
||||
|
||||
function handleSubmit() {
|
||||
if (!isContainerNetworkTableMeta(meta)) {
|
||||
throw new Error('Invalid row meta');
|
||||
}
|
||||
|
||||
disconnectMutation.mutate(
|
||||
{
|
||||
environmentId,
|
||||
networkId: row.original.id,
|
||||
containerId: meta.containerId,
|
||||
},
|
||||
{
|
||||
onSuccess() {
|
||||
router.stateService.reload();
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue