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

feat(contentManagement): expose page API to allow remove section #8624

Merged
merged 2 commits into from
Oct 17, 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/8624.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- (contentManagement) Add a Page API to allow remove section ([#8624](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8624))
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,24 @@
return (
<>
{section.title ? (
<EuiTitle size="s">
<h2>
{isCardCollapsible ? (
<EuiButtonIcon
iconType={isCardVisible ? 'arrowDown' : 'arrowRight'}
onClick={() => setIsCardVisible(!isCardVisible)}
color="text"
aria-label={isCardVisible ? 'Show panel' : 'Hide panel'}
/>
) : null}
{section.title}
</h2>
</EuiTitle>
) : null}
{isCardVisible && (
<>
<EuiSpacer size="m" /> <EmbeddableRenderer factory={factory} input={input} />
<EuiTitle size="s">
<h2>
{isCardCollapsible ? (
<EuiButtonIcon
iconType={isCardVisible ? 'arrowDown' : 'arrowRight'}
onClick={() => setIsCardVisible(!isCardVisible)}

Check warning on line 75 in src/plugins/content_management/public/components/section_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/content_management/public/components/section_render.tsx#L75

Added line #L75 was not covered by tests
color="text"
aria-label={isCardVisible ? 'Show panel' : 'Hide panel'}
/>
) : null}
{section.title}
</h2>
</EuiTitle>
<EuiSpacer size="m" />
</>
)}
) : null}
{isCardVisible && <EmbeddableRenderer factory={factory} input={input} />}
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/content_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
return {
registerContentProvider: this.contentManagementService.registerContentProvider,
updatePageSection: this.contentManagementService.updatePageSection,
getPage: (id: string) => this.contentManagementService.getPage(id),

Check warning on line 69 in src/plugins/content_management/public/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/content_management/public/plugin.ts#L69

Added line #L69 was not covered by tests
renderPage: (id: string, renderOptions?: RenderOptions) => {
const page = this.contentManagementService.getPage(id);
if (page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,16 @@ test('it should callback with error if section not exist', () => {
expect(callbackMock.mock.calls[0][0]).toBe(null);
expect(callbackMock.mock.calls[0][1]).toBeInstanceOf(Error);
});

test('it should remove the specified section', () => {
const page = new Page({ id: 'page1' });
page.createSection({
id: 'section_id',
kind: 'dashboard',
order: 1000,
input: { timeRange: { from: 'now-7d', to: 'now' } },
});
expect(page.getSections()).toHaveLength(1);
page.removeSection('section_id');
expect(page.getSections()).toHaveLength(0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export class Page {
this.setSection(section);
}

removeSection(id: string) {
this.sections.delete(id);
this.sections$.next(this.getSections());
}

getSections() {
return [...this.sections.values()].sort((a, b) => a.order - b.order);
}
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/content_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { CoreStart } from 'opensearch-dashboards/public';

import { ContentManagementService, ContentProvider, Section } from './services';
import { ContentManagementService, ContentProvider, Page, Section } from './services';
import { EmbeddableSetup, EmbeddableStart } from '../../embeddable/public';

export interface ContentManagementPluginSetup {
Expand Down Expand Up @@ -36,6 +36,10 @@ export interface ContentManagementPluginStart {
targetArea: string,
callback: (section: Section | null, err?: Error) => Section | null
) => void;
/**
* @experimental this API is experimental and might change in future releases
*/
getPage: (id: string) => Page | undefined;
renderPage: (id: string, options?: RenderOptions) => React.ReactNode;
}

Expand Down
Loading