Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Show "unsaved changes" label when in unsaved state of saved search #169548

Merged
merged 38 commits into from Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
126de49
[Discover] Introduce unsaved_changes_badge package
jughosta Oct 23, 2023
d39741a
[Discover] Add actions to the context menu
jughosta Oct 23, 2023
ee46448
[Discover] Implement reset
jughosta Oct 23, 2023
fb015aa
[Discover] Add save actions
jughosta Oct 23, 2023
5a9b107
[Discover] Remove reset button from histogram
jughosta Oct 23, 2023
a2748dc
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Oct 23, 2023
e2f255a
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Oct 23, 2023
69de59b
[Discover] Update the icon
jughosta Oct 23, 2023
defc078
Merge remote-tracking branch 'origin/135887-discover-unsaved-changes'…
jughosta Oct 23, 2023
c2e8661
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 23, 2023
686ad60
[Discover] Add missing logic
jughosta Oct 24, 2023
e4dea54
[Discover] Add tests
jughosta Oct 24, 2023
4399d28
[Discover] Update tests
jughosta Oct 24, 2023
e3728d6
[Discover] Add comments and update tests
jughosta Oct 24, 2023
78a0653
[Discover] Rename to revert
jughosta Oct 24, 2023
98da9e3
[Discover] Add tests
jughosta Oct 24, 2023
583d2c7
[Discover] Add functional tests
jughosta Oct 24, 2023
0af0520
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 24, 2023
9fdb6ab
[Discover] Support customization
jughosta Oct 24, 2023
3949ec4
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 24, 2023
726e3f3
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 25, 2023
bc7b0e5
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 25, 2023
3bb3c36
[Discover] Handle clearing the breakdown field
jughosta Oct 25, 2023
efe2913
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 26, 2023
7039e5b
[Discover] Fix for the test
jughosta Oct 26, 2023
08b838d
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 27, 2023
b273e07
[Discover] Fix badge clicks
jughosta Oct 27, 2023
5262a24
[Discover] Update diffing logic
jughosta Oct 27, 2023
65f8cbd
[Discover] Update saved search changes
jughosta Oct 27, 2023
ff08dd2
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Oct 27, 2023
9424da3
[Discover] Update test
jughosta Oct 27, 2023
968cb95
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Nov 1, 2023
cff1810
[Discover] Address TS errors
jughosta Nov 1, 2023
38fb7c9
Merge branch 'main' into 135887-discover-unsaved-changes
kibanamachine Nov 1, 2023
35be168
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Nov 1, 2023
316ec35
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Nov 8, 2023
c1dd889
Merge branch 'main' into 135887-discover-unsaved-changes
jughosta Nov 13, 2023
d83fe6e
[Discover] Update tests
jughosta Nov 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -791,6 +791,7 @@ packages/kbn-unified-field-list @elastic/kibana-data-discovery
examples/unified_field_list_examples @elastic/kibana-data-discovery
src/plugins/unified_histogram @elastic/kibana-data-discovery
src/plugins/unified_search @elastic/kibana-visualizations
packages/kbn-unsaved-changes-badge @elastic/kibana-data-discovery
x-pack/plugins/upgrade_assistant @elastic/platform-deployment-management
x-pack/plugins/uptime @elastic/uptime
x-pack/plugins/drilldowns/url_drilldown @elastic/appex-sharedux
Expand Down
3 changes: 2 additions & 1 deletion .i18nrc.json
Expand Up @@ -132,7 +132,8 @@
"unifiedSearch": "src/plugins/unified_search",
"unifiedFieldList": "packages/kbn-unified-field-list",
"unifiedHistogram": "src/plugins/unified_histogram",
"unifiedDataTable": "packages/kbn-unified-data-table"
"unifiedDataTable": "packages/kbn-unified-data-table",
"unsavedChangesBadge": "packages/kbn-unsaved-changes-badge"
},
"translations": []
}
11 changes: 11 additions & 0 deletions examples/discover_customization_examples/public/plugin.tsx
Expand Up @@ -163,6 +163,17 @@ export class DiscoverCustomizationExamplesPlugin implements Plugin {
order: 300,
},
],
getBadges: () => {
return [
{
data: {
badgeText: 'Example badge',
color: 'warning',
},
order: 10,
},
];
},
});

customizations.set({
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -782,6 +782,7 @@
"@kbn/unified-field-list-examples-plugin": "link:examples/unified_field_list_examples",
"@kbn/unified-histogram-plugin": "link:src/plugins/unified_histogram",
"@kbn/unified-search-plugin": "link:src/plugins/unified_search",
"@kbn/unsaved-changes-badge": "link:packages/kbn-unsaved-changes-badge",
"@kbn/upgrade-assistant-plugin": "link:x-pack/plugins/upgrade_assistant",
"@kbn/uptime-plugin": "link:x-pack/plugins/uptime",
"@kbn/url-drilldown-plugin": "link:x-pack/plugins/drilldowns/url_drilldown",
Expand Down
8 changes: 8 additions & 0 deletions packages/kbn-unsaved-changes-badge/README.md
@@ -0,0 +1,8 @@
# @kbn/unsaved-changes-badge

A yellow "Unsaved changes" badge which can be found for example on Discover page.
It supports callbacks to save or revert the changes.

To integrate it into TopNav component, consider using `getTopNavUnsavedChangesBadge(...)` util and pass the result to `badges` prop of the top nav.

There is also a standalone component `<UnsavedChangesBadge .../>`.
17 changes: 17 additions & 0 deletions packages/kbn-unsaved-changes-badge/index.ts
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export {
UnsavedChangesBadge,
type UnsavedChangesBadgeProps,
} from './src/components/unsaved_changes_badge';

export {
getTopNavUnsavedChangesBadge,
type TopNavUnsavedChangesBadgeParams,
} from './src/utils/get_top_nav_unsaved_changes_badge';
13 changes: 13 additions & 0 deletions packages/kbn-unsaved-changes-badge/jest.config.js
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-unsaved-changes-badge'],
};
5 changes: 5 additions & 0 deletions packages/kbn-unsaved-changes-badge/kibana.jsonc
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/unsaved-changes-badge",
"owner": "@elastic/kibana-data-discovery"
}
10 changes: 10 additions & 0 deletions packages/kbn-unsaved-changes-badge/package.json
@@ -0,0 +1,10 @@
{
"name": "@kbn/unsaved-changes-badge",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": [
"*.css",
"*.scss"
]
}

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

@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { UnsavedChangesBadge, type UnsavedChangesBadgeProps } from './unsaved_changes_badge';
@@ -0,0 +1,90 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { screen, waitFor } from '@testing-library/dom';
import { render, act } from '@testing-library/react';
import { UnsavedChangesBadge } from './unsaved_changes_badge';

describe('<UnsavedChangesBadge />', () => {
test('should render correctly', async () => {
const onRevert = jest.fn();
const { getByTestId, queryByTestId } = render(
<UnsavedChangesBadge badgeText="test" onRevert={onRevert} />
);
expect(getByTestId('unsavedChangesBadge')).toBeInTheDocument();

getByTestId('unsavedChangesBadge').click();
await waitFor(() => {
return Boolean(queryByTestId('unsavedChangesBadgeMenuPanel'));
});
expect(queryByTestId('revertUnsavedChangesButton')).toBeInTheDocument();
expect(queryByTestId('saveUnsavedChangesButton')).not.toBeInTheDocument();
expect(queryByTestId('saveUnsavedChangesAsButton')).not.toBeInTheDocument();

expect(onRevert).not.toHaveBeenCalled();

act(() => {
getByTestId('revertUnsavedChangesButton').click();
});
expect(onRevert).toHaveBeenCalled();
});

test('should show all menu items', async () => {
const onRevert = jest.fn().mockResolvedValue(true);
const onSave = jest.fn().mockResolvedValue(true);
const onSaveAs = jest.fn().mockResolvedValue(true);
const { getByTestId, queryByTestId, container } = render(
<UnsavedChangesBadge
badgeText="test"
onRevert={onRevert}
onSave={onSave}
onSaveAs={onSaveAs}
/>
);

expect(container).toMatchSnapshot();

getByTestId('unsavedChangesBadge').click();
await waitFor(() => {
return Boolean(queryByTestId('unsavedChangesBadgeMenuPanel'));
});
expect(queryByTestId('revertUnsavedChangesButton')).toBeInTheDocument();
expect(queryByTestId('saveUnsavedChangesButton')).toBeInTheDocument();
expect(queryByTestId('saveUnsavedChangesAsButton')).toBeInTheDocument();

expect(screen.getByTestId('unsavedChangesBadgeMenuPanel')).toMatchSnapshot();
});

test('should call callbacks', async () => {
const onRevert = jest.fn().mockResolvedValue(true);
const onSave = jest.fn().mockResolvedValue(true);
const onSaveAs = jest.fn().mockResolvedValue(true);
const { getByTestId, queryByTestId } = render(
<UnsavedChangesBadge
badgeText="test"
onRevert={onRevert}
onSave={onSave}
onSaveAs={onSaveAs}
/>
);
act(() => {
getByTestId('unsavedChangesBadge').click();
});
await waitFor(() => {
return Boolean(queryByTestId('unsavedChangesBadgeMenuPanel'));
});

expect(onSave).not.toHaveBeenCalled();

act(() => {
getByTestId('saveUnsavedChangesButton').click();
});
expect(onSave).toHaveBeenCalled();
});
});