Skip to content

Commit

Permalink
[8.7] [Discover] Remove table column after that field was deleted (#1…
Browse files Browse the repository at this point in the history
…50980) (#151684)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Discover] Remove table column after that field was deleted
(#150980)](#150980)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2023-02-21T10:50:27Z","message":"[Discover]
Remove table column after that field was deleted (#150980)\n\nCloses
#150958
#151531
Summary\r\n\r\nThis PR removes the field from table and sidebar after it
was added as a\r\ncolumn but deleted in the end.\r\n\r\nSteps for
testing:\r\n- Create a runtime field\r\n- Add to the table\r\n- Delete
the field and observe that it is removed from the table
and\r\nsidebar.","sha":"406e6c06d187a07b4c2377644e693e43c40d05f2","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","backport:prev-minor","v8.8.0"],"number":150980,"url":"#150980
Remove table column after that field was deleted (#150980)\n\nCloses
#150958
#151531
Summary\r\n\r\nThis PR removes the field from table and sidebar after it
was added as a\r\ncolumn but deleted in the end.\r\n\r\nSteps for
testing:\r\n- Create a runtime field\r\n- Add to the table\r\n- Delete
the field and observe that it is removed from the table
and\r\nsidebar.","sha":"406e6c06d187a07b4c2377644e693e43c40d05f2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"#150980
Remove table column after that field was deleted (#150980)\n\nCloses
#150958
#151531
Summary\r\n\r\nThis PR removes the field from table and sidebar after it
was added as a\r\ncolumn but deleted in the end.\r\n\r\nSteps for
testing:\r\n- Create a runtime field\r\n- Add to the table\r\n- Delete
the field and observe that it is removed from the table
and\r\nsidebar.","sha":"406e6c06d187a07b4c2377644e693e43c40d05f2"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
  • Loading branch information
kibanamachine and jughosta committed Feb 21, 2023
1 parent c2e9d8b commit abbdcf4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,18 @@ export function DiscoverLayout({
[filterManager, dataView, dataViews, trackUiMetric, capabilities]
);

const onFieldEdited = useCallback(async () => {
if (!dataView.isPersisted()) {
await updateAdHocDataViewId(dataView);
}
stateContainer.dataState.refetch$.next('reset');
}, [dataView, stateContainer, updateAdHocDataViewId]);
const onFieldEdited = useCallback(
async ({ removedFieldName }: { removedFieldName?: string } = {}) => {
if (removedFieldName && currentColumns.includes(removedFieldName)) {
onRemoveColumn(removedFieldName);
}
if (!dataView.isPersisted()) {
await updateAdHocDataViewId(dataView);
}
stateContainer.dataState.refetch$.next('reset');
},
[dataView, stateContainer, updateAdHocDataViewId, currentColumns, onRemoveColumn]
);

const onDisableFilters = useCallback(() => {
const disabledFilters = filterManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export interface DiscoverFieldProps {
*/
onAddFilter?: (field: DataViewField | string, value: unknown, type: '+' | '-') => void;
/**
* Callback to remove/deselect a the field
* Callback to remove a field column from the table
* @param fieldName
*/
onRemoveField: (fieldName: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function DiscoverSidebarComponent({
},
fieldName,
onDelete: async () => {
await onFieldEdited();
await onFieldEdited({ removedFieldName: fieldName });
},
});
if (setFieldEditorRef) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface DiscoverSidebarResponsiveProps {
*/
onChangeDataView: (id: string) => void;
/**
* Callback function when removing a field
* Callback to remove a field column from the table
* @param fieldName
*/
onRemoveField: (fieldName: string) => void;
Expand All @@ -100,7 +100,7 @@ export interface DiscoverSidebarResponsiveProps {
/**
* callback to execute on edit runtime field
*/
onFieldEdited: () => Promise<void>;
onFieldEdited: (options?: { removedFieldName?: string }) => Promise<void>;
/**
* callback to execute on create dataview
*/
Expand Down
35 changes: 35 additions & 0 deletions test/functional/apps/discover/group1/_sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const filterBar = getService('filterBar');
const fieldEditor = getService('fieldEditor');
const retry = getService('retry');
const dataGrid = getService('dataGrid');
const INITIAL_FIELD_LIST_SUMMARY = '53 available fields. 0 empty fields. 3 meta fields.';

describe('discover sidebar', function describeIndexTests() {
Expand Down Expand Up @@ -715,6 +716,40 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'test/functional/fixtures/es_archiver/index_pattern_without_timefield'
);
});

it('should remove the table column after a field was deleted', async () => {
const newField = '_test_field_and_column_removal';
await PageObjects.discover.addRuntimeField(newField, `emit("hi there")`);

await retry.waitFor('form to close', async () => {
return !(await testSubjects.exists('fieldEditor'));
});

await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSidebarHasLoaded();

let selectedFields = await PageObjects.discover.getSidebarSectionFieldNames('selected');
expect(selectedFields.includes(newField)).to.be(false);
expect(await dataGrid.getHeaderFields()).to.eql(['@timestamp', 'Document']);

await PageObjects.discover.clickFieldListItemAdd(newField);
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSidebarHasLoaded();

selectedFields = await PageObjects.discover.getSidebarSectionFieldNames('selected');
expect(selectedFields.includes(newField)).to.be(true);
expect(await dataGrid.getHeaderFields()).to.eql(['@timestamp', newField]);

await PageObjects.discover.removeField(newField);
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSidebarHasLoaded();

await retry.waitFor('sidebar to update', async () => {
return !(await PageObjects.discover.getAllFieldNames()).includes(newField);
});

expect(await dataGrid.getHeaderFields()).to.eql(['@timestamp', 'Document']);
});
});
});
}

0 comments on commit abbdcf4

Please sign in to comment.