mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [Fix delete disabled state (#204154)](https://github.com/elastic/kibana/pull/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":"christiane.heiligers@elastic.co"},"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\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\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\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 <christiane.heiligers@elastic.co>
This commit is contained in:
parent
c1be2bcafd
commit
8cdb16672a
3 changed files with 36 additions and 240 deletions
|
@ -1,239 +1,5 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Table prevents hidden saved objects from being deleted 1`] = `
|
||||
<Fragment>
|
||||
<EuiSearchBar
|
||||
box={
|
||||
Object {
|
||||
"data-test-subj": "savedObjectSearchBar",
|
||||
"schema": Object {
|
||||
"recognizedFields": Array [
|
||||
"type",
|
||||
"tag",
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
filters={
|
||||
Array [
|
||||
Object {
|
||||
"field": "type",
|
||||
"multiSelect": "or",
|
||||
"name": "Type",
|
||||
"options": Array [
|
||||
Object {
|
||||
"value": 2,
|
||||
},
|
||||
],
|
||||
"type": "field_value_selection",
|
||||
},
|
||||
]
|
||||
}
|
||||
onChange={[Function]}
|
||||
toolsRight={
|
||||
Array [
|
||||
<EuiToolTip
|
||||
content={
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="Selected objects can’t be deleted because they are hidden objects."
|
||||
id="savedObjectsManagement.objectsTable.table.deleteDisabledTooltip"
|
||||
/>
|
||||
}
|
||||
delay="regular"
|
||||
display="inlineBlock"
|
||||
position="top"
|
||||
>
|
||||
<EuiButton
|
||||
color="danger"
|
||||
data-test-subj="savedObjectsManagementDelete"
|
||||
iconType="trash"
|
||||
isDisabled={true}
|
||||
onClick={[Function]}
|
||||
title="Unable to delete saved objects"
|
||||
>
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="Delete"
|
||||
id="savedObjectsManagement.objectsTable.table.deleteButtonLabel"
|
||||
/>
|
||||
</EuiButton>
|
||||
</EuiToolTip>,
|
||||
<EuiPopover
|
||||
anchorPosition="downCenter"
|
||||
button={
|
||||
<EuiButton
|
||||
iconSide="right"
|
||||
iconType="arrowDown"
|
||||
isDisabled={false}
|
||||
onClick={[Function]}
|
||||
>
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="Export"
|
||||
id="savedObjectsManagement.objectsTable.table.exportPopoverButtonLabel"
|
||||
/>
|
||||
</EuiButton>
|
||||
}
|
||||
closePopover={[Function]}
|
||||
display="inline-block"
|
||||
hasArrow={true}
|
||||
isOpen={false}
|
||||
ownFocus={true}
|
||||
panelPaddingSize="m"
|
||||
repositionToCrossAxis={true}
|
||||
>
|
||||
<EuiFormRow
|
||||
label={
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="Options"
|
||||
id="savedObjectsManagement.objectsTable.exportObjectsConfirmModal.exportOptionsLabel"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<EuiSwitch
|
||||
checked={true}
|
||||
label={
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="Include related objects"
|
||||
id="savedObjectsManagement.objectsTable.exportObjectsConfirmModal.includeReferencesDeepLabel"
|
||||
/>
|
||||
}
|
||||
name="includeReferencesDeep"
|
||||
onChange={[Function]}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<EuiFormRow>
|
||||
<EuiButton
|
||||
fill={true}
|
||||
iconType="exportAction"
|
||||
onClick={[Function]}
|
||||
>
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="Export"
|
||||
id="savedObjectsManagement.objectsTable.table.exportButtonLabel"
|
||||
/>
|
||||
</EuiButton>
|
||||
</EuiFormRow>
|
||||
</EuiPopover>,
|
||||
]
|
||||
}
|
||||
/>
|
||||
<EuiSpacer />
|
||||
<div
|
||||
data-test-subj="savedObjectsTable"
|
||||
>
|
||||
<EuiBasicTable
|
||||
columns={
|
||||
Array [
|
||||
Object {
|
||||
"align": "center",
|
||||
"data-test-subj": "savedObjectsTableRowType",
|
||||
"description": "Type of the saved object",
|
||||
"field": "type",
|
||||
"name": "Type",
|
||||
"render": [Function],
|
||||
"sortable": true,
|
||||
"width": "65px",
|
||||
},
|
||||
Object {
|
||||
"data-test-subj": "savedObjectsTableRowTitle",
|
||||
"dataType": "string",
|
||||
"description": "Title of the saved object",
|
||||
"field": "meta.title",
|
||||
"name": "Title",
|
||||
"render": [Function],
|
||||
"sortable": false,
|
||||
},
|
||||
Object {
|
||||
"field": "updated_at",
|
||||
"name": "Last updated",
|
||||
"render": [Function],
|
||||
"sortable": true,
|
||||
"width": "150px",
|
||||
},
|
||||
Object {
|
||||
"actions": Array [
|
||||
Object {
|
||||
"data-test-subj": "savedObjectsTableAction-inspect",
|
||||
"description": "Inspect this saved object",
|
||||
"icon": "inspect",
|
||||
"name": "Inspect",
|
||||
"onClick": [Function],
|
||||
"type": "icon",
|
||||
},
|
||||
Object {
|
||||
"data-test-subj": "savedObjectsTableAction-relationships",
|
||||
"description": "View the relationships this saved object has to other saved objects",
|
||||
"icon": "kqlSelector",
|
||||
"name": "Relationships",
|
||||
"onClick": [Function],
|
||||
"type": "icon",
|
||||
},
|
||||
],
|
||||
"name": "Actions",
|
||||
"width": "80px",
|
||||
},
|
||||
]
|
||||
}
|
||||
itemId="id"
|
||||
items={
|
||||
Array [
|
||||
Object {
|
||||
"attributes": Object {},
|
||||
"id": "1",
|
||||
"meta": Object {
|
||||
"editUrl": "#/management/kibana/dataViews/dataView/1",
|
||||
"icon": "indexPatternApp",
|
||||
"inAppUrl": Object {
|
||||
"path": "/management/kibana/dataViews/dataView/1",
|
||||
"uiCapabilitiesPath": "management.kibana.indexPatterns",
|
||||
},
|
||||
"title": "MyIndexPattern*",
|
||||
},
|
||||
"references": Array [],
|
||||
"type": "index-pattern",
|
||||
},
|
||||
]
|
||||
}
|
||||
loading={false}
|
||||
noItemsMessage={
|
||||
<EuiI18n
|
||||
default="No items found"
|
||||
token="euiBasicTable.noItemsMessage"
|
||||
/>
|
||||
}
|
||||
onChange={[Function]}
|
||||
pagination={
|
||||
Object {
|
||||
"pageIndex": 1,
|
||||
"pageSize": 2,
|
||||
"pageSizeOptions": Array [
|
||||
5,
|
||||
10,
|
||||
20,
|
||||
50,
|
||||
],
|
||||
"totalItemCount": 3,
|
||||
}
|
||||
}
|
||||
rowProps={[Function]}
|
||||
selection={
|
||||
Object {
|
||||
"onSelectionChange": [Function],
|
||||
}
|
||||
}
|
||||
sorting={
|
||||
Object {
|
||||
"sort": Object {
|
||||
"direction": "desc",
|
||||
"field": "updated_at",
|
||||
},
|
||||
}
|
||||
}
|
||||
tableLayout="fixed"
|
||||
/>
|
||||
</div>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`Table should render normally 1`] = `
|
||||
<Fragment>
|
||||
<EuiSearchBar
|
||||
|
@ -267,6 +33,7 @@ exports[`Table should render normally 1`] = `
|
|||
toolsRight={
|
||||
Array [
|
||||
<EuiToolTip
|
||||
data-test-subj="deleteSOToolTip"
|
||||
delay="regular"
|
||||
display="inlineBlock"
|
||||
position="top"
|
||||
|
|
|
@ -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 } },
|
||||
|
@ -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`, () => {
|
||||
|
|
|
@ -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}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue