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

[D&D] Adds Bar line and Area charts to Wizard #2266

Merged
merged 10 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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 src/plugins/vis_type_vislib/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}

export { getConfigCollections } from './utils/collections';

export * from './types';
2 changes: 2 additions & 0 deletions src/plugins/vis_type_vislib/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ export interface BasicVislibParams extends CommonVislibParams {
times: TimeMarker[];
type: string;
}

export { Positions };
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export { Vis } from './vis';
export { TypesService } from './vis_types/types_service';
export { VISUALIZE_EMBEDDABLE_TYPE, VIS_EVENT_TO_TRIGGER } from './embeddable';
export { VisualizationContainer, VisualizationNoResults } from './components';
export { getSchemas as getVisSchemas } from './legacy/build_pipeline';
export { getSchemas as getVisSchemas, buildVislibDimensions } from './legacy/build_pipeline';

/** @public types */
export { VisualizationsSetup, VisualizationsStart };
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/wizard/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"dashboard",
"visualizations",
"opensearchUiShared",
"visDefaultEditor"
"visDefaultEditor",
"visTypeVislib"
],
"optionalPlugins": []
}
3 changes: 2 additions & 1 deletion src/plugins/wizard/public/application/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
@import "@elastic/eui/src/global_styling/variables/form";

$osdHeaderOffset: $euiHeaderHeightCompensation;
$wizSideNavWidth: 470px;
$wizLeftNavWidth: 462px;
$wizRightNavWidth: 320px;
ashwin-pc marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 11 additions & 2 deletions src/plugins/wizard/public/application/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
padding: 0;
display: grid;
grid-template:
"topNav topNav topNav" min-content
"leftNav workspace rightNav" 1fr / #{$wizSideNavWidth} 1fr #{$wizSideNavWidth};
"topNav topNav" min-content
"leftNav workspaceNav" 1fr / #{$wizLeftNavWidth} 1fr;
height: calc(100vh - #{$osdHeaderOffset});

&__resizeContainer {
min-height: 0;
background-color: $euiColorEmptyShade;
}

&__resizeButton {
transform: translateX(-$euiSizeM / 2);
}
}

.headerIsExpanded .wizLayout {
Expand Down
35 changes: 32 additions & 3 deletions src/plugins/wizard/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React from 'react';
import { I18nProvider } from '@osd/i18n/react';
import { EuiPage } from '@elastic/eui';
import { EuiPage, EuiResizableContainer } from '@elastic/eui';
import { DragDropProvider } from './utils/drag_drop/drag_drop_context';
import { LeftNav } from './components/left_nav';
import { TopNav } from './components/top_nav';
Expand All @@ -21,8 +21,37 @@ export const WizardApp = () => {
<EuiPage className="wizLayout">
<TopNav />
<LeftNav />
<Workspace />
<RightNav />
<EuiResizableContainer className="wizLayout__resizeContainer">
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel
className="wizLayout__workspaceResize"
paddingSize="none"
initialSize={80}
minSize="300px"
mode="main"
>
<Workspace />
</EuiResizablePanel>
<EuiResizableButton className="wizLayout__resizeButton" />
<EuiResizablePanel
className="wizLayout__rightNavResize"
paddingSize="none"
initialSize={20}
minSize="250px"
mode={[
'collapsible',
{
position: 'top',
},
]}
id="wizRightResize"
>
<RightNav />
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
</EuiPage>
</DragDropProvider>
</I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
overflow-y: auto;
margin-right: -$euiSizeS;
padding-right: $euiSizeS;
margin-left: -$euiSizeS;
padding-left: $euiSizeS;
margin-top: $euiSizeS;
}

Expand Down
55 changes: 47 additions & 8 deletions src/plugins/wizard/public/application/components/right_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiSuperSelect, EuiSuperSelectOption, EuiIcon, IconType } from '@elastic/eui';
import React, { useState } from 'react';
import {
EuiSuperSelect,
EuiSuperSelectOption,
EuiIcon,
IconType,
EuiConfirmModal,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import { useVisualizationType } from '../utils/use';
import './side_nav.scss';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { WizardServices } from '../../types';
import { setActiveVisualization, useTypedDispatch } from '../utils/state_management';

export const RightNav = () => {
const [newVisType, setNewVisType] = useState<string>();
const {
services: { types },
} = useOpenSearchDashboards<WizardServices>();
Expand All @@ -23,6 +32,7 @@ export const RightNav = () => {
value: name,
inputDisplay: <OptionItem icon={icon} title={title} />,
dropdownDisplay: <OptionItem icon={icon} title={title} />,
'data-test-subj': `visType-${name}`,
}));

return (
Expand All @@ -32,19 +42,48 @@ export const RightNav = () => {
options={options}
valueOfSelected={activeVisName}
onChange={(name) => {
dispatch(
setActiveVisualization({
name,
style: types.get(name)?.ui.containerConfig.style.defaults,
})
);
setNewVisType(name);
}}
fullWidth
data-test-subj="chartPicker"
/>
</div>
<div className="wizSidenav__style">
<StyleSection />
</div>
{newVisType && (
<EuiConfirmModal
title={i18n.translate('wizard.rightNav.changeVisType.modalTitle', {
defaultMessage: 'Change Visualization type',
})}
confirmButtonText={i18n.translate('wizard.rightNav.changeVisType.confirmText', {
defaultMessage: 'Ok',
})}
cancelButtonText={i18n.translate('wizard.rightNav.changeVisType.cancelText', {
defaultMessage: 'Cancel',
})}
onCancel={() => setNewVisType(undefined)}
onConfirm={() => {
dispatch(
setActiveVisualization({
name: newVisType,
style: types.get(newVisType)?.ui.containerConfig.style.defaults,
})
);

setNewVisType(undefined);
}}
maxWidth="300px"
joshuarrrr marked this conversation as resolved.
Show resolved Hide resolved
data-test-subj="confirmVisChangeModal"
>
<p>
<FormattedMessage
id="wizard.rightNav.changeVisType.modalDescription"
defaultMessage="Currently, changing the visualization type clears the existing selection of fields. Are you sure you want to change the visualization type?"
ashwin-pc marked this conversation as resolved.
Show resolved Hide resolved
/>
</p>
</EuiConfirmModal>
)}
</section>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

&--fixedWidthChild {
width: calc(#{$wizSideNavWidth} - #{$euiSizeXL} * 2);
width: calc(#{$wizLeftNavWidth} - #{$euiSizeXL} * 2);
}

&--selectableWrapper .euiSelectableList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
&.right {
border-left: $euiBorderThin;
grid-area: rightNav;
height: 100%;
}

&__header {
Expand Down Expand Up @@ -46,5 +47,5 @@
}

.wizDatasourceSelect {
max-width: calc(#{$wizSideNavWidth} - 1px);
max-width: calc(#{$wizLeftNavWidth} - 1px);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
grid-gap: $euiSizeM;
padding: $euiSizeM;
background-color: $euiColorEmptyShade;
height: 100%;

&__empty {
height: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { WizardServices } from '../../types';
import { validateSchemaState } from '../utils/validate_schema_state';
import { useTypedSelector } from '../utils/state_management';
import { useVisualizationType } from '../utils/use';
import { PersistedState } from '../../../../visualizations/public';

import hand_field from '../../assets/hand_field.svg';
import fields_bg from '../../assets/fields_bg.svg';
Expand All @@ -34,6 +35,8 @@ export const Workspace: FC = ({ children }) => {
timeRange: data.query.timefilter.timefilter.getTime(),
});
const rootState = useTypedSelector((state) => state);
// Visualizations require the uiState to persist even when the expression changes
const uiState = useMemo(() => new PersistedState(), []);

useEffect(() => {
async function loadExpression() {
Expand Down Expand Up @@ -77,7 +80,11 @@ export const Workspace: FC = ({ children }) => {
</EuiFlexGroup>
<EuiPanel className="wizCanvas" data-test-subj="visualizationLoader">
{expression ? (
<ReactExpressionRenderer expression={expression} searchContext={searchContext} />
<ReactExpressionRenderer
expression={expression}
searchContext={searchContext}
uiState={uiState}
/>
) : (
<EuiFlexItem className="wizWorkspace__empty" data-test-subj="emptyWorkspace">
<EuiEmptyPrompt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { cloneDeep } from 'lodash';
import { OpenSearchaggsExpressionFunctionDefinition } from '../../../../data/public';
import { ExpressionFunctionOpenSearchDashboards } from '../../../../expressions';
import { buildExpressionFunction } from '../../../../expressions/public';
import { VisualizationState } from '../../application/utils/state_management';
import { getAggService, getIndexPatterns } from '../../plugin_services';

export const getAggExpressionFunctions = async (visualization: VisualizationState) => {
const { activeVisualization, indexPattern: indexId = '' } = visualization;
const { aggConfigParams } = activeVisualization || {};

const indexPatternsService = getIndexPatterns();
const indexPattern = await indexPatternsService.get(indexId);
const aggConfigs = getAggService().createAggConfigs(indexPattern, cloneDeep(aggConfigParams));
ashwin-pc marked this conversation as resolved.
Show resolved Hide resolved

const opensearchDashboards = buildExpressionFunction<ExpressionFunctionOpenSearchDashboards>(
'opensearchDashboards',
{}
);

// soon this becomes: const opensearchaggs = vis.data.aggs!.toExpressionAst();
const opensearchaggs = buildExpressionFunction<OpenSearchaggsExpressionFunctionDefinition>(
'opensearchaggs',
{
index: indexId,
metricsAtAllLevels: false,
partialRows: false,
joshuarrrr marked this conversation as resolved.
Show resolved Hide resolved
aggConfigs: JSON.stringify(aggConfigs.aggs),
includeFormatHints: false,
}
);

return {
aggConfigs,
expressionFns: [opensearchDashboards, opensearchaggs],
};
};
8 changes: 7 additions & 1 deletion src/plugins/wizard/public/visualizations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

import type { TypeServiceSetup } from '../services/type_service';
import { createMetricConfig } from './metric';
import { createHistogramConfig, createLineConfig, createAreaConfig } from './vislib';

export function registerDefaultTypes(typeServiceSetup: TypeServiceSetup) {
const visualizationTypes = [createMetricConfig];
const visualizationTypes = [
createHistogramConfig,
createLineConfig,
createAreaConfig,
createMetricConfig,
];

visualizationTypes.forEach((createTypeConfig) => {
typeServiceSetup.createVisualizationType(createTypeConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { cloneDeep } from 'lodash';
Copy link
Collaborator

@AMoo-Miki AMoo-Miki Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

import { SchemaConfig } from '../../../../visualizations/public';
import { MetricVisExpressionFunctionDefinition } from '../../../../vis_type_metric/public';
import {
AggConfigs,
IAggConfig,
OpenSearchaggsExpressionFunctionDefinition,
} from '../../../../data/common';
import { AggConfigs, IAggConfig } from '../../../../data/common';
import { buildExpression, buildExpressionFunction } from '../../../../expressions/public';
import { RootState } from '../../application/utils/state_management';
import { MetricOptionsDefaults } from './metric_viz_type';
import { getAggService, getIndexPatterns } from '../../plugin_services';
import { getAggExpressionFunctions } from '../common/expression_helpers';

const prepareDimension = (params: SchemaConfig) => {
const visdimension = buildExpressionFunction('visdimension', { accessor: params.accessor });
Expand Down Expand Up @@ -92,24 +87,7 @@ export interface MetricRootState extends RootState {
}

export const toExpression = async ({ style: styleState, visualization }: MetricRootState) => {
const { activeVisualization, indexPattern: indexId = '' } = visualization;
const { aggConfigParams } = activeVisualization || {};

const indexPatternsService = getIndexPatterns();
const indexPattern = await indexPatternsService.get(indexId);
const aggConfigs = getAggService().createAggConfigs(indexPattern, cloneDeep(aggConfigParams));

// soon this becomes: const opensearchaggs = vis.data.aggs!.toExpressionAst();
const opensearchaggs = buildExpressionFunction<OpenSearchaggsExpressionFunctionDefinition>(
'opensearchaggs',
{
index: indexId,
metricsAtAllLevels: false,
partialRows: false,
aggConfigs: JSON.stringify(aggConfigs.aggs),
includeFormatHints: false,
}
);
const { aggConfigs, expressionFns } = await getAggExpressionFunctions(visualization);

// TODO: Update to use the getVisSchemas function from the Visualizations plugin
// const schemas = getVisSchemas(vis, params);
Expand Down Expand Up @@ -169,7 +147,5 @@ export const toExpression = async ({ style: styleState, visualization }: MetricR
metricVis.addArgument('metric', prepareDimension(metric));
});

const ast = buildExpression([opensearchaggs, metricVis]);

return `opensearchDashboards | opensearch_dashboards_context | ${ast.toString()}`;
return buildExpression([...expressionFns, metricVis]).toString();
};
Loading