-
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
[D&D] Fix: Topnav updates aggregation parameters #1905
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 |
---|---|---|
|
@@ -14,8 +14,9 @@ import { | |
EuiPanel, | ||
EuiPopover, | ||
} from '@elastic/eui'; | ||
import React, { FC, useState, useMemo, useEffect, Fragment } from 'react'; | ||
import React, { FC, useState, useMemo, useEffect, useLayoutEffect } from 'react'; | ||
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; | ||
import { IExpressionLoaderParams } from '../../../../expressions/public'; | ||
import { WizardServices } from '../../types'; | ||
import { validateSchemaState } from '../utils/validate_schema_state'; | ||
import { useTypedDispatch, useTypedSelector } from '../utils/state_management'; | ||
|
@@ -32,10 +33,16 @@ export const Workspace: FC = ({ children }) => { | |
services: { | ||
expressions: { ReactExpressionRenderer }, | ||
notifications: { toasts }, | ||
data, | ||
}, | ||
} = useOpenSearchDashboards<WizardServices>(); | ||
const { toExpression, ui } = useVisualizationType(); | ||
const [expression, setExpression] = useState<string>(); | ||
const [searchContext, setSearchContext] = useState<IExpressionLoaderParams['searchContext']>({ | ||
query: data.query.queryString.getQuery(), | ||
filters: data.query.filterManager.getFilters(), | ||
timeRange: data.query.timefilter.timefilter.getTime(), | ||
}); | ||
const rootState = useTypedSelector((state) => state); | ||
|
||
useEffect(() => { | ||
|
@@ -57,6 +64,20 @@ export const Workspace: FC = ({ children }) => { | |
loadExpression(); | ||
}, [rootState, toExpression, toasts, ui.containerConfig.data.schemas]); | ||
|
||
useLayoutEffect(() => { | ||
const subscription = data.query.state$.subscribe(({ state }) => { | ||
setSearchContext({ | ||
query: state.query, | ||
timeRange: state.time, | ||
filters: state.filters, | ||
}); | ||
}); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, [data.query.state$]); | ||
|
||
return ( | ||
<section className="wizWorkspace"> | ||
<EuiFlexGroup className="wizCanvasControls"> | ||
|
@@ -66,13 +87,13 @@ export const Workspace: FC = ({ children }) => { | |
</EuiFlexGroup> | ||
<EuiPanel className="wizCanvas"> | ||
{expression ? ( | ||
<ReactExpressionRenderer expression={expression} /> | ||
<ReactExpressionRenderer expression={expression} searchContext={searchContext} /> | ||
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.
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. Yeah, for now either the |
||
) : ( | ||
<EuiFlexItem className="wizWorkspace__empty"> | ||
<EuiEmptyPrompt | ||
title={<h2>Drop some fields here to start</h2>} | ||
body={ | ||
<Fragment> | ||
<> | ||
<p>Drag a field directly to the canvas or axis to generate a visualization.</p> | ||
<span className="wizWorkspace__container"> | ||
<EuiIcon className="wizWorkspace__fieldSvg" type={fields_bg} size="original" /> | ||
|
@@ -82,7 +103,7 @@ export const Workspace: FC = ({ children }) => { | |
size="original" | ||
/> | ||
</span> | ||
</Fragment> | ||
</> | ||
} | ||
/> | ||
</EuiFlexItem> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,5 +171,5 @@ export const toExpression = async ({ style: styleState, visualization }: MetricR | |
|
||
const ast = buildExpression([opensearchaggs, metricVis]); | ||
|
||
return ast.toString(); | ||
return `opensearchDashboards | opensearch_dashboards_context | ${ast.toString()}`; | ||
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. I assume this change is intended, and maybe it's obvious for someone who understands expressions, but an explanatory comment would seem useful. 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. The I want to abstract away most of this logic into utility functions so that all we have here is some sort of builder function that simply chains the expression function builders. |
||
}; |
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.
Do we still need a defined screen title or does it default to the app name or something?
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.
it's an optional parameter that can be the title of the visualization but it can be ignored. When ignored the title is OpenSearch Dashboards. We can add it in future when we have the saved object stuff all polished up.