Skip to content
Snippets Groups Projects
Select Git revision
  • 7ef1d906f1383ba2a1bab424cfd3dbc22b7c1269
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

actions.tsx

Blame
  • user avatar
    David Sehnal authored
    7ef1d906
    History
    actions.tsx 1.64 KiB
    /**
     * Copyright (c) 2018 - 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import * as React from 'react';
    import { PluginUIComponent } from '../base';
    import { ApplyActionContol } from './apply-action';
    import { State } from 'mol-state';
    
    export class StateObjectActions extends PluginUIComponent<{ state: State, nodeRef: string, hideHeader?: boolean, initiallyColapsed?: boolean }> {
        get current() {
            return this.plugin.state.behavior.currentObject.value;
        }
    
        componentDidMount() {
            this.subscribe(this.plugin.state.behavior.currentObject, o => {
                this.forceUpdate();
            });
    
            this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
                const current = this.current;
                if (current.ref !== ref || current.state !== state) return;
                this.forceUpdate();
            });
        }
    
        render() {
            const { state, nodeRef: ref } = this.props;
            const cell = state.cells.get(ref)!;
            const actions = state.actions.fromCell(cell, this.plugin);
            if (actions.length === 0) return null;
    
            const def = cell.transform.transformer.definition;
            const display = cell.obj ? cell.obj.label : (def.display && def.display.name) || def.name;
    
            return <>
                {!this.props.hideHeader && <div className='msp-section-header'>{`Actions (${display})`}</div> }
                {actions.map((act, i) => <ApplyActionContol plugin={this.plugin} key={`${act.id}`} state={state} action={act} nodeRef={ref} initiallyCollapsed={this.props.initiallyColapsed} />)}
            </>;
        }
    }