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

feat: implement a new parameter type "StringList" #370

Merged
merged 6 commits into from
Jan 21, 2025
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
3 changes: 3 additions & 0 deletions packages/core/src/InputObserverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class InputObserverController {

// The current requirement only needs to retain 'BUSY' and 'COMPLETE' in NodeStatus.
async reportNodeStatus(nodeId: NodeId, status: NodeStatus): Promise<void> {
if (status === 'AVAILABLE') {
return;
}
await this.storage.setNodeStatus(nodeId, status);
this.nodeStatus$.next({nodeId, status});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/ItemWithParams/ParamEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { StringableParamEvaluator } from './StringableParamEvaluator';
import { ParamsValueEvaluator } from '../types/ParamsValueEvaluator';
import { RepeatableParamEvaluator } from './RepeatableParamEvaluator';
import { SelectableParamEvaluator } from './SelectableParamEvaluator';
import { StringListParamEvaluator } from './StringListParamEvaluator';

export class ParamEvaluator implements ParamsValueEvaluator<any>{
private evaluators: ParamsValueEvaluator<Param>[] = [
new StringableParamEvaluator(),
new SelectableParamEvaluator(),
new RepeatableParamEvaluator(this),
new StringListParamEvaluator(),
]

canEvaluate(param: Param): param is Param {
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/ItemWithParams/StringListParamEvaluator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Param, StringableParam, StringListParam } from '../Param';
import { ItemValue } from '../types/ItemValue';
import { ParamsValueEvaluator } from '../types/ParamsValueEvaluator';

export class StringListParamEvaluator implements ParamsValueEvaluator<StringListParam> {
type = 'StringListParam' as const;

evaluate(itemValue: ItemValue, param: StringListParam) {
const value = param.value as string;
const result = value.split(',').map(v => v.trim().toString()).filter(v => v.length > 0);
return result;
}

canEvaluate(param: Param): param is StringListParam {
return param.type === this.type;
}
}
34 changes: 33 additions & 1 deletion packages/core/src/Param/Param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@ export type RepeatableParam<RepeatableRow> = {
value: Record<string, unknown>[]
}

/**
* This type can represent ["a", "b", "c"] using 'a, b, c', which facilitates user input
* */
export type StringListParam = {
name: string,
label: string,
help: string,
type: 'StringListParam',
value: unknown
}

export type Param =
SelectParam |
StringableParam |
PropertySelectionParam |
PortSelectionParam |
RepeatableParam<Param[]>
RepeatableParam<Param[]> |
StringListParam;

export type ParamValue = Param['value']

Expand All @@ -81,6 +93,26 @@ type StringableConfigType = Omit<StringableParam, 'value' | 'type'> & {
value: StringableInputValue['value']
}

export const strList = ({
name,
label,
help,
value,
}: {
name: string,
label?: string,
help?: string,
value?: unknown,
}): StringListParam => {
return {
name,
type: 'StringListParam',
label: label ?? name,
help: help ?? '',
value: value ?? undefined,
}
}

export const createDefaultStringable = ({
name,
label,
Expand Down
1 change: 1 addition & 0 deletions packages/ds-ext/src/DiagramEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class DiagramEditorProvider implements vscode.CustomEditorProvider<Diagra
return;
}

// @ts-ignore
const disposable = handler({ postMessage, event, document, inputObserverController: this.inputObserverController });
if(typeof disposable === 'function' && disposable){
disposables.push(disposable);
Expand Down
2 changes: 1 addition & 1 deletion packages/ds-ext/src/MessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DiagramDocument } from './DiagramDocument';
import { InputObserverController } from '@data-story/core';

export type MessageHandlerArgs = {
postMessage: (msg: any) => Thenable<boolean> | undefined;
postMessage: (msg: any) => boolean | undefined;
event: any;
document: DiagramDocument,
inputObserverController: InputObserverController
Expand Down
52 changes: 52 additions & 0 deletions packages/ui/src/components/DataStory/Form/StringListInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useCallback } from 'react';
import { FormComponent, FormComponentProps } from '../types';
import { FormFieldWrapper, useFormField } from './UseFormField';
import CodeMirror, { BasicSetupOptions } from '@uiw/react-codemirror';
import { StringListParam } from '@data-story/core/*';

const basicSetup: BasicSetupOptions = {
lineNumbers: false,
highlightActiveLineGutter: false,
highlightActiveLine: false,
foldGutter: false,
autocompletion: false,
};

function StringListInputComponent({
param,
node,
}: FormComponentProps) {
const { getValues, setValue} = useFormField();

const onChange = useCallback((value, viewUpdate) => {
setValue(value);
}, [setValue]);

return (<div className="group flex flex-col-reverse bg-gray-50 h-full border-gray-50 border-2">
<div className="flex w-full text-gray-500 max-h-64 overflow-y-auto">
<CodeMirror
className="text-xs h-full w-full bg-white font-mono"
value={(getValues() ?? '').toString()}
basicSetup={basicSetup}
onChange={onChange}
/>
</div>
</div>
);
}

export function StringListInput(props: FormComponentProps) {
return <FormFieldWrapper fieldName={props.param.name}>
<StringListInputComponent {...props} />
</FormFieldWrapper>
}

export class StringListComponent implements FormComponent<StringListParam> {
getComponent(params: FormComponentProps) {
return (<StringListInput {...params} />)
}

getType() {
return 'StringListParam'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StringableWithConfig } from './StringableWithConfig';
import { RepeatableWithConfig } from './RepeatableWithConfig';
import { SelectInput } from '../../../../Form/SelectInput';
import { FormFieldWrapper } from '../../../../Form/UseFormField';
import { StringListInput } from '../../../../Form/StringListInput';

export function ParamsComponent({
node,
Expand All @@ -22,6 +23,11 @@ export function ParamsComponent({
node={node}
/>}

{param.type === 'StringListParam' && <StringListInput
param={param}
node={node}
/>}

{/* Vertical layout */}
{param.type === 'RepeatableParam' && <RepeatableWithConfig
param={param}
Expand All @@ -38,10 +44,10 @@ export function ParamsComponent({
</>;
}

export function Params ({
export function Params({
node,
}) {
return (<FormFieldWrapper fieldName={'params'}>
<ParamsComponent node={node}/>
<ParamsComponent node={node} />
</FormFieldWrapper>);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { FormComponent, FormComponentProps } from '../../../../types';
import { StringableComponent } from './StringableWithConfig';
import { PortSelectionComponent } from '../../../../Form/PortSelectionInput';
import { SelectComponent } from '../../../../Form/SelectInput';
import { StringListComponent } from '../../../../Form/StringListInput';

export class ParamsComponentFactory{
availableComponents: FormComponent<Param>[] = [
new StringableComponent(),
new PortSelectionComponent(),
new SelectComponent(),
new StringListComponent(),
]
private selectedComponent?: FormComponent<Param> = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const TableNodeComponent = ({ id, data }: {
...virtualPaddingVars,
}}
data-cy={'data-story-table-scroll'}
className="max-h-64 max-w-128 nowheel overflow-auto scrollbar rounded-sm">
className="max-h-64 max-w-128 min-w-6 nowheel overflow-auto scrollbar rounded-sm">
<table className="table-fixed grid">
<MemoizedTableHeader
headerGroups={getHeaderGroups()}
Expand Down
Loading