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

fix(ExpressionEditor): Fix stale data in Expression Editor #536

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FunctionComponent, Ref, useCallback, useContext, useMemo, useState } from 'react';
import {
Card,
CardBody,
Expand All @@ -11,8 +10,9 @@ import {
MenuToggle,
MenuToggleElement,
} from '@patternfly/react-core';
import { MetadataEditor } from '../../MetadataEditor';
import { FunctionComponent, Ref, useCallback, useContext, useMemo, useState } from 'react';
import { EntitiesContext } from '../../../providers';
import { MetadataEditor } from '../../MetadataEditor';
import { CanvasNode } from './canvas.models';
import { DataFormatService } from './dataformat.service';

Expand All @@ -35,10 +35,9 @@ export const DataFormatEditor: FunctionComponent<DataFormatEditorProps> = (props
visualComponentSchema.definition = {};
}
}
const model = visualComponentSchema?.definition;
const { dataFormat: dataFormat, model: dataFormatModel } = DataFormatService.parseDataFormatModel(
const { dataFormat, model: dataFormatModel } = DataFormatService.parseDataFormatModel(
dataFormatCatalogMap,
model,
visualComponentSchema?.definition,
);
const dataFormatSchema = useMemo(() => {
return DataFormatService.getDataFormatSchema(dataFormat!);
Expand All @@ -50,12 +49,13 @@ export const DataFormatEditor: FunctionComponent<DataFormatEditorProps> = (props

const handleOnChange = useCallback(
(selectedDataFormat: string, newDataFormatModel: Record<string, unknown>) => {
const model = props.selectedNode.data?.vizNode?.getComponentSchema()?.definition;
if (!model) return;
DataFormatService.setDataFormatModel(dataFormatCatalogMap, model, selectedDataFormat, newDataFormatModel);
props.selectedNode.data?.vizNode?.updateModel(model);
entitiesContext?.updateSourceCodeFromEntities();
},
[entitiesContext, dataFormatCatalogMap, model, props.selectedNode.data?.vizNode],
[entitiesContext, dataFormatCatalogMap, props.selectedNode.data?.vizNode],
);

const onSelect = useCallback(
Expand All @@ -78,7 +78,6 @@ export const DataFormatEditor: FunctionComponent<DataFormatEditorProps> = (props

return (
dataFormatCatalogMap &&
model &&
dataFormat && (
<Card isCompact={true} isExpanded={isExpanded}>
<CardHeader onExpand={() => setIsExpanded(!isExpanded)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FunctionComponent, Ref, useCallback, useContext, useMemo, useState } from 'react';
import {
Card,
CardBody,
Expand All @@ -11,8 +10,9 @@ import {
MenuToggle,
MenuToggleElement,
} from '@patternfly/react-core';
import { MetadataEditor } from '../../MetadataEditor';
import { FunctionComponent, Ref, useCallback, useContext, useMemo, useState } from 'react';
import { EntitiesContext } from '../../../providers';
import { MetadataEditor } from '../../MetadataEditor';
import { CanvasNode } from './canvas.models';
import { ExpressionService } from './expression.service';

Expand All @@ -34,8 +34,10 @@ export const ExpressionEditor: FunctionComponent<ExpressionEditorProps> = (props
visualComponentSchema.definition = {};
}
}
const model = visualComponentSchema?.definition;
const { language, model: expressionModel } = ExpressionService.parseExpressionModel(languageCatalogMap, model);
const { language, model: expressionModel } = ExpressionService.parseExpressionModel(
languageCatalogMap,
visualComponentSchema?.definition,
);
const languageSchema = useMemo(() => {
return ExpressionService.getLanguageSchema(language!);
}, [language]);
Expand All @@ -46,12 +48,13 @@ export const ExpressionEditor: FunctionComponent<ExpressionEditorProps> = (props

const handleOnChange = useCallback(
(selectedLanguage: string, newExpressionModel: Record<string, unknown>) => {
const model = props.selectedNode.data?.vizNode?.getComponentSchema()?.definition;
if (!model) return;
ExpressionService.setExpressionModel(languageCatalogMap, model, selectedLanguage, newExpressionModel);
props.selectedNode.data?.vizNode?.updateModel(model);
entitiesContext?.updateSourceCodeFromEntities();
},
[entitiesContext, languageCatalogMap, model, props.selectedNode.data?.vizNode],
[entitiesContext, languageCatalogMap, props.selectedNode.data?.vizNode],
);

const onSelect = useCallback(
Expand All @@ -74,7 +77,6 @@ export const ExpressionEditor: FunctionComponent<ExpressionEditorProps> = (props

return (
languageCatalogMap &&
model &&
language && (
<Card isCompact={true} isExpanded={isExpanded}>
<CardHeader onExpand={() => setIsExpanded(!isExpanded)}>
Expand Down
Loading