Skip to content

Commit

Permalink
[8.x] Fix delete disabled state (#204154) (#204267)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [Fix delete disabled state
(#204154)](#204154)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Christiane (Tina)
Heiligers","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-13T17:39:48Z","message":"Fix
delete disabled state (#204154)\n\nfix
https://github.com/elastic/kibana/issues/204095\r\n\r\nDisables delete
when no saved objects are selected or all objects\r\nselected are hidden
and delete is allowed.\r\n\r\n![Screenshot 2024-12-12 at 18
02\r\n10](https://github.com/user-attachments/assets/e894a087-7906-4905-bd2e-2325a90d37c0)\r\n\r\n\r\n##
Summary\r\n\r\nSummarize your PR. If it involves visual changes include
a screenshot or\r\ngif.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"4ee52227bce2a1ffffaf930d41513bb0c644c199","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor"],"title":"Fix
delete disabled
state","number":204154,"url":"https://github.com/elastic/kibana/pull/204154","mergeCommit":{"message":"Fix
delete disabled state (#204154)\n\nfix
https://github.com/elastic/kibana/issues/204095\r\n\r\nDisables delete
when no saved objects are selected or all objects\r\nselected are hidden
and delete is allowed.\r\n\r\n![Screenshot 2024-12-12 at 18
02\r\n10](https://github.com/user-attachments/assets/e894a087-7906-4905-bd2e-2325a90d37c0)\r\n\r\n\r\n##
Summary\r\n\r\nSummarize your PR. If it involves visual changes include
a screenshot or\r\ngif.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"4ee52227bce2a1ffffaf930d41513bb0c644c199"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204154","number":204154,"mergeCommit":{"message":"Fix
delete disabled state (#204154)\n\nfix
https://github.com/elastic/kibana/issues/204095\r\n\r\nDisables delete
when no saved objects are selected or all objects\r\nselected are hidden
and delete is allowed.\r\n\r\n![Screenshot 2024-12-12 at 18
02\r\n10](https://github.com/user-attachments/assets/e894a087-7906-4905-bd2e-2325a90d37c0)\r\n\r\n\r\n##
Summary\r\n\r\nSummarize your PR. If it involves visual changes include
a screenshot or\r\ngif.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"4ee52227bce2a1ffffaf930d41513bb0c644c199"}}]}]
BACKPORT-->

Co-authored-by: Christiane (Tina) Heiligers <[email protected]>
  • Loading branch information
kibanamachine and TinaHeiligers authored Dec 13, 2024
1 parent c1be2bc commit 8cdb166
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 240 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Table', () => {
expect(component.state().isSearchTextValid).toBe(true);
});

it(`prevents hidden saved objects from being deleted`, () => {
it(`prevents hidden saved objects from being deleted`, async () => {
const selectedSavedObjects = [
{ type: 'visualization', meta: { hiddenType: true } },
{ type: 'search', meta: { hiddenType: true } },
Expand All @@ -124,9 +124,33 @@ describe('Table', () => {
selectedSavedObjects,
capabilities: { savedObjectsManagement: { delete: false } } as any,
};
const component = shallowWithI18nProvider(<Table {...customizedProps} />);
render(
<I18nProvider>
<Table {...customizedProps} />
</I18nProvider>
);

expect(component).toMatchSnapshot();
await waitFor(() => {
expect(screen.getByTestId('savedObjectsManagementDelete')).toBeDisabled();
});
});

it(`disables delete when no objects are selected `, async () => {
const selectedSavedObjects = [] as any;
const customizedProps = {
...defaultProps,
selectedSavedObjects,
capabilities: { savedObjectsManagement: { delete: true } } as any,
};
render(
<I18nProvider>
<Table {...customizedProps} />
</I18nProvider>
);

await waitFor(() => {
expect(screen.getByTestId('savedObjectsManagementDelete')).toBeDisabled();
});
});

it(`allows for automatic refreshing after an action`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ export class Table extends PureComponent<TableProps, TableState> {
const activeActionContents = this.state.activeAction?.render() ?? null;
const exceededResultCount = totalItemCount > MAX_PAGINATED_ITEM;

const allHidden = selectedSavedObjects.every(({ meta: { hiddenType } }) => hiddenType);

const anySelected = selectedSavedObjects.length > 0;
const allHidden =
anySelected && selectedSavedObjects.every(({ meta: { hiddenType } }) => hiddenType);
return (
<Fragment>
{activeActionContents}
Expand All @@ -403,6 +404,8 @@ export class Table extends PureComponent<TableProps, TableState> {
defaultQuery={this.props.initialQuery}
toolsRight={[
<EuiToolTip
data-test-subj="deleteSOToolTip"
key="deleteSOToolTip"
content={
allHidden ? (
<FormattedMessage
Expand All @@ -417,7 +420,9 @@ export class Table extends PureComponent<TableProps, TableState> {
iconType="trash"
color="danger"
onClick={onDelete}
isDisabled={allHidden || !capabilities.savedObjectsManagement.delete}
isDisabled={
!anySelected || allHidden || !capabilities.savedObjectsManagement.delete
}
title={
capabilities.savedObjectsManagement.delete
? undefined
Expand Down

0 comments on commit 8cdb166

Please sign in to comment.