1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

refactor(edge/stacks): migrate envs table to react [EE-5613] (#9093)

This commit is contained in:
Chaim Lev-Ari 2023-06-25 12:38:43 +07:00 committed by GitHub
parent dfc1a7b1d7
commit 11571fd6ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 652 additions and 281 deletions

View file

@ -0,0 +1,106 @@
import { CellContext, createColumnHelper } from '@tanstack/react-table';
import { ChevronDown, ChevronRight } from 'lucide-react';
import clsx from 'clsx';
import { useState } from 'react';
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
import { Button } from '@@/buttons';
import { Icon } from '@@/Icon';
import { EdgeStackStatus } from '../../types';
import { EnvironmentActions } from './EnvironmentActions';
import { ActionStatus } from './ActionStatus';
import { EdgeStackEnvironment } from './types';
const columnHelper = createColumnHelper<EdgeStackEnvironment>();
export const columns = [
columnHelper.accessor('Name', {
id: 'name',
header: 'Name',
}),
columnHelper.accessor((env) => endpointStatusLabel(env.StackStatus), {
id: 'status',
header: 'Status',
}),
columnHelper.accessor((env) => env.StackStatus.Error, {
id: 'error',
header: 'Error',
cell: ErrorCell,
}),
...(isBE
? [
columnHelper.display({
id: 'actions',
header: 'Actions',
cell({ row: { original: env } }) {
return <EnvironmentActions environment={env} />;
},
}),
columnHelper.display({
id: 'actionStatus',
header: 'Action Status',
cell({ row: { original: env } }) {
return <ActionStatus environmentId={env.Id} />;
},
}),
]
: []),
];
function ErrorCell({ getValue }: CellContext<EdgeStackEnvironment, string>) {
const [isExpanded, setIsExpanded] = useState(false);
const value = getValue();
if (!value) {
return '-';
}
return (
<Button
className="flex cursor-pointer"
onClick={() => setIsExpanded(!isExpanded)}
>
<div className="pt-0.5 pr-1">
<Icon icon={isExpanded ? ChevronDown : ChevronRight} />
</div>
<div
className={clsx('overflow-hidden whitespace-normal', {
'h-[1.5em]': isExpanded,
})}
>
{value}
</div>
</Button>
);
}
function endpointStatusLabel(status: EdgeStackStatus) {
const details = (status && status.Details) || {};
const labels = [];
if (details.Acknowledged) {
labels.push('Acknowledged');
}
if (details.ImagesPulled) {
labels.push('Images pre-pulled');
}
if (details.Ok) {
labels.push('Deployed');
}
if (details.Error) {
labels.push('Failed');
}
if (!labels.length) {
labels.push('Pending');
}
return labels.join(', ');
}