Skip to content

Commit ba5a5c6

Browse files
authored
[Security][EuiInMemoryTable] Replace usage of deprecated ref method with controlled selection.selected API (#175838)
Closes #175836 ## Summary **Please help us QA your affected tables to confirm that your plugin's table selection still works as before!** EUI will shortly be removing this deprecated ref `setSelection` method in favor of the new controlled `selection.selected` prop. This PR converts the Security plugin's basic usages of controlled selection and additionally removes 2 deletion cancellation behaviors on the team's request. There should not be any other UI/UX regressions when selecting rows. See also: - elastic/eui#7321 - #175722 (examples of basic conversions)
1 parent da17447 commit ba5a5c6

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export class RoleMappingsGridPage extends Component<Props, State> {
7474
readOnly: false,
7575
};
7676

77-
private tableRef: React.RefObject<EuiInMemoryTable<RoleMapping>>;
7877
constructor(props: any) {
7978
super(props);
8079
this.state = {
@@ -85,7 +84,6 @@ export class RoleMappingsGridPage extends Component<Props, State> {
8584
selectedItems: [],
8685
error: undefined,
8786
};
88-
this.tableRef = React.createRef();
8987
}
9088

9189
public componentDidMount() {
@@ -226,6 +224,7 @@ export class RoleMappingsGridPage extends Component<Props, State> {
226224
selectedItems: newSelectedItems,
227225
});
228226
},
227+
selected: selectedItems,
229228
};
230229

231230
const search = {
@@ -237,13 +236,7 @@ export class RoleMappingsGridPage extends Component<Props, State> {
237236
{(deleteRoleMappingsPrompt) => {
238237
return (
239238
<EuiButton
240-
onClick={() =>
241-
deleteRoleMappingsPrompt(
242-
selectedItems,
243-
this.onRoleMappingsDeleted,
244-
this.onRoleMappingsDeleteCancel
245-
)
246-
}
239+
onClick={() => deleteRoleMappingsPrompt(selectedItems, this.onRoleMappingsDeleted)}
247240
color="danger"
248241
data-test-subj="bulkDeleteActionButton"
249242
>
@@ -298,7 +291,6 @@ export class RoleMappingsGridPage extends Component<Props, State> {
298291
loading={loadState === 'loadingTable'}
299292
message={message}
300293
isSelectable={true}
301-
ref={this.tableRef}
302294
rowProps={() => {
303295
return {
304296
'data-test-subj': 'roleMappingRow',
@@ -499,10 +491,6 @@ export class RoleMappingsGridPage extends Component<Props, State> {
499491
}
500492
};
501493

502-
private onRoleMappingsDeleteCancel = () => {
503-
this.tableRef.current?.setSelection([]);
504-
};
505-
506494
private async checkPrivileges() {
507495
try {
508496
const { canManageRoleMappings, hasCompatibleRealms } =

x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class RolesGridPage extends Component<Props, State> {
6868
readOnly: false,
6969
};
7070

71-
private tableRef: React.RefObject<EuiInMemoryTable<Role>>;
7271
constructor(props: Props) {
7372
super(props);
7473
this.state = {
@@ -80,7 +79,6 @@ export class RolesGridPage extends Component<Props, State> {
8079
permissionDenied: false,
8180
includeReservedRoles: true,
8281
};
83-
this.tableRef = React.createRef();
8482
}
8583

8684
public componentDidMount() {
@@ -156,6 +154,7 @@ export class RolesGridPage extends Component<Props, State> {
156154
selectableMessage: (selectable: boolean) =>
157155
!selectable ? 'Role is reserved' : '',
158156
onSelectionChange: (selection: Role[]) => this.setState({ selection }),
157+
selected: this.state.selection,
159158
}
160159
}
161160
pagination={{
@@ -188,7 +187,6 @@ export class RolesGridPage extends Component<Props, State> {
188187
direction: 'asc',
189188
},
190189
}}
191-
ref={this.tableRef}
192190
rowProps={(role: Role) => {
193191
return {
194192
'data-test-subj': `roleRow`,
@@ -484,7 +482,6 @@ export class RolesGridPage extends Component<Props, State> {
484482
);
485483
}
486484
private onCancelDelete = () => {
487-
this.setState({ showDeleteConfirmation: false, selection: [] });
488-
this.tableRef.current?.setSelection([]);
485+
this.setState({ showDeleteConfirmation: false });
489486
};
490487
}

0 commit comments

Comments
 (0)