-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from stone-lyl/main
feat: implement a new parameter type "StringList"
- Loading branch information
Showing
10 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/core/src/ItemWithParams/StringListParamEvaluator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/ui/src/components/DataStory/Form/StringListInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters