Skip to content

Commit

Permalink
[D&D] Refactor and cleanup embeddables (#1947)
Browse files Browse the repository at this point in the history
General plugin updates (#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 #1940
- add basic error embeddable rendering
- render via ExpressionLoader instead of wizard_component #1920
- wizard_component no longer used, but updated for future use
- add subscription handling for query, filter, timerange changes #1937
- fix clone/replace panel actions #1943, #1944
- fix title/description panel rendering #1921
- add inspection panel action #1936

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

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

Signed-off-by: Josh Romero <rmerqg@amazon.com>
  • Loading branch information
joshuarrrr authored Jul 26, 2022
1 parent c599eff commit 6be418e
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 6be418e

Please sign in to comment.