Skip to content
Snippets Groups Projects
Commit 749e366c authored by Alexander Rose's avatar Alexander Rose
Browse files

added 'Invalid Option' to select control; tweaked assembly param

parent 573eedd7
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ import { compile } from 'mol-script/runtime/query/compiler'; ...@@ -14,6 +14,7 @@ import { compile } from 'mol-script/runtime/query/compiler';
import { MolScriptBuilder } from 'mol-script/language/builder'; import { MolScriptBuilder } from 'mol-script/language/builder';
import { StateObject } from 'mol-state'; import { StateObject } from 'mol-state';
import { PluginContext } from 'mol-plugin/context'; import { PluginContext } from 'mol-plugin/context';
import { stringToWords } from 'mol-util/string';
export { TrajectoryFromMmCif } export { TrajectoryFromMmCif }
type TrajectoryFromMmCif = typeof TrajectoryFromMmCif type TrajectoryFromMmCif = typeof TrajectoryFromMmCif
...@@ -90,21 +91,21 @@ const StructureAssemblyFromModel = PluginStateTransform.BuiltIn({ ...@@ -90,21 +91,21 @@ const StructureAssemblyFromModel = PluginStateTransform.BuiltIn({
to: SO.Molecule.Structure, to: SO.Molecule.Structure,
params(a) { params(a) {
const model = a.data; const model = a.data;
const ids = model.symmetry.assemblies.map(a => [a.id, a.id] as [string, string]); const ids = model.symmetry.assemblies.map(a => [a.id, `${a.id}: ${stringToWords(a.details)}`] as [string, string]);
return { id: PD.makeOptional(PD.Select(ids.length ? ids[0][0] : '', ids, { label: 'Asm Id', description: 'Assembly Id' })) }; if (!ids.length) ids.push(['deposited', 'Deposited'])
return { id: PD.Select(ids[0][0], ids, { label: 'Asm Id', description: 'Assembly Id' }) };
} }
})({ })({
apply({ a, params }, plugin: PluginContext) { apply({ a, params }, plugin: PluginContext) {
return Task.create('Build Assembly', async ctx => { return Task.create('Build Assembly', async ctx => {
let id = (params.id || '').trim();
const model = a.data; const model = a.data;
if (!id && model.symmetry.assemblies.length) id = model.symmetry.assemblies[0].id; const id = params.id;
const asm = ModelSymmetry.findAssembly(model, id); const asm = ModelSymmetry.findAssembly(model, id);
if (id && !asm) throw new Error(`Assembly '${id}' not found`); if (id !== 'deposited' && !asm) throw new Error(`Assembly '${id}' not found`);
const base = Structure.ofModel(model); const base = Structure.ofModel(model);
if (!asm) { if (!asm) {
plugin.log.warn(`Model '${a.label}' has no assembly, returning default structure.`); plugin.log.warn(`Model '${a.label}' has no assembly, returning deposited structure.`);
const label = { label: a.data.label, description: structureDesc(base) }; const label = { label: a.data.label, description: structureDesc(base) };
return new SO.Molecule.Structure(base, label); return new SO.Molecule.Structure(base, label);
} }
......
...@@ -203,6 +203,7 @@ export class SelectControl extends SimpleParam<PD.Select<string | number>> { ...@@ -203,6 +203,7 @@ export class SelectControl extends SimpleParam<PD.Select<string | number>> {
} }
renderControl() { renderControl() {
return <select value={this.props.value || ''} onChange={this.onChange} disabled={this.props.isDisabled}> return <select value={this.props.value || ''} onChange={this.onChange} disabled={this.props.isDisabled}>
{!this.props.param.options.some(e => e[0] === this.props.value) ? <option key={this.props.value} value={this.props.value}>{`Invalid Option '${this.props.value}'`}</option> : ''}
{this.props.param.options.map(([value, label]) => <option key={value} value={value}>{label}</option>)} {this.props.param.options.map(([value, label]) => <option key={value} value={value}>{label}</option>)}
</select>; </select>;
} }
......
...@@ -25,4 +25,16 @@ export const upperCase = (str: string) => str.toUpperCase() ...@@ -25,4 +25,16 @@ export const upperCase = (str: string) => str.toUpperCase()
/** Uppercase the first character of each word. */ /** Uppercase the first character of each word. */
export function capitalize(str: string) { export function capitalize(str: string) {
return str.toLowerCase().replace(/^\w|\s\w/g, upperCase); return str.toLowerCase().replace(/^\w|\s\w/g, upperCase);
}
export function splitSnakeCase(str: string) {
return str.replace(/_/g, ' ')
}
export function snakeCaseToWords(str: string) {
return capitalize(splitSnakeCase(str))
}
export function stringToWords(str: string) {
return capitalize(splitCamelCase(splitSnakeCase(str)))
} }
\ 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