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

[Backport 2.x] feat: provide new embeddable option to hide embeddable panel action button #7676

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/7503.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Provide new embeddable option to hide embeddable panel action button ([#7503](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7503))
1 change: 1 addition & 0 deletions src/plugins/embeddable/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type EmbeddableInput = {
id: string;
lastReloadRequestTime?: number;
hidePanelTitles?: boolean;
hidePanelActions?: boolean;

/**
* Reserved key for enhancements added by other plugins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,59 @@ test('Updates when hidePanelTitles is toggled', async () => {
expect(title.length).toBe(1);
});

test('Updates when hidePanelActions is toggled', async () => {
const inspector = inspectorPluginMock.createStartContract();

const container = new HelloWorldContainer(
{ id: '123', panels: {}, viewMode: ViewMode.VIEW, hidePanelActions: false },
{ getEmbeddableFactory } as any
);

const embeddable = await container.addNewEmbeddable<
ContactCardEmbeddableInput,
ContactCardEmbeddableOutput,
ContactCardEmbeddable
>(CONTACT_CARD_EMBEDDABLE, {
firstName: 'Rob',
lastName: 'Stark',
});

const component = mount(
<I18nProvider>
<EmbeddablePanel
embeddable={embeddable}
getActions={() => Promise.resolve([])}
getAllEmbeddableFactories={start.getEmbeddableFactories}
getEmbeddableFactory={start.getEmbeddableFactory}
notifications={{} as any}
overlays={{} as any}
application={applicationMock}
inspector={inspector}
SavedObjectFinder={() => null}
/>
</I18nProvider>
);

let actionButton = findTestSubject(component, 'embeddablePanelToggleMenuIcon');
expect(actionButton.length).toBe(1);

container.updateInput({ hidePanelActions: true });

await nextTick();
component.update();

actionButton = findTestSubject(component, 'embeddablePanelToggleMenuIcon');
expect(actionButton.length).toBe(0);

container.updateInput({ hidePanelActions: false });

await nextTick();
component.update();

actionButton = findTestSubject(component, 'embeddablePanelToggleMenuIcon');
expect(actionButton.length).toBe(1);
});

test('Check when hide header option is false', async () => {
const inspector = inspectorPluginMock.createStartContract();

Expand Down
23 changes: 17 additions & 6 deletions src/plugins/embeddable/public/lib/panel/embeddable_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ interface State {
focusedPanelIndex?: string;
viewMode: ViewMode;
hidePanelTitle: boolean;
hidePanelAction: boolean;
closeContextMenu: boolean;
badges: Array<Action<EmbeddableContext>>;
notifications: Array<Action<EmbeddableContext>>;
Expand All @@ -112,15 +113,19 @@ export class EmbeddablePanel extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
const { embeddable } = this.props;
const viewMode = embeddable.getInput().viewMode ?? ViewMode.EDIT;
const hidePanelTitle =
Boolean(embeddable.parent?.getInput()?.hidePanelTitles) ||
Boolean(embeddable.getInput()?.hidePanelTitles);
const input = embeddable.getInput();
const parentInput = embeddable.parent?.getInput();

const viewMode = input?.viewMode ?? ViewMode.EDIT;
const hidePanelTitle = Boolean(parentInput?.hidePanelTitles) || Boolean(input?.hidePanelTitles);
const hidePanelAction =
Boolean(parentInput?.hidePanelActions) || Boolean(input?.hidePanelActions);

this.state = {
panels: [],
viewMode,
hidePanelTitle,
hidePanelAction,
closeContextMenu: false,
badges: [],
notifications: [],
Expand Down Expand Up @@ -182,10 +187,15 @@ export class EmbeddablePanel extends React.Component<Props, State> {
if (parent) {
this.parentSubscription = parent.getInput$().subscribe(async () => {
if (this.mounted && parent) {
const input = embeddable.getInput();
const parentInput = parent.getInput();
this.setState({
hidePanelTitle:
Boolean(embeddable.parent?.getInput()?.hidePanelTitles) ||
Boolean(embeddable.getInput()?.hidePanelTitles),
Boolean(parentInput?.hidePanelTitles) || Boolean(input?.hidePanelTitles),
});
this.setState({
hidePanelAction:
Boolean(parentInput?.hidePanelActions) || Boolean(input?.hidePanelActions),
});

this.refreshBadges();
Expand Down Expand Up @@ -245,6 +255,7 @@ export class EmbeddablePanel extends React.Component<Props, State> {
<PanelHeader
getActionContextMenuPanel={this.getActionContextMenuPanel}
hidePanelTitle={this.state.hidePanelTitle}
hidePanelAction={this.state.hidePanelAction}
isViewMode={viewOnlyMode}
closeContextMenu={this.state.closeContextMenu}
title={title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface PanelHeaderProps {
title?: string;
isViewMode: boolean;
hidePanelTitle: boolean;
hidePanelAction: boolean;
getActionContextMenuPanel: () => Promise<EuiContextMenuPanelDescriptor[]>;
closeContextMenu: boolean;
badges: Array<Action<EmbeddableContext>>;
Expand Down Expand Up @@ -129,6 +130,7 @@ export function PanelHeader({
title,
isViewMode,
hidePanelTitle,
hidePanelAction,
getActionContextMenuPanel,
closeContextMenu,
badges,
Expand Down Expand Up @@ -166,12 +168,14 @@ export function PanelHeader({
if (!showPanelBar) {
return (
<div className={classes}>
<PanelOptionsMenu
getActionContextMenuPanel={getActionContextMenuPanel}
isViewMode={isViewMode}
closeContextMenu={closeContextMenu}
title={title}
/>
{!hidePanelAction && (
<PanelOptionsMenu
getActionContextMenuPanel={getActionContextMenuPanel}
isViewMode={isViewMode}
closeContextMenu={closeContextMenu}
title={title}
/>
)}
<EuiScreenReaderOnly>{getAriaLabel()}</EuiScreenReaderOnly>
</div>
);
Expand Down Expand Up @@ -210,12 +214,14 @@ export function PanelHeader({
{renderBadges(badges, embeddable)}
</h2>
{renderNotifications(notifications, embeddable)}
<PanelOptionsMenu
isViewMode={isViewMode}
getActionContextMenuPanel={getActionContextMenuPanel}
closeContextMenu={closeContextMenu}
title={title}
/>
{!hidePanelAction && (
<PanelOptionsMenu
isViewMode={isViewMode}
getActionContextMenuPanel={getActionContextMenuPanel}
closeContextMenu={closeContextMenu}
title={title}
/>
)}
</figcaption>
);
}
Loading