Skip to content

Commit

Permalink
[D&D] Refactor and cleanup embeddables (opensearch-project#1947)
Browse files Browse the repository at this point in the history
General plugin updates (opensearch-project#1939):
- add start service getters/setters to plugin service
- move setters from setup to start so they're available to embeddable

Embeddable updates:
- use getters instead of depending on start services in constructor
- remove wizard from add panel "create" list
- add correct edit paths/URLs for linking to wizard opensearch-project#1940
- add basic error embeddable rendering
- render via ExpressionLoader instead of wizard_component opensearch-project#1920
- wizard_component no longer used, but updated for future use
- add subscription handling for query, filter, timerange changes opensearch-project#1937
- fix clone/replace panel actions opensearch-project#1943, opensearch-project#1944
- fix title/description panel rendering opensearch-project#1921
- add inspection panel action opensearch-project#1936

Asset updates:
- Update empty workspace illustration
- Add secondary fill icon version to match new visualization icons

fixes opensearch-project#1936, opensearch-project#1920, opensearch-project#1937, opensearch-project#1940, opensearch-project#1921, opensearch-project#1939, opensearch-project#1941, opensearch-project#1943, opensearch-project#1944

Signed-off-by: Josh Romero <rmerqg@amazon.com>
  • Loading branch information
joshuarrrr authored and ashwin-pc committed Aug 3, 2022
1 parent 0c0df21 commit ab0463c
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 262 deletions.
91 changes: 58 additions & 33 deletions src/plugins/wizard/public/assets/fields_bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions src/plugins/wizard/public/assets/hand_field.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/plugins/wizard/public/assets/wizard_icon_secondary_fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 16 additions & 50 deletions src/plugins/wizard/public/embeddable/wizard_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,32 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from 'react';
import React from 'react';

import { SavedObjectEmbeddableInput, withEmbeddableSubscription } from '../../../embeddable/public';
import { WizardEmbeddable, WizardOutput } from './wizard_embeddable';
import { validateSchemaState } from '../application/utils/validate_schema_state';
import { getReactExpressionRenderer } from '../plugin_services';

interface Props {
embeddable: WizardEmbeddable;
input: SavedObjectEmbeddableInput;
output: WizardOutput;
}

function WizardEmbeddableComponentInner({
embeddable,
input: {},
output: { savedAttributes },
}: Props) {
const { ReactExpressionRenderer, toasts, types, indexPatterns, aggs } = embeddable;
const [expression, setExpression] = useState<string>();

useEffect(() => {
const { visualizationState: visualization, styleState: style } = savedAttributes || {};
if (savedAttributes === undefined || visualization === undefined || style === undefined) {
return;
}

const rootState = {
visualization: JSON.parse(visualization),
style: JSON.parse(style),
};

const visualizationType = types.get(rootState.visualization?.activeVisualization?.name ?? '');
if (!visualizationType) {
throw new Error(`Invalid visualization type ${visualizationType}`);
}
const { toExpression, ui } = visualizationType;

async function loadExpression() {
const schemas = ui.containerConfig.data.schemas;
const [valid, errorMsg] = validateSchemaState(schemas, rootState);

if (!valid) {
if (errorMsg) {
toasts.addWarning(errorMsg);
}
setExpression(undefined);
return;
}
const exp = await toExpression(rootState, indexPatterns, aggs);
setExpression(exp);
}

if (savedAttributes !== undefined) {
loadExpression();
}
}, [aggs, indexPatterns, savedAttributes, toasts, types]);

return <ReactExpressionRenderer expression={expression ?? ''} />;

// TODO: add correct loading and error states
function WizardEmbeddableComponentInner({ embeddable, input: {}, output: { error } }: Props) {
const { expression } = embeddable;
const ReactExpressionRenderer = getReactExpressionRenderer();

return (
<>
{error?.message ? (
// TODO: add correct loading and error states
<div>{error.message}</div>
) : (
<ReactExpressionRenderer expression={expression ?? ''} />
)}
</>
);
}

export const WizardEmbeddableComponent = withEmbeddableSubscription<
Expand Down
Loading

0 comments on commit ab0463c

Please sign in to comment.