Skip to content
Snippets Groups Projects
Commit cf0d5673 authored by David Sehnal's avatar David Sehnal
Browse files

wip, params

parent faf3a714
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ export const CreateStructureFromPDBe = StateAction.create<PluginStateObject.Root
definition: () => ({
id: PD.Text('PDB id', '', '1grm'),
}),
validate: p => !p.id || !p.id.trim() ? [['Enter id.', 'id']] : void 0
// validate: p => !p.id || !p.id.trim() ? [['Enter id.', 'id']] : void 0
},
apply({ params, state }) {
const url = `http://www.ebi.ac.uk/pdbe/static/entry/${params.id.toLowerCase()}_updated.cif`;
......
......@@ -31,7 +31,7 @@ const Download = PluginStateTransform.Create<SO.Root, SO.Data.String | SO.Data.B
label: PD.Text('Label', '', ''),
isBinary: PD.Boolean('Binary', 'If true, download data as binary (string otherwise)', false)
}),
validate: p => !p.url || !p.url.trim() ? [['Enter url.', 'url']] : void 0
// validate: p => !p.url || !p.url.trim() ? [['Enter url.', 'url']] : void 0
},
apply({ params: p }, globalCtx: PluginContext) {
return Task.create('Download', async ctx => {
......
......@@ -14,7 +14,10 @@ import { ParamDefinition as PD } from 'mol-util/param-definition';
export { CreateStructureRepresentation }
namespace CreateStructureRepresentation {
export interface Params {
type: { name: string, params: any /** todo is there "common type" */ }
type: { name: string, params: any /** todo is there "common type" */ },
// TODO
// colorTheme: { name: string, params: any /** todo is there "common type" */ }
// sizeTheme: { name: string, params: any /** todo is there "common type" */ }
}
}
const CreateStructureRepresentation = PluginStateTransform.Create<SO.Molecule.Structure, SO.Molecule.Representation3D, CreateStructureRepresentation.Params>({
......
......@@ -4,7 +4,7 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { StateObject, State, Transform, StateObjectCell } from 'mol-state';
import { StateObject, State, Transform, StateObjectCell, Transformer } from 'mol-state';
import { shallowEqual } from 'mol-util/object';
import * as React from 'react';
import { PurePluginComponent } from '../base';
......@@ -23,11 +23,14 @@ class StateTransformParameters extends PurePluginComponent<StateTransformParamet
}
validate(params: any) {
const validate = this.props.info.definition.validate;
if (!validate) return void 0;
const result = validate(params, this.props.info.source, this.plugin);
if (!result || result.length === 0) return void 0;
return result.map(r => r[0]);
// TODO
return void 0;
// const validate = this.props.info.definition.validate;
// if (!validate) return void 0;
// const result = validate(params, this.props.info.source, this.plugin);
// if (!result || result.length === 0) return void 0;
// return result.map(r => r[0]);
}
areInitial(params: any) {
......@@ -50,7 +53,7 @@ class StateTransformParameters extends PurePluginComponent<StateTransformParamet
namespace StateTransformParameters {
export interface Props {
info: {
definition: PD.Provider,
definition: Transformer.ParamsProvider,
params: PD.Params,
initialValues: any,
source: StateObject,
......
......@@ -46,7 +46,7 @@ namespace StateAction {
*/
apply(params: ApplyParams<A, P>, globalCtx: unknown): T | Task<T>,
readonly params?: PD.Provider<A, P, unknown>
readonly params?: Transformer.ParamsProvider<A, P>
/** Test if the transform can be applied to a given node */
isApplicable?(a: A, globalCtx: unknown): boolean
......
......@@ -47,6 +47,15 @@ export namespace Transformer {
export enum UpdateResult { Unchanged, Updated, Recreate }
export interface ParamsProvider<A extends StateObject = StateObject, P = any> {
/** Check the parameters and return a list of errors if the are not valid. */
default?(a: A, globalCtx: unknown): P,
/** Specify default control descriptors for the parameters */
definition?(a: A, globalCtx: unknown): { [K in keyof P]?: PD.Any },
/** Optional custom parameter equality. Use shallow structural equal by default. */
areEqual?(oldParams: P, newParams: P): boolean
}
export interface Definition<A extends StateObject = StateObject, B extends StateObject = StateObject, P = unknown> {
readonly name: string,
readonly from: StateObject.Ctor[],
......@@ -66,7 +75,7 @@ export namespace Transformer {
*/
update?(params: UpdateParams<A, B, P>, globalCtx: unknown): Task<UpdateResult> | UpdateResult,
readonly params?: PD.Provider<A, P, unknown>,
readonly params?: ParamsProvider<A, P>,
/** Test if the transform can be applied to a given node */
isApplicable?(a: A, globalCtx: unknown): boolean,
......
......@@ -135,14 +135,8 @@ export namespace ParamDefinition {
*/
export type ParamErrors = [string, string | string[]][]
export interface Provider<A = any, P = any, Ctx = any> {
/** Check the parameters and return a list of errors if the are not valid. */
default?(a: A, globalCtx: Ctx): P,
/** Specify default control descriptors for the parameters */
definition?(a: A, globalCtx: Ctx): { [K in keyof P]?: Any },
/** Check the parameters and return a list of errors if the are not valid. */
validate?(params: P, a: A, globalCtx: unknown): ParamErrors | undefined,
/** Optional custom parameter equality. Use shallow structural equal by default. */
areEqual?(oldParams: P, newParams: P): boolean
export function validate(params: Params, values: any): ParamErrors | undefined {
// TODO
return void 0;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment