refactor(ce): drop orphaned access role column + no-op lodash compact (F6,F7)
F6: delete AccessDatatable/columns/role.tsx — the BE-only role column lost its
only importer when useColumns stopped importing it; zero importers remain.
F7: useColumns wrapped only always-truthy helper.accessor results in _.compact,
a no-op; return the plain array and drop the now-dead lodash import (same
collapse already done in the parallel Wizard column files).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
import { CellContext } from '@tanstack/react-table';
|
||||
import { Edit, X } from 'lucide-react';
|
||||
|
||||
import { useRbacRoles } from '@/react/portainer/users/RolesView/useRbacRoles';
|
||||
|
||||
import { Button } from '@@/buttons';
|
||||
import { Select } from '@@/form-components/Input';
|
||||
|
||||
import { Access, getTableMeta } from '../types';
|
||||
|
||||
import { helper } from './helper';
|
||||
|
||||
export const role = helper.accessor('Role.Name', {
|
||||
cell: RoleCell,
|
||||
header: 'Role',
|
||||
meta: {
|
||||
width: 320,
|
||||
},
|
||||
});
|
||||
|
||||
function RoleCell({
|
||||
row: { original: item, getCanSelect },
|
||||
table,
|
||||
getValue,
|
||||
}: CellContext<Access, string>) {
|
||||
const meta = getTableMeta(table.options.meta);
|
||||
const type = item.Type as 'team' | 'user';
|
||||
const updateValue = meta.roles.getRoleValue(item.Id, type);
|
||||
const role = getValue();
|
||||
|
||||
if (!getCanSelect()) {
|
||||
return <>{role}</>;
|
||||
}
|
||||
|
||||
if (typeof updateValue === 'undefined') {
|
||||
return (
|
||||
<>
|
||||
{role}
|
||||
<Button
|
||||
color="none"
|
||||
icon={Edit}
|
||||
onClick={() => meta.roles.setRolesValue(item.Id, type, item.Role.Id)}
|
||||
data-cy="edit-role-button"
|
||||
>
|
||||
Edit
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<RollEdit
|
||||
value={updateValue}
|
||||
onChange={(value) => meta.roles.setRolesValue(item.Id, type, value)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function RollEdit({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: number;
|
||||
onChange(value?: number): void;
|
||||
}) {
|
||||
const rolesQuery = useRbacRoles({
|
||||
select: (roles) => roles.map((r) => ({ label: r.Name, value: r.Id })),
|
||||
});
|
||||
|
||||
if (!rolesQuery.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex max-w-xs items-center gap-3">
|
||||
<Select
|
||||
aria-label="Role"
|
||||
data-cy="role-select"
|
||||
value={value}
|
||||
options={rolesQuery.data}
|
||||
onChange={(e) => onChange(parseInt(e.target.value, 10))}
|
||||
/>
|
||||
<Button
|
||||
color="none"
|
||||
icon={X}
|
||||
onClick={() => onChange()}
|
||||
data-cy="cancel-role-button"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import _ from 'lodash';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { inheritedName } from './inheritedName';
|
||||
@@ -7,7 +6,7 @@ import { type } from './type';
|
||||
|
||||
export function useColumns({ inheritFrom }: { inheritFrom: boolean }) {
|
||||
return useMemo(
|
||||
() => _.compact([inheritFrom ? inheritedName : name, type]),
|
||||
() => [inheritFrom ? inheritedName : name, type],
|
||||
[inheritFrom]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user