55 * 2.0.
66 */
77
8- import React , { Fragment , useState } from 'react' ;
8+ import React , { Fragment } from 'react' ;
99
10- import {
11- EuiButtonIcon ,
12- EuiFieldSearch ,
13- EuiIconTip ,
14- EuiSpacer ,
15- EuiTable ,
16- EuiTableBody ,
17- EuiTableHeader ,
18- EuiTableHeaderCell ,
19- EuiTableRow ,
20- EuiTableRowCell ,
21- EuiTextColor ,
22- } from '@elastic/eui' ;
23- import { i18n } from '@kbn/i18n' ;
10+ import { EuiTextColor , EuiInMemoryTable , EuiBasicTableColumn } from '@elastic/eui' ;
2411
2512import { ASRoleMapping } from '../../app_search/types' ;
2613import { WSRoleMapping } from '../../workplace_search/types' ;
27- import { MANAGE_BUTTON_LABEL , DELETE_BUTTON_LABEL } from '../constants' ;
2814import { RoleRules } from '../types' ;
2915
3016import './role_mappings_table.scss' ;
@@ -38,7 +24,9 @@ import {
3824 EXTERNAL_ATTRIBUTE_LABEL ,
3925 ATTRIBUTE_VALUE_LABEL ,
4026 FILTER_ROLE_MAPPINGS_PLACEHOLDER ,
27+ ROLE_MAPPINGS_NO_RESULTS_MESSAGE ,
4128} from './constants' ;
29+ import { UsersAndRolesRowActions } from './users_and_roles_row_actions' ;
4230
4331interface AccessItem {
4432 name : string ;
@@ -58,8 +46,6 @@ interface Props {
5846 handleDeleteMapping ( roleMappingId : string ) : void ;
5947}
6048
61- const MAX_CELL_WIDTH = 24 ;
62-
6349const noItemsPlaceholder = < EuiTextColor color = "subdued" > —</ EuiTextColor > ;
6450
6551const getAuthProviderDisplayValue = ( authProvider : string ) =>
@@ -73,114 +59,104 @@ export const RoleMappingsTable: React.FC<Props> = ({
7359 initializeRoleMapping,
7460 handleDeleteMapping,
7561} ) => {
76- const [ filterValue , updateValue ] = useState ( '' ) ;
62+ const getFirstAttributeName = ( rules : RoleRules ) : string => Object . entries ( rules ) [ 0 ] [ 0 ] ;
63+ const getFirstAttributeValue = ( rules : RoleRules ) : string => Object . entries ( rules ) [ 0 ] [ 1 ] ;
7764
7865 // This is needed because App Search has `engines` and Workplace Search has `groups`.
79- const standardizeRoleMapping = ( roleMappings as SharedRoleMapping [ ] ) . map ( ( rm ) => {
66+ const standardizedRoleMappings = ( roleMappings as SharedRoleMapping [ ] ) . map ( ( rm ) => {
8067 const _rm = { ...rm } as SharedRoleMapping ;
8168 _rm . accessItems = rm [ accessItemKey ] ;
8269 return _rm ;
83- } ) ;
84-
85- const filterResults = ( result : SharedRoleMapping ) => {
86- // Filter out non-alphanumeric characters, except for underscores, hyphens, and spaces
87- const sanitizedValue = filterValue . replace ( / [ ^ \w \s - ] / g, '' ) ;
88- const values = Object . values ( result ) ;
89- const regexp = new RegExp ( sanitizedValue , 'i' ) ;
90- return values . filter ( ( x ) => regexp . test ( x ) ) . length > 0 ;
70+ } ) as SharedRoleMapping [ ] ;
71+
72+ const attributeNameCol : EuiBasicTableColumn < SharedRoleMapping > = {
73+ field : 'attribute' ,
74+ name : EXTERNAL_ATTRIBUTE_LABEL ,
75+ render : ( _ , { rules } : SharedRoleMapping ) => getFirstAttributeName ( rules ) ,
9176 } ;
9277
93- const filteredResults = standardizeRoleMapping . filter ( filterResults ) ;
94- const getFirstAttributeName = ( rules : RoleRules ) : string => Object . entries ( rules ) [ 0 ] [ 0 ] ;
95- const getFirstAttributeValue = ( rules : RoleRules ) : string => Object . entries ( rules ) [ 0 ] [ 1 ] ;
78+ const attributeValueCol : EuiBasicTableColumn < SharedRoleMapping > = {
79+ field : 'attributeValue' ,
80+ name : ATTRIBUTE_VALUE_LABEL ,
81+ render : ( _ , { rules } : SharedRoleMapping ) => getFirstAttributeValue ( rules ) ,
82+ } ;
9683
97- const rowActions = ( id : string ) => (
98- < >
99- < EuiButtonIcon
100- onClick = { ( ) => initializeRoleMapping ( id ) }
101- iconType = "pencil"
102- aria-label = { MANAGE_BUTTON_LABEL }
103- data-test-subj = "ManageButton"
104- /> { ' ' }
105- < EuiButtonIcon
106- onClick = { ( ) => handleDeleteMapping ( id ) }
107- iconType = "trash"
108- aria-label = { DELETE_BUTTON_LABEL }
109- data-test-subj = "DeleteButton"
84+ const roleCol : EuiBasicTableColumn < SharedRoleMapping > = {
85+ field : 'roleType' ,
86+ name : ROLE_LABEL ,
87+ render : ( _ , { rules } : SharedRoleMapping ) => getFirstAttributeValue ( rules ) ,
88+ } ;
89+
90+ const accessItemsCol : EuiBasicTableColumn < SharedRoleMapping > = {
91+ field : 'accessItems' ,
92+ name : accessHeader ,
93+ render : ( _ , { accessAllEngines, accessItems } : SharedRoleMapping ) => (
94+ < span data-test-subj = "AccessItemsList" >
95+ { accessAllEngines ? (
96+ ALL_LABEL
97+ ) : (
98+ < >
99+ { accessItems . length === 0
100+ ? noItemsPlaceholder
101+ : accessItems . map ( ( { name } ) => (
102+ < Fragment key = { name } >
103+ { name }
104+ < br />
105+ </ Fragment >
106+ ) ) }
107+ </ >
108+ ) }
109+ </ span >
110+ ) ,
111+ } ;
112+
113+ const authProviderCol : EuiBasicTableColumn < SharedRoleMapping > = {
114+ field : 'authProvider' ,
115+ name : AUTH_PROVIDER_LABEL ,
116+ render : ( _ , { authProvider } : SharedRoleMapping ) => (
117+ < span data-test-subj = "AuthProviderDisplayValue" >
118+ { authProvider . map ( getAuthProviderDisplayValue ) . join ( ', ' ) }
119+ </ span >
120+ ) ,
121+ } ;
122+
123+ const actionsCol : EuiBasicTableColumn < SharedRoleMapping > = {
124+ field : 'id' ,
125+ name : '' ,
126+ align : 'right' ,
127+ render : ( _ , { id } : SharedRoleMapping ) => (
128+ < UsersAndRolesRowActions
129+ onManageClick = { ( ) => initializeRoleMapping ( id ) }
130+ onDeleteClick = { ( ) => handleDeleteMapping ( id ) }
110131 />
111- </ >
112- ) ;
132+ ) ,
133+ } ;
113134
135+ const columns = shouldShowAuthProvider
136+ ? [ attributeNameCol , attributeValueCol , roleCol , accessItemsCol , authProviderCol , actionsCol ]
137+ : [ attributeNameCol , attributeValueCol , roleCol , accessItemsCol , actionsCol ] ;
138+
139+ const pagination = {
140+ hidePerPageOptions : true ,
141+ } ;
142+
143+ const search = {
144+ box : {
145+ incremental : true ,
146+ fullWidth : false ,
147+ placeholder : FILTER_ROLE_MAPPINGS_PLACEHOLDER ,
148+ 'data-test-subj' : 'RoleMappingsTableSearchInput' ,
149+ } ,
150+ } ;
114151 return (
115- < >
116- < EuiFieldSearch
117- value = { filterValue }
118- placeholder = { FILTER_ROLE_MAPPINGS_PLACEHOLDER }
119- onChange = { ( e ) => updateValue ( e . target . value ) }
120- />
121- < EuiSpacer />
122- { filteredResults . length > 0 ? (
123- < EuiTable className = "roleMappingsTable" >
124- < EuiTableHeader >
125- < EuiTableHeaderCell > { EXTERNAL_ATTRIBUTE_LABEL } </ EuiTableHeaderCell >
126- < EuiTableHeaderCell > { ATTRIBUTE_VALUE_LABEL } </ EuiTableHeaderCell >
127- < EuiTableHeaderCell > { ROLE_LABEL } </ EuiTableHeaderCell >
128- < EuiTableHeaderCell > { accessHeader } </ EuiTableHeaderCell >
129- { shouldShowAuthProvider && (
130- < EuiTableHeaderCell > { AUTH_PROVIDER_LABEL } </ EuiTableHeaderCell >
131- ) }
132- < EuiTableHeaderCell />
133- </ EuiTableHeader >
134- < EuiTableBody >
135- { filteredResults . map (
136- ( { id, authProvider, rules, roleType, accessAllEngines, accessItems, toolTip } ) => (
137- < EuiTableRow key = { id } >
138- < EuiTableRowCell > { getFirstAttributeName ( rules ) } </ EuiTableRowCell >
139- < EuiTableRowCell style = { { maxWidth : MAX_CELL_WIDTH } } >
140- { getFirstAttributeValue ( rules ) }
141- </ EuiTableRowCell >
142- < EuiTableRowCell > { roleType } </ EuiTableRowCell >
143- < EuiTableRowCell
144- data-test-subj = "AccessItemsList"
145- style = { { maxWidth : MAX_CELL_WIDTH } }
146- >
147- { accessAllEngines ? (
148- ALL_LABEL
149- ) : (
150- < >
151- { accessItems . length === 0
152- ? noItemsPlaceholder
153- : accessItems . map ( ( { name } ) => (
154- < Fragment key = { name } >
155- { name }
156- < br />
157- </ Fragment >
158- ) ) }
159- </ >
160- ) }
161- </ EuiTableRowCell >
162- { shouldShowAuthProvider && (
163- < EuiTableRowCell data-test-subj = "AuthProviderDisplay" >
164- { authProvider . map ( getAuthProviderDisplayValue ) . join ( ', ' ) }
165- </ EuiTableRowCell >
166- ) }
167- < EuiTableRowCell align = "right" >
168- { id && rowActions ( id ) }
169- { toolTip && < EuiIconTip position = "left" content = { toolTip . content } /> }
170- </ EuiTableRowCell >
171- </ EuiTableRow >
172- )
173- ) }
174- </ EuiTableBody >
175- </ EuiTable >
176- ) : (
177- < p >
178- { i18n . translate ( 'xpack.enterpriseSearch.roleMapping.moResults.message' , {
179- defaultMessage : "No results found for '{filterValue}'" ,
180- values : { filterValue } ,
181- } ) }
182- </ p >
183- ) }
184- </ >
152+ < EuiInMemoryTable
153+ data-test-subj = "RoleMappingsTable"
154+ columns = { columns }
155+ items = { standardizedRoleMappings }
156+ search = { search }
157+ pagination = { pagination }
158+ message = { ROLE_MAPPINGS_NO_RESULTS_MESSAGE }
159+ responsive = { false }
160+ />
185161 ) ;
186162} ;
0 commit comments