-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Dashboard First] Library Notification #76122
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
Merged
ThomThomson
merged 9 commits into
elastic:master
from
ThomThomson:feature/byReferenceBadgeViaMenuItem
Sep 1, 2020
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3fdc6ef
started badge design
ThomThomson 937ffb9
Merge branch 'master' of github.com:elastic/kibana into feature/byRef…
ThomThomson 4719b92
Made library badge only compatible with ReferenceOrValueEmbeddables
ThomThomson 5e9d5f3
type fixes, config value reset
ThomThomson ad224a7
Merge branch 'master' of github.com:elastic/kibana into feature/byRef…
ThomThomson 0a6b5d2
Wrote library notification using the MenuItem prop from action. Allow…
ThomThomson 9a608f5
Undid config change
ThomThomson 4459c58
Merge branch 'master' into feature/byReferenceBadgeViaMenuItem
elasticmachine 5fdc561
removed unneeded boolean cast
ThomThomson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/plugins/dashboard/public/application/actions/library_notification_action.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { isErrorEmbeddable, ReferenceOrValueEmbeddable } from '../../embeddable_plugin'; | ||
| import { DashboardContainer } from '../embeddable'; | ||
| import { getSampleDashboardInput } from '../test_helpers'; | ||
| import { | ||
| CONTACT_CARD_EMBEDDABLE, | ||
| ContactCardEmbeddableFactory, | ||
| ContactCardEmbeddable, | ||
| ContactCardEmbeddableInput, | ||
| ContactCardEmbeddableOutput, | ||
| } from '../../embeddable_plugin_test_samples'; | ||
| import { coreMock } from '../../../../../core/public/mocks'; | ||
| import { CoreStart } from 'kibana/public'; | ||
| import { LibraryNotificationAction } from '.'; | ||
| import { embeddablePluginMock } from 'src/plugins/embeddable/public/mocks'; | ||
| import { ViewMode } from '../../../../embeddable/public'; | ||
|
|
||
| const { setup, doStart } = embeddablePluginMock.createInstance(); | ||
| setup.registerEmbeddableFactory( | ||
| CONTACT_CARD_EMBEDDABLE, | ||
| new ContactCardEmbeddableFactory((() => null) as any, {} as any) | ||
| ); | ||
| const start = doStart(); | ||
|
|
||
| let container: DashboardContainer; | ||
| let embeddable: ContactCardEmbeddable & ReferenceOrValueEmbeddable; | ||
| let coreStart: CoreStart; | ||
| beforeEach(async () => { | ||
| coreStart = coreMock.createStart(); | ||
|
|
||
| const containerOptions = { | ||
| ExitFullScreenButton: () => null, | ||
| SavedObjectFinder: () => null, | ||
| application: {} as any, | ||
| embeddable: start, | ||
| inspector: {} as any, | ||
| notifications: {} as any, | ||
| overlays: coreStart.overlays, | ||
| savedObjectMetaData: {} as any, | ||
| uiActions: {} as any, | ||
| }; | ||
|
|
||
| container = new DashboardContainer(getSampleDashboardInput(), containerOptions); | ||
|
|
||
| const contactCardEmbeddable = await container.addNewEmbeddable< | ||
| ContactCardEmbeddableInput, | ||
| ContactCardEmbeddableOutput, | ||
| ContactCardEmbeddable | ||
| >(CONTACT_CARD_EMBEDDABLE, { | ||
| firstName: 'Kibanana', | ||
| }); | ||
|
|
||
| if (isErrorEmbeddable(contactCardEmbeddable)) { | ||
| throw new Error('Failed to create embeddable'); | ||
| } | ||
| embeddable = embeddablePluginMock.mockRefOrValEmbeddable< | ||
| ContactCardEmbeddable, | ||
| ContactCardEmbeddableInput | ||
| >(contactCardEmbeddable, { | ||
| mockedByReferenceInput: { savedObjectId: 'testSavedObjectId', id: contactCardEmbeddable.id }, | ||
| mockedByValueInput: { firstName: 'Kibanana', id: contactCardEmbeddable.id }, | ||
| }); | ||
| embeddable.updateInput({ viewMode: ViewMode.EDIT }); | ||
| }); | ||
|
|
||
| test('Notification is shown when embeddable on dashboard has reference type input', async () => { | ||
| const action = new LibraryNotificationAction(); | ||
| embeddable.updateInput(await embeddable.getInputAsRefType()); | ||
| expect(await action.isCompatible({ embeddable })).toBe(true); | ||
| }); | ||
|
|
||
| test('Notification is not shown when embeddable input is by value', async () => { | ||
| const action = new LibraryNotificationAction(); | ||
| embeddable.updateInput(await embeddable.getInputAsValueType()); | ||
| expect(await action.isCompatible({ embeddable })).toBe(false); | ||
| }); | ||
|
|
||
| test('Notification is not shown when view mode is set to view', async () => { | ||
| const action = new LibraryNotificationAction(); | ||
| embeddable.updateInput(await embeddable.getInputAsRefType()); | ||
| embeddable.updateInput({ viewMode: ViewMode.VIEW }); | ||
| expect(await action.isCompatible({ embeddable })).toBe(false); | ||
| }); |
89 changes: 89 additions & 0 deletions
89
src/plugins/dashboard/public/application/actions/library_notification_action.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { EuiBadge } from '@elastic/eui'; | ||
| import { IEmbeddable, ViewMode, isReferenceOrValueEmbeddable } from '../../embeddable_plugin'; | ||
| import { ActionByType, IncompatibleActionError } from '../../ui_actions_plugin'; | ||
| import { reactToUiComponent } from '../../../../kibana_react/public'; | ||
|
|
||
| export const ACTION_LIBRARY_NOTIFICATION = 'ACTION_LIBRARY_NOTIFICATION'; | ||
|
|
||
| export interface LibraryNotificationActionContext { | ||
| embeddable: IEmbeddable; | ||
| } | ||
|
|
||
| export class LibraryNotificationAction implements ActionByType<typeof ACTION_LIBRARY_NOTIFICATION> { | ||
| public readonly id = ACTION_LIBRARY_NOTIFICATION; | ||
| public readonly type = ACTION_LIBRARY_NOTIFICATION; | ||
| public readonly order = 1; | ||
|
|
||
| private displayName = i18n.translate('dashboard.panel.LibraryNotification', { | ||
| defaultMessage: 'Library', | ||
| }); | ||
|
|
||
| private icon = 'folderCheck'; | ||
|
|
||
| public readonly MenuItem = reactToUiComponent(() => ( | ||
| <EuiBadge | ||
| data-test-subj={`embeddablePanelNotification-${this.id}`} | ||
| iconType={this.icon} | ||
| key={this.id} | ||
| style={{ marginTop: '2px', marginRight: '4px' }} | ||
| color="hollow" | ||
| > | ||
| {this.displayName} | ||
| </EuiBadge> | ||
| )); | ||
|
|
||
| public getDisplayName({ embeddable }: LibraryNotificationActionContext) { | ||
| if (!embeddable.getRoot() || !embeddable.getRoot().isContainer) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| return this.displayName; | ||
| } | ||
|
|
||
| public getIconType({ embeddable }: LibraryNotificationActionContext) { | ||
| if (!embeddable.getRoot() || !embeddable.getRoot().isContainer) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| return this.icon; | ||
| } | ||
|
|
||
| public getDisplayNameTooltip = ({ embeddable }: LibraryNotificationActionContext) => { | ||
| if (!embeddable.getRoot() || !embeddable.getRoot().isContainer) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| return i18n.translate('dashboard.panel.libraryNotification.toolTip', { | ||
| defaultMessage: | ||
| 'This panel is linked to a Library item. Editing the panel might affect other dashboards.', | ||
| }); | ||
| }; | ||
|
|
||
| public isCompatible = async ({ embeddable }: LibraryNotificationActionContext) => { | ||
| return Boolean( | ||
| embeddable.getInput()?.viewMode !== ViewMode.VIEW && | ||
| isReferenceOrValueEmbeddable(embeddable) && | ||
| embeddable.inputIsRefType(embeddable.getInput()) | ||
| ); | ||
| }; | ||
|
|
||
| public execute = async () => {}; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can omit Boolean() here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Removed that