Browse Source

ParamDefinition.ValueRef defaultRef option

David Sehnal 4 years ago
parent
commit
dfa83c94f7
2 changed files with 4 additions and 3 deletions
  1. 1 1
      src/mol-plugin-state/transforms/misc.ts
  2. 3 2
      src/mol-util/param-definition.ts

+ 1 - 1
src/mol-plugin-state/transforms/misc.ts

@@ -42,7 +42,7 @@ const CreateGroup = PluginStateTransform.BuiltIn({
 //     params: (_, ctx: PluginContext) => {
 //         const getOptions = () => ctx.state.data.selectQ(q => q.rootsOfType(SO.Molecule.Model)).map(m => [m.transform.ref, m.obj?.label || m.transform.ref] as [string, string]);
 //         return {
-//             ref: PD.ValueRef<SO.Molecule.Model>(getOptions, ctx.state.data.tryGetCellData)
+//             ref: PD.ValueRef<SO.Molecule.Model>(getOptions, ctx.state.data.tryGetCellData, { defaultRef: getOptions()[0]?.[0] })
 //         };
 //     }
 // })({

+ 3 - 2
src/mol-util/param-definition.ts

@@ -286,10 +286,11 @@ export namespace ParamDefinition {
     export interface ValueRef<T = any> extends Base<{ ref: string, getValue: () => T }> {
         type: 'value-ref',
         resolveRef: (ref: string) => T,
+        // a provider because the list changes over time
         getOptions: () => Select<string>['options'],
     }
-    export function ValueRef<T>(getOptions: ValueRef['getOptions'], resolveRef: ValueRef<T>['resolveRef'], info?: Info) {
-        return setInfo<ValueRef<T>>({ type: 'value-ref', defaultValue: { ref: '', getValue: unsetGetValue as any }, getOptions, resolveRef }, info);
+    export function ValueRef<T>(getOptions: ValueRef['getOptions'], resolveRef: ValueRef<T>['resolveRef'], info?: Info & { defaultRef?: string }) {
+        return setInfo<ValueRef<T>>({ type: 'value-ref', defaultValue: { ref: info?.defaultRef ?? '', getValue: unsetGetValue as any }, getOptions, resolveRef }, info);
     }
 
     export interface Converted<T, C> extends Base<T> {