import { useMemo } from "react"; import { Intent } from "@blueprintjs/core"; import { RowGroup, RowGroupOption, TextField, TextWithSelect, SettingsManager } from "Components/UserSettings"; const { Provider: MetadataProvider, useSettings: useMetadataSettings } = new SettingsManager<"metadata">(); const PARAM_OPTIONS = [ { label: "By name", value: "srcName" }, { label: "By UID", value: "srcUid" } ]; const USE_OPTIONS = { "default": "Default formatter", "function": "Custom function", "smartblock": "SmartBlock" }; function MetadataWidget(){ const [ { func, smartblock: { param, paramValue }, use }, setOpts ] = useMetadataSettings(); const handlers = useMemo(() => { function updateSingleValue(op, val){ setOpts(prevState => ({ ...prevState, [op]: val })); } function updateSmartblock(prop, val){ const returnValue = prop == "param" ? { param: val, paramValue: "" } : { paramValue: val }; setOpts(prevState => ({ ...prevState, smartblock: { ...prevState.smartblock, ...returnValue } })); } return { updateFuncName: (val) => updateSingleValue("func", val), updateSmartblockParam: (val) => updateSmartblock("param", val), updateSmartblockParamValue: (val) => updateSmartblock("paramValue", val), updateUse: (val) => updateSingleValue("use", val) }; }, [setOpts]); const smartblockButtonProps = useMemo(() => ({ intent: Intent.PRIMARY }), []); return ( ); } export { MetadataProvider, MetadataWidget, useMetadataSettings };