add 'filter' property to CallBlock to prepare to filter suggestions on output type
This commit is contained in:
parent
0a8d430d3a
commit
d3138e6617
2 changed files with 7 additions and 5 deletions
|
|
@ -22,9 +22,10 @@ interface CallBlockProps<
|
||||||
FnState=EditorState,
|
FnState=EditorState,
|
||||||
InputState=EditorState,
|
InputState=EditorState,
|
||||||
> extends State2Props<CallBlockState<FnState,InputState>,EditorState> {
|
> extends State2Props<CallBlockState<FnState,InputState>,EditorState> {
|
||||||
|
filter: (suggestion: SuggestionType) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function headlessCallBlock({setState}: CallBlockProps) {
|
function headlessCallBlock(setState: (callback: SetStateFn<CallBlockState,EditorState>) => void) {
|
||||||
const setFn = (callback: SetStateFn) => {
|
const setFn = (callback: SetStateFn) => {
|
||||||
setState(state => ({...state, fn: callback(state.fn)}));
|
setState(state => ({...state, fn: callback(state.fn)}));
|
||||||
}
|
}
|
||||||
|
|
@ -40,9 +41,9 @@ function headlessCallBlock({setState}: CallBlockProps) {
|
||||||
return {setFn, setInput, onFnCancel, onInputCancel};
|
return {setFn, setInput, onFnCancel, onInputCancel};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CallBlock({ state, setState }: CallBlockProps) {
|
export function CallBlock({ state, setState, filter }: CallBlockProps) {
|
||||||
const {setFn, setInput, onFnCancel, onInputCancel}
|
const {setFn, setInput, onFnCancel, onInputCancel}
|
||||||
= headlessCallBlock({ state, setState });
|
= headlessCallBlock(setState);
|
||||||
const env = useContext(EnvContext);
|
const env = useContext(EnvContext);
|
||||||
const resolved = evalEditorBlock(state, env);
|
const resolved = evalEditorBlock(state, env);
|
||||||
return <span className={"functionBlock" + ((resolved instanceof DeepError) ? " unifyError" : "")}>
|
return <span className={"functionBlock" + ((resolved instanceof DeepError) ? " unifyError" : "")}>
|
||||||
|
|
@ -84,7 +85,7 @@ function FunctionHeader({ fn, setFn, input, onFnCancel }) {
|
||||||
const {
|
const {
|
||||||
setFn : setFnFn,
|
setFn : setFnFn,
|
||||||
onFnCancel : onFnFnCancel,
|
onFnCancel : onFnFnCancel,
|
||||||
} = headlessCallBlock({state: fn, setState: setFn});
|
} = headlessCallBlock(setFn);
|
||||||
|
|
||||||
return <FunctionHeader
|
return <FunctionHeader
|
||||||
fn={fn.fn}
|
fn={fn.fn}
|
||||||
|
|
@ -130,7 +131,7 @@ function NestedParams({fn, setFn, depth, errorDepth}) {
|
||||||
const {
|
const {
|
||||||
setFn : setFnFn,
|
setFn : setFnFn,
|
||||||
setInput : setFnInput,
|
setInput : setFnInput,
|
||||||
} = headlessCallBlock({state: fn, setState: setFn});
|
} = headlessCallBlock(setFn);
|
||||||
return <InputParams
|
return <InputParams
|
||||||
fn={fn.fn}
|
fn={fn.fn}
|
||||||
setFn={setFnFn}
|
setFn={setFnFn}
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ export function Editor({state, setState, onCancel, filter}: EditorProps) {
|
||||||
return <CallBlock
|
return <CallBlock
|
||||||
state={state}
|
state={state}
|
||||||
setState={setState as (callback:(p:CallBlockState)=>EditorState)=>void}
|
setState={setState as (callback:(p:CallBlockState)=>EditorState)=>void}
|
||||||
|
filter={filter}
|
||||||
/>;
|
/>;
|
||||||
case "let":
|
case "let":
|
||||||
return <LetInBlock
|
return <LetInBlock
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue