2023-05-02 06:42:16 +00:00
|
|
|
import { CellContext, ColumnDef } from '@tanstack/react-table';
|
2023-10-11 07:27:42 +00:00
|
|
|
import { Eye, EyeOff, Users } from 'lucide-react';
|
2023-05-02 06:42:16 +00:00
|
|
|
|
|
|
|
import { ResourceControlOwnership } from '@/react/portainer/access-control/types';
|
|
|
|
|
|
|
|
import { Icon } from '@@/Icon';
|
|
|
|
|
|
|
|
export interface IResource {
|
|
|
|
ResourceControl?: {
|
|
|
|
Ownership: ResourceControlOwnership;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-09-07 14:59:59 +00:00
|
|
|
export function createOwnershipColumn<D extends IResource>(
|
|
|
|
enableHiding = true
|
|
|
|
): ColumnDef<D, ResourceControlOwnership> {
|
2023-05-02 06:42:16 +00:00
|
|
|
return {
|
|
|
|
accessorFn: (row) =>
|
|
|
|
row.ResourceControl?.Ownership || ResourceControlOwnership.ADMINISTRATORS,
|
|
|
|
header: 'Ownership',
|
|
|
|
id: 'ownership',
|
|
|
|
cell: OwnershipCell,
|
2023-09-07 14:59:59 +00:00
|
|
|
enableHiding,
|
2023-05-02 06:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function OwnershipCell({
|
|
|
|
getValue,
|
|
|
|
}: CellContext<D, ResourceControlOwnership>) {
|
|
|
|
const value = getValue();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className="flex items-center gap-2">
|
|
|
|
<Icon icon={ownershipIcon(value)} className="space-right" />
|
|
|
|
{value}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-10-11 07:27:42 +00:00
|
|
|
|
|
|
|
export function ownershipIcon(ownership: ResourceControlOwnership) {
|
|
|
|
switch (ownership) {
|
|
|
|
case ResourceControlOwnership.PRIVATE:
|
|
|
|
return EyeOff;
|
|
|
|
case ResourceControlOwnership.ADMINISTRATORS:
|
|
|
|
return EyeOff;
|
|
|
|
case ResourceControlOwnership.RESTRICTED:
|
|
|
|
return Users;
|
|
|
|
default:
|
|
|
|
return Eye;
|
|
|
|
}
|
|
|
|
}
|