From 48aab77058e39396148be11ace91ccef821d3f04 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Tue, 9 Apr 2024 08:11:29 +0300 Subject: [PATCH] refactor(rbac): migrate roles table to react [EE-4711] (#10772) --- .../rbac/components/roles-datatable/index.js | 14 --- .../roles-datatable.controller.js | 15 --- .../roles-datatable/roles-datatable.css | 7 -- .../roles-datatable/roles-datatable.html | 92 ------------------- app/portainer/rbac/index.js | 2 - app/portainer/rbac/views/roles/roles.html | 6 +- app/portainer/react/components/users.ts | 4 +- app/react/portainer/users/RolesView/.keep | 0 .../users/RolesView/RbacRolesDatatable.tsx | 68 ++++++++++++++ 9 files changed, 72 insertions(+), 136 deletions(-) delete mode 100644 app/portainer/rbac/components/roles-datatable/index.js delete mode 100644 app/portainer/rbac/components/roles-datatable/roles-datatable.controller.js delete mode 100644 app/portainer/rbac/components/roles-datatable/roles-datatable.css delete mode 100644 app/portainer/rbac/components/roles-datatable/roles-datatable.html delete mode 100644 app/react/portainer/users/RolesView/.keep create mode 100644 app/react/portainer/users/RolesView/RbacRolesDatatable.tsx diff --git a/app/portainer/rbac/components/roles-datatable/index.js b/app/portainer/rbac/components/roles-datatable/index.js deleted file mode 100644 index 917604fc2..000000000 --- a/app/portainer/rbac/components/roles-datatable/index.js +++ /dev/null @@ -1,14 +0,0 @@ -import controller from './roles-datatable.controller'; -import './roles-datatable.css'; - -export const rolesDatatable = { - templateUrl: './roles-datatable.html', - controller, - bindings: { - titleText: '@', - dataset: '<', - tableKey: '@', - orderBy: '@', - reverseOrder: '<', - }, -}; diff --git a/app/portainer/rbac/components/roles-datatable/roles-datatable.controller.js b/app/portainer/rbac/components/roles-datatable/roles-datatable.controller.js deleted file mode 100644 index ff980bbac..000000000 --- a/app/portainer/rbac/components/roles-datatable/roles-datatable.controller.js +++ /dev/null @@ -1,15 +0,0 @@ -import angular from 'angular'; -import { RoleTypes } from '../../models/role'; - -export default class RolesDatatableController { - /* @ngInject */ - constructor($controller, $scope) { - this.limitedFeature = 'rbac-roles'; - - angular.extend(this, $controller('GenericDatatableController', { $scope })); - } - - isDefaultItem(item) { - return item.ID === RoleTypes.STANDARD; - } -} diff --git a/app/portainer/rbac/components/roles-datatable/roles-datatable.css b/app/portainer/rbac/components/roles-datatable/roles-datatable.css deleted file mode 100644 index 14def6618..000000000 --- a/app/portainer/rbac/components/roles-datatable/roles-datatable.css +++ /dev/null @@ -1,7 +0,0 @@ -th.be-visual-indicator-col { - width: 300px; -} - -td.be-visual-indicator-col { - text-align: center; -} diff --git a/app/portainer/rbac/components/roles-datatable/roles-datatable.html b/app/portainer/rbac/components/roles-datatable/roles-datatable.html deleted file mode 100644 index 688f83cf8..000000000 --- a/app/portainer/rbac/components/roles-datatable/roles-datatable.html +++ /dev/null @@ -1,92 +0,0 @@ -
- - -
-
-
- -
- {{ $ctrl.titleText }} -
- -
-
- - - - - - - - - - - - - - - - - - - - - -
- - - -
{{ item.Name }}{{ item.Description }} - - - - Default -
Loading...
No role available.
-
- -
-
-
diff --git a/app/portainer/rbac/index.js b/app/portainer/rbac/index.js index 21563de83..7638c33d2 100644 --- a/app/portainer/rbac/index.js +++ b/app/portainer/rbac/index.js @@ -1,7 +1,6 @@ import { AccessHeaders } from '../authorization-guard'; import { rolesView } from './views/roles'; import { accessViewer } from './components/access-viewer'; -import { rolesDatatable } from './components/roles-datatable'; import { RoleService } from './services/role.service'; import { RolesFactory } from './services/role.rest'; @@ -10,7 +9,6 @@ angular .module('portainer.rbac', ['ngResource']) .constant('API_ENDPOINT_ROLES', 'api/roles') .component('accessViewer', accessViewer) - .component('rolesDatatable', rolesDatatable) .component('rolesView', rolesView) .factory('RoleService', RoleService) .factory('Roles', RolesFactory) diff --git a/app/portainer/rbac/views/roles/roles.html b/app/portainer/rbac/views/roles/roles.html index 4eea636e8..ac32d0869 100644 --- a/app/portainer/rbac/views/roles/roles.html +++ b/app/portainer/rbac/views/roles/roles.html @@ -1,10 +1,6 @@ -
-
- -
-
+
diff --git a/app/portainer/react/components/users.ts b/app/portainer/react/components/users.ts index c8d9f4117..587acbcc4 100644 --- a/app/portainer/react/components/users.ts +++ b/app/portainer/react/components/users.ts @@ -5,6 +5,7 @@ import { withUIRouter } from '@/react-tools/withUIRouter'; import { UsersDatatable } from '@/react/portainer/users/ListView/UsersDatatable/UsersDatatable'; import { withCurrentUser } from '@/react-tools/withCurrentUser'; import { EffectiveAccessViewerDatatable } from '@/react/portainer/users/RolesView/AccessViewer/EffectiveAccessViewerDatatable'; +import { RbacRolesDatatable } from '@/react/portainer/users/RolesView/RbacRolesDatatable'; export const usersModule = angular .module('portainer.app.react.components.users', []) @@ -17,4 +18,5 @@ export const usersModule = angular r2a(withUIRouter(withCurrentUser(EffectiveAccessViewerDatatable)), [ 'dataset', ]) - ).name; + ) + .component('rbacRolesDatatable', r2a(RbacRolesDatatable, ['dataset'])).name; diff --git a/app/react/portainer/users/RolesView/.keep b/app/react/portainer/users/RolesView/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/react/portainer/users/RolesView/RbacRolesDatatable.tsx b/app/react/portainer/users/RolesView/RbacRolesDatatable.tsx new file mode 100644 index 000000000..f2b1c8daf --- /dev/null +++ b/app/react/portainer/users/RolesView/RbacRolesDatatable.tsx @@ -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 | undefined; +}) { + const tableState = useTableState(store, tableKey); + + return ( + + ); +} + +function getColumns() { + const columnHelper = createColumnHelper(); + + 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 ? ( + Default + ) : ( + + ), + meta: { + className: 'text-center', + }, + }), + ]); +}