-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Lens] Enable read only editor mode to inspect panel's configuration #208554
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
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
b28b798
:lipstick: Enable read only mode for the flyout
dej611 5f78ceb
:white_check_mark: Add tests
dej611 26f96b6
:sparkles: New show config action
dej611 2a67834
:white_check_mark: Add tests
dej611 7c3a49d
:sparkles: Enabled read only api
dej611 6c6f7f3
:white_check_mark: Add tests
dej611 88bea79
:wrench: Add read only typeguards
dej611 1ab9a8a
:sparkles: Add action complementary functions
dej611 ff5cdcd
:wrench: Export new action
dej611 9536d39
:sparkles: Enable show config action on hover quick actions
dej611 233ae77
:recycle: Refactor edit/show logic
dej611 4d5f159
:white_check_mark: Add tests
dej611 ba66538
:lipstick: Change icon to wrench
dej611 34ff73b
:sparkles: Enable read only panels in embeddable
dej611 8fa0749
Merge remote-tracking branch 'upstream/main' into fix/106553
dej611 8980e3c
:label: Fix types
dej611 af5eb85
:label: Fix type
dej611 903d98b
:wrench: Updated limits
dej611 77606e6
Update src/platform/packages/shared/presentation/presentation_publish…
dej611 37adbd8
:fire: Remove unused module
dej611 2078fc3
:wrench: Update limits
dej611 f9d4fa0
Merge branch 'fix/106553' of https://github.com/dej611/kibana into fi…
dej611 1cf4957
:sparkles: Enhance return type
dej611 8857562
:sparkles: Make title and icon dynamic based on permissions
dej611 faaf03f
:sparkles: Make title dynamic based on context
dej611 57baf06
:white_check_mark: Enhance return type and add more test scenarios
dej611 faa7c27
:ok_hand: Integrated feedback
dej611 2c17bc5
Merge remote-tracking branch 'upstream/main' into fix/106553
dej611 554bb50
:label: Fix types with the new names
dej611 ad3ec2c
Merge branch 'main' into fix/106553
dej611 8bb8030
:ok_hand: Integrate new ux feedback
dej611 ed6f8f6
:white_check_mark: Update tests with managed scenarios
dej611 22607f2
:fire: remove unused translations
dej611 d90ca72
Merge branch 'main' into fix/106553
dej611 1818e1e
Merge branch 'main' into fix/106553
dej611 101890d
Merge branch 'main' into fix/106553
dej611 c661857
:ok_hand: Apply suggestions from code review
dej611 659235f
Merge branch 'main' into fix/106553
dej611 98af290
:fire: Removed unused translations
dej611 4ae9ab1
Merge remote-tracking branch 'upstream/main' into fix/106553
dej611 22f90b3
Merge remote-tracking branch 'upstream/main' into fix/106553
dej611 ba46222
:recycle: Sync with new changes
dej611 c3df978
:ok_hand: Integrate feedback
dej611 830429c
:white_check_mark: Adapt tests for new API
dej611 7662660
:white_check_mark: Add FTR test
dej611 139ca11
Merge remote-tracking branch 'upstream/main' into fix/106553
dej611 54deb76
:white_check_mark: Fix tests
dej611 dc028c6
Merge branch 'main' into fix/106553
dej611 d9d56e5
Update src/platform/plugins/private/presentation_panel/public/panel_a…
dej611 daabf8a
Merge branch 'main' into fix/106553
dej611 f9e9cf6
Update x-pack/platform/plugins/shared/lens/public/app_plugin/shared/e…
dej611 7077e65
Merge remote-tracking branch 'upstream/main' into fix/106553
dej611 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
33 changes: 33 additions & 0 deletions
33
...ages/shared/presentation/presentation_publishing/interfaces/has_read_only_capabilities.ts
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,33 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { HasTypeDisplayName } from './has_type'; | ||
|
|
||
| /** | ||
| * An interface which determines whether or not a given API offers to show the config for read only permissions. | ||
| * In order to be read only, the api requires a show config function to execute the action | ||
| * a getTypeDisplayName function to display to the user which type of chart is being | ||
| * shown, and an isReadOnlyEnabled function. | ||
| */ | ||
| export interface HasReadOnlyCapabilities extends HasTypeDisplayName { | ||
| onShowConfig: () => Promise<void>; | ||
| isReadOnlyEnabled: () => { read: boolean; write: boolean }; | ||
| } | ||
|
|
||
| /** | ||
| * A type guard which determines whether or not a given API is editable. | ||
| */ | ||
| export const hasReadOnlyCapabilities = (root: unknown): root is HasReadOnlyCapabilities => { | ||
| return Boolean( | ||
| root && | ||
| typeof (root as HasReadOnlyCapabilities).onShowConfig === 'function' && | ||
| typeof (root as HasReadOnlyCapabilities).getTypeDisplayName === 'function' && | ||
| typeof (root as HasReadOnlyCapabilities).isReadOnlyEnabled === 'function' | ||
| ); | ||
| }; |
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
10 changes: 10 additions & 0 deletions
10
...ins/private/presentation_panel/public/panel_actions/show_config_panel_action/constants.ts
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,10 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| export const ACTION_SHOW_CONFIG_PANEL = 'ACTION_SHOW_CONFIG_PANEL'; |
67 changes: 67 additions & 0 deletions
67
...ion_panel/public/panel_actions/show_config_panel_action/show_config_panel_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,67 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { PublishesViewMode, ViewMode } from '@kbn/presentation-publishing'; | ||
| import { BehaviorSubject, take } from 'rxjs'; | ||
| import { ShowConfigPanelAction, ShowConfigPanelActionApi } from './show_config_panel_action'; | ||
|
|
||
| describe('Show config panel action', () => { | ||
| let action: ShowConfigPanelAction; | ||
| let context: { embeddable: ShowConfigPanelActionApi }; | ||
| let updateViewMode: (viewMode: ViewMode) => void; | ||
|
|
||
| beforeEach(() => { | ||
| const viewModeSubject = new BehaviorSubject<ViewMode>('view'); | ||
| updateViewMode = jest.fn((viewMode) => viewModeSubject.next(viewMode)); | ||
|
|
||
| action = new ShowConfigPanelAction(); | ||
| context = { | ||
| embeddable: { | ||
| viewMode$: viewModeSubject, | ||
| onShowConfig: jest.fn(), | ||
| isReadOnlyEnabled: jest.fn().mockReturnValue({ read: true, write: false }), | ||
| getTypeDisplayName: jest.fn().mockReturnValue('A very fun panel type'), | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| it('is compatible when api meets all conditions', async () => { | ||
| expect(await action.isCompatible(context)).toBe(true); | ||
| }); | ||
|
|
||
| it('is incompatible when context lacks necessary functions', async () => { | ||
| const emptyContext = { | ||
| embeddable: {}, | ||
| }; | ||
| expect(await action.isCompatible(emptyContext)).toBe(false); | ||
| }); | ||
|
|
||
| it('is incompatible when view mode is edit', async () => { | ||
| (context.embeddable as PublishesViewMode).viewMode$ = new BehaviorSubject<ViewMode>('edit'); | ||
| expect(await action.isCompatible(context)).toBe(false); | ||
| }); | ||
|
|
||
| it('is incompatible when view is not enabled', async () => { | ||
| context.embeddable.isReadOnlyEnabled = jest.fn().mockReturnValue({ read: false, write: false }); | ||
| expect(await action.isCompatible(context)).toBe(false); | ||
| }); | ||
|
|
||
| it('is incompatible when view mode is view but user has write permissions', async () => { | ||
| context.embeddable.isReadOnlyEnabled = jest.fn().mockReturnValue({ read: true, write: true }); | ||
| expect(await action.isCompatible(context)).toBe(false); | ||
| }); | ||
|
|
||
| it('should trigger a change ont he subject when changing viewMode', (done) => { | ||
| const subject$ = action.getCompatibilityChangesSubject(context); | ||
| subject$?.pipe(take(1)).subscribe(() => { | ||
| done(); | ||
| }); | ||
| updateViewMode('edit'); | ||
| }); | ||
| }); |
88 changes: 88 additions & 0 deletions
88
...sentation_panel/public/panel_actions/show_config_panel_action/show_config_panel_action.ts
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,88 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { | ||
| EmbeddableApiContext, | ||
| CanAccessViewMode, | ||
| apiCanAccessViewMode, | ||
| getInheritedViewMode, | ||
| getViewModeSubject, | ||
| HasReadOnlyCapabilities, | ||
| hasReadOnlyCapabilities, | ||
| } from '@kbn/presentation-publishing'; | ||
| import { | ||
| Action, | ||
| FrequentCompatibilityChangeAction, | ||
| IncompatibleActionError, | ||
| } from '@kbn/ui-actions-plugin/public'; | ||
| import { map } from 'rxjs'; | ||
| import { ACTION_SHOW_CONFIG_PANEL } from './constants'; | ||
|
|
||
| export type ShowConfigPanelActionApi = CanAccessViewMode & HasReadOnlyCapabilities; | ||
|
|
||
| const isApiCompatible = (api: unknown | null): api is ShowConfigPanelActionApi => { | ||
| return hasReadOnlyCapabilities(api) && apiCanAccessViewMode(api); | ||
| }; | ||
|
|
||
| export class ShowConfigPanelAction | ||
| implements Action<EmbeddableApiContext>, FrequentCompatibilityChangeAction<EmbeddableApiContext> | ||
| { | ||
| public readonly type = ACTION_SHOW_CONFIG_PANEL; | ||
| public readonly id = ACTION_SHOW_CONFIG_PANEL; | ||
| public order = 50; | ||
|
|
||
| constructor() {} | ||
|
|
||
| public getDisplayName({ embeddable }: EmbeddableApiContext) { | ||
| if (!isApiCompatible(embeddable)) throw new IncompatibleActionError(); | ||
|
nreese marked this conversation as resolved.
|
||
| return i18n.translate('presentationPanel.action.showConfigPanel.displayName', { | ||
| defaultMessage: 'Show {value} configuration', | ||
| values: { | ||
| value: embeddable.getTypeDisplayName(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| public getCompatibilityChangesSubject({ embeddable }: EmbeddableApiContext) { | ||
| return apiCanAccessViewMode(embeddable) | ||
| ? getViewModeSubject(embeddable)?.pipe(map(() => undefined)) | ||
| : undefined; | ||
| } | ||
|
|
||
| public couldBecomeCompatible({ embeddable }: EmbeddableApiContext) { | ||
| return isApiCompatible(embeddable); | ||
| } | ||
|
|
||
| public getIconType({ embeddable }: EmbeddableApiContext) { | ||
| if (!isApiCompatible(embeddable)) throw new IncompatibleActionError(); | ||
| return 'glasses'; | ||
| } | ||
|
|
||
| /** | ||
| * The compatible check is scoped to the read only capabilities | ||
| * Note: it does not take into account write permissions | ||
| */ | ||
| public async isCompatible({ embeddable }: EmbeddableApiContext) { | ||
| if (!isApiCompatible(embeddable) || getInheritedViewMode(embeddable) !== 'view') { | ||
| return false; | ||
| } | ||
| const { read: canRead, write: canWrite } = embeddable.isReadOnlyEnabled(); | ||
| return Boolean( | ||
| // No option to view or edit the configuration is offered for users with write permission. | ||
| canRead && !canWrite | ||
| ); | ||
| } | ||
|
|
||
| public async execute({ embeddable }: EmbeddableApiContext) { | ||
| if (!isApiCompatible(embeddable)) throw new IncompatibleActionError(); | ||
| await embeddable.onShowConfig(); | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
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.
Change this to align with the
show_config_actionone when user has edit capabilities. Ideally both actions should be merged into either a single action or with a better controller in a follow up