Skip to content
Snippets Groups Projects

feat: add insert variables dropdown for visualizations

Merged Dennis Collaris requested to merge feat/lexical-insert-variables-0dvis into main
Files
2
@@ -10,18 +10,22 @@ import {
$parseSerializedNode
} from "lexical";
import { Input } from '@graphpolaris/shared/lib/components/inputs';
import { VariableNode } from '../VariableNode';
import { VariableNode, VariableType } from '../VariableNode';
import { useState } from 'react';
import { useGraphQueryResult } from '@graphpolaris/shared/lib/data-access';
import { useGraphQueryResult, useVisualization } from '@graphpolaris/shared/lib/data-access';
export const InsertVariablesPlugin = () => {
const [editor] = useLexicalComposerContext();
const { openVisualizationArray } = useVisualization();
const onChange = (value: string | number) => {
const visualizationOptions = openVisualizationArray
.map(x => x.name);
const onChange = (value: string | number, type: VariableType) => {
editor.update(() => {
const selection = $getSelection() as BaseSelection;
const node = new VariableNode(String(value));
const node = new VariableNode(String(value), type);
selection.insertNodes([node]);
@@ -43,13 +47,24 @@ export const InsertVariablesPlugin = () => {
return Object.entries(typeObj.attributes).map(([k,v]) => Object.keys(v).map(x => `${k}_${x}`)).flat();
}
return nodeTypes.map((nodeType) =>
return <>
{ nodeTypes.map((nodeType) =>
<Input
type="dropdown"
label={`${nodeType} variable`}
value=""
options={optionsForType(nodeType)}
onChange={onChange}
onChange={(v) => onChange(v, VariableType.statistic)}
/>
);
)
}
{ (visualizationOptions.length > 0) ? <Input
type="dropdown"
label={`Visualization`}
value=""
options={visualizationOptions}
onChange={(v) => onChange(v, VariableType.visualization)}
/> : ''
}
</>;
};
\ No newline at end of file
Loading