From 31635b75e9d8fe8480137eb5a03257ba54eba1ca Mon Sep 17 00:00:00 2001 From: Eyo Okon Eyo Date: Thu, 13 Jun 2024 19:52:23 +0200 Subject: [PATCH] start work on assign to role flyout --- .../view_space/view_space_roles.tsx | 142 +++++++++++++++--- .../management/view_space/view_space_tabs.tsx | 2 +- 2 files changed, 124 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/spaces/public/management/view_space/view_space_roles.tsx b/x-pack/plugins/spaces/public/management/view_space/view_space_roles.tsx index 8ec03a09c0cbd..9f398543b8882 100644 --- a/x-pack/plugins/spaces/public/management/view_space/view_space_roles.tsx +++ b/x-pack/plugins/spaces/public/management/view_space/view_space_roles.tsx @@ -5,35 +5,60 @@ * 2.0. */ -import type { EuiBasicTableColumn, EuiTableFieldDataColumnType } from '@elastic/eui'; import { EuiBasicTable, EuiButton, EuiButtonEmpty, + EuiComboBox, + EuiFilterButton, + EuiFilterGroup, EuiFlexGroup, EuiFlexItem, EuiFlyout, EuiFlyoutBody, EuiFlyoutFooter, EuiFlyoutHeader, + EuiForm, + EuiFormRow, + EuiSpacer, EuiText, EuiTitle, } from '@elastic/eui'; +import type { + EuiBasicTableColumn, + EuiComboBoxOptionOption, + EuiTableFieldDataColumnType, +} from '@elastic/eui'; import type { FC } from 'react'; import React, { useState } from 'react'; +import type { KibanaFeature } from '@kbn/features-plugin/common'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import type { Role } from '@kbn/security-plugin-types-common'; import type { Space } from '../../../common'; +import { FeatureTable } from '../edit_space/enabled_features/feature_table'; interface Props { space: Space; roles: Role[]; + features: KibanaFeature[]; } -export const ViewSpaceAssignedRoles: FC = ({ space, roles }) => { +const filterRolesAssignedToSpace = (roles: Role[], space: Space) => { + return roles.filter((role) => + role.kibana.reduce((acc, cur) => { + return ( + (cur.spaces.includes(space.name) || cur.spaces.includes('*')) && + Boolean(cur.base.length) && + acc + ); + }, true) + ); +}; + +export const ViewSpaceAssignedRoles: FC = ({ space, roles, features }) => { const [showRolesPrivilegeEditor, setShowRolesPrivilegeEditor] = useState(false); const getRowProps = (item: Role) => { const { name } = item; @@ -89,12 +114,7 @@ export const ViewSpaceAssignedRoles: FC = ({ space, roles }) => { }, ]; - const rolesInUse = roles.filter((role) => { - const privilegesSum = role.kibana.reduce((sum, privilege) => { - return sum + privilege.base.length; - }, 0); - return privilegesSum > 0; - }); + const rolesInUse = filterRolesAssignedToSpace(roles, space); if (!rolesInUse) { return null; @@ -104,6 +124,7 @@ export const ViewSpaceAssignedRoles: FC = ({ space, roles }) => { <> {showRolesPrivilegeEditor && ( { @@ -143,7 +164,6 @@ export const ViewSpaceAssignedRoles: FC = ({ space, roles }) => { = ({ space, roles }) => { ); }; -interface PrivilegesRolesFormProps { - space: Space; - roles: Role[]; +interface PrivilegesRolesFormProps extends Props { closeFlyout: () => void; onSaveClick: () => void; } export const PrivilegesRolesForm: FC = (props) => { - const { space, roles, onSaveClick, closeFlyout } = props; + const { space, roles, onSaveClick, closeFlyout, features } = props; + + const [selectedRoles, setSelectedRoles] = useState>>([]); + const [spacePrivilege, setSpacePrivilege] = useState<'all' | 'read' | 'custom'>('all'); const getForm = () => { - return ; + return ( + + + ({ + label: role.name, + }))} + selectedOptions={selectedRoles} + onChange={(value) => { + setSelectedRoles(value); + }} + isClearable={true} + data-test-subj="roleSelectionComboBox" + autoFocus + fullWidth + /> + + + + setSpacePrivilege('all')} + > + + + setSpacePrivilege('read')} + > + + + setSpacePrivilege('custom')} + > + + + + + {spacePrivilege === 'custom' && ( + + <> + +

+ +

+
+ + + +
+ )} +
+ ); }; const getSaveButton = () => { @@ -186,9 +291,8 @@ export const PrivilegesRolesForm: FC = (props) => {

Assign role to {space.name}

- - - + +

= (props) => { />

- {getForm()} -
+ + {getForm()} diff --git a/x-pack/plugins/spaces/public/management/view_space/view_space_tabs.tsx b/x-pack/plugins/spaces/public/management/view_space/view_space_tabs.tsx index 07074fd498cb0..d4cd9dc47dca2 100644 --- a/x-pack/plugins/spaces/public/management/view_space/view_space_tabs.tsx +++ b/x-pack/plugins/spaces/public/management/view_space/view_space_tabs.tsx @@ -61,7 +61,7 @@ export const getTabs = (space: Space, features: KibanaFeature[], roles: Role[]): {roles.length} ), - content: , + content: , }, ]; };