mirror of
https://github.com/portainer/portainer.git
synced 2025-08-03 04:45:21 +02:00
refactor(rbac): migrate roles table to react [EE-4711] (#10772)
This commit is contained in:
parent
7e53d01d0f
commit
48aab77058
9 changed files with 72 additions and 136 deletions
68
app/react/portainer/users/RolesView/RbacRolesDatatable.tsx
Normal file
68
app/react/portainer/users/RolesView/RbacRolesDatatable.tsx
Normal file
|
@ -0,0 +1,68 @@
|
|||
import { FileCode } from 'lucide-react';
|
||||
import { createColumnHelper } from '@tanstack/react-table';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { RoleTypes } from '@/portainer/rbac/models/role';
|
||||
|
||||
import { Datatable } from '@@/datatables';
|
||||
import { createPersistedStore } from '@@/datatables/types';
|
||||
import { useTableState } from '@@/datatables/useTableState';
|
||||
import { BEFeatureIndicator } from '@@/BEFeatureIndicator';
|
||||
|
||||
import { isBE } from '../../feature-flags/feature-flags.service';
|
||||
import { FeatureId } from '../../feature-flags/enums';
|
||||
|
||||
import { RbacRole } from './types';
|
||||
|
||||
const tableKey = 'rbac-roles-table';
|
||||
|
||||
const store = createPersistedStore(tableKey);
|
||||
|
||||
const columns = getColumns();
|
||||
|
||||
export function RbacRolesDatatable({
|
||||
dataset,
|
||||
}: {
|
||||
dataset: Array<RbacRole> | undefined;
|
||||
}) {
|
||||
const tableState = useTableState(store, tableKey);
|
||||
|
||||
return (
|
||||
<Datatable
|
||||
title="Roles"
|
||||
titleIcon={FileCode}
|
||||
dataset={dataset || []}
|
||||
columns={columns}
|
||||
isLoading={!dataset}
|
||||
emptyContentLabel="No role available."
|
||||
settingsManager={tableState}
|
||||
disableSelect
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function getColumns() {
|
||||
const columnHelper = createColumnHelper<RbacRole>();
|
||||
|
||||
return _.compact([
|
||||
columnHelper.accessor('Name', {
|
||||
header: 'Name',
|
||||
}),
|
||||
columnHelper.accessor('Description', {
|
||||
header: 'Description',
|
||||
}),
|
||||
!isBE &&
|
||||
columnHelper.display({
|
||||
id: 'be-indicator',
|
||||
cell: ({ row: { original: item } }) =>
|
||||
item.Id === RoleTypes.STANDARD ? (
|
||||
<b>Default</b>
|
||||
) : (
|
||||
<BEFeatureIndicator featureId={FeatureId.RBAC_ROLES} />
|
||||
),
|
||||
meta: {
|
||||
className: 'text-center',
|
||||
},
|
||||
}),
|
||||
]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue