-
Notifications
You must be signed in to change notification settings - Fork 890
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] allow to update section input after page rendered #7651
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [contentManagement] allow to update section input after page rendered ([#7651](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7651)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DashboardContainerInput } from '../../../dashboard/public'; | ||
|
||
export type DashboardContainerExplicitInput = Partial< | ||
Pick<DashboardContainerInput, 'filters' | 'timeRange' | 'query'> | ||
>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,15 @@ | |
this.config = pageConfig; | ||
} | ||
|
||
createSection(section: Section) { | ||
private setSection(section: Section) { | ||
this.sections.set(section.id, section); | ||
this.sections$.next(this.getSections()); | ||
} | ||
|
||
createSection(section: Section) { | ||
this.setSection(section); | ||
} | ||
|
||
getSections() { | ||
return [...this.sections.values()].sort((a, b) => a.order - b.order); | ||
} | ||
|
@@ -31,6 +35,28 @@ | |
return this.sections$; | ||
} | ||
|
||
updateSectionInput( | ||
sectionId: string, | ||
callback: (section: Section | null, err?: Error) => Section | null | ||
) { | ||
const section = this.sections.get(sectionId); | ||
if (!section) { | ||
callback(null, new Error(`Section id ${sectionId} not found`)); | ||
return; | ||
} | ||
|
||
const updated = callback(section); | ||
if (updated) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you feel about doing
... and then a switch-case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! I will adopt this change in the upcoming PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (updated.kind === 'dashboard' && section.kind === 'dashboard') { | ||
this.setSection({ ...section, input: updated.input }); | ||
} | ||
if (updated.kind === 'card' && section.kind === 'card') { | ||
this.setSection({ ...section, input: updated.input }); | ||
} | ||
// TODO: we may need to support update input of `custom` section | ||
} | ||
} | ||
|
||
addContent(sectionId: string, content: Content) { | ||
const sectionContents = this.contents.get(sectionId); | ||
if (sectionContents) { | ||
|
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.
What's the difference between the language here? I guess it will be overwritten by
...section.input
?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.
Yes, it can be override by
section.input
. Here it just changed the default language fromlucene
tokuery(DQL)
.