From 875846c4d5b3d0ab4d5f6c21b4d0ecc8627c7e26 Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Tue, 17 Aug 2021 15:32:33 +0200 Subject: [PATCH 1/8] allow setting className on SimpleSchemaForm --- src/components/SimpleSchemaForm.jsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/SimpleSchemaForm.jsx b/src/components/SimpleSchemaForm.jsx index 199452670..4ccc8230a 100644 --- a/src/components/SimpleSchemaForm.jsx +++ b/src/components/SimpleSchemaForm.jsx @@ -20,7 +20,8 @@ export default class SimpleSchemaForm extends Component { colField: undefined, colWidth: undefined, disabled: false, - button: true + button: true, + className: undefined }; static propTypes = { @@ -33,7 +34,8 @@ export default class SimpleSchemaForm extends Component { colField: PropTypes.bool, colWidth: PropTypes.number, disabled: PropTypes.bool, - button: PropTypes.bool + button: PropTypes.bool, + className: PropTypes.string }; onChange = form => { @@ -75,6 +77,10 @@ export default class SimpleSchemaForm extends Component { }); } + if (this.props.className) { + extraConfig.className = `rjsf ${this.props.className}`; + } + each(['fields', 'className', 'formContext'], k => { if (this.props[k]) extraConfig[k] = this.props[k]; }); @@ -100,7 +106,9 @@ export default class SimpleSchemaForm extends Component { {...extraConfig} > {this.props.button ? ( - + ) : ( <> )} -- GitLab From 5b05103741bff6d8649498770eeaf48e6d2200f5 Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Tue, 17 Aug 2021 15:32:58 +0200 Subject: [PATCH 2/8] add initial ActorButton component to allow executing arb actors via simple button click --- src/components/samples/ActorButton.jsx | 68 ++++++++++++++++++++++++ src/components/yaml-layout/Component.jsx | 1 + src/connect/samples/ActorButton.js | 26 +++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/components/samples/ActorButton.jsx create mode 100644 src/connect/samples/ActorButton.js diff --git a/src/components/samples/ActorButton.jsx b/src/components/samples/ActorButton.jsx new file mode 100644 index 000000000..974989deb --- /dev/null +++ b/src/components/samples/ActorButton.jsx @@ -0,0 +1,68 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import RestService from 'services/RestService'; +import SimpleSchemaForm from 'components/SimpleSchemaForm'; +import { ucfirst } from 'helpers/formatting'; + +function ActorButton(props) { + const schemaName = `${ucfirst(props.actor)}Schema`; + const root = props.schemas[schemaName]; + const formData = { + sampleid: props.currentSample, + enqueue: false, + ...props.params + }; + + const { properties } = root.definitions[schemaName]; + const uiSchema = { + 'ui:order': root.uiorder, + ...root.uischema + }; + + const onSubmit = newFormData => { + console.log('onclick', newFormData); + return RestService[root.method](root.url, newFormData).catch(error => { + console.log(error); + this.props.actions.addToast({ + type: 'error', + title: 'Could not start actor', + text: error + }); + }); + }; + + return ( + + ); +} + +ActorButton.defaultProps = { + params: {}, + currentSample: undefined, + runningScan: undefined, + operator: false +}; + +ActorButton.propTypes = { + schemas: PropTypes.shape({}).isRequired, + actor: PropTypes.string.isRequired, + title: PropTypes.string.isRequired, + actions: PropTypes.shape({ + alert: PropTypes.func + }).isRequired, + params: PropTypes.shape({}), + currentSample: PropTypes.number, + runningScan: PropTypes.number, + operator: PropTypes.bool +}; + +export default ActorButton; diff --git a/src/components/yaml-layout/Component.jsx b/src/components/yaml-layout/Component.jsx index daf56300d..f7d073476 100644 --- a/src/components/yaml-layout/Component.jsx +++ b/src/components/yaml-layout/Component.jsx @@ -27,6 +27,7 @@ export const componentMap = { hdf5plot0d: 'hdf5/Hdf5Plot', // deprecated hdf5plot: 'hdf5/Hdf5Plot', newscanbuttonsample: 'samples/NewScanButtonSample2' + actorbutton: 'samples/ActorButton', }; export default function YamlComponent({ yamlNode, panel }) { diff --git a/src/connect/samples/ActorButton.js b/src/connect/samples/ActorButton.js new file mode 100644 index 000000000..28f92351e --- /dev/null +++ b/src/connect/samples/ActorButton.js @@ -0,0 +1,26 @@ +import { connect } from 'react-redux'; + +import { withNamespace } from 'providers/namespace'; +import app from 'providers/app'; +import session from 'providers/session'; +import scans from 'providers/scans'; +import metadata from 'providers/metadata'; + +import ActorButton from 'components/samples/ActorButton'; + +const mapStateToProps = (state, own) => ({ + schemas: own.providers.app.schema.selector('results', state), + operator: session.selector('operator', state), + runningScan: scans.selector('runningScanid', state), + currentSample: metadata.selector('currentSample', state) +}); + +const mapDispatchToProps = () => ({ + actions: { + addToast: payload => app.dispatch('ADD_TOAST', payload) + } +}); + +export default withNamespace({ app })( + connect(mapStateToProps, mapDispatchToProps)(ActorButton) +); -- GitLab From 67ec16cfc514fee00d21832d726a85b9cd05e2f0 Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Wed, 18 Aug 2021 09:03:56 +0200 Subject: [PATCH 3/8] tidy debug --- src/components/samples/ActorButton.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/samples/ActorButton.jsx b/src/components/samples/ActorButton.jsx index 974989deb..517193a68 100644 --- a/src/components/samples/ActorButton.jsx +++ b/src/components/samples/ActorButton.jsx @@ -21,9 +21,7 @@ function ActorButton(props) { }; const onSubmit = newFormData => { - console.log('onclick', newFormData); return RestService[root.method](root.url, newFormData).catch(error => { - console.log(error); this.props.actions.addToast({ type: 'error', title: 'Could not start actor', -- GitLab From 842eeb59cf53d4648efd4fafab749ae1dd453690 Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Thu, 21 Apr 2022 10:11:36 +0200 Subject: [PATCH 4/8] style --- src/components/yaml-layout/Component.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/yaml-layout/Component.jsx b/src/components/yaml-layout/Component.jsx index f7d073476..4f34f8289 100644 --- a/src/components/yaml-layout/Component.jsx +++ b/src/components/yaml-layout/Component.jsx @@ -26,8 +26,8 @@ export const componentMap = { sampledclist: 'samples/SampleDCList', hdf5plot0d: 'hdf5/Hdf5Plot', // deprecated hdf5plot: 'hdf5/Hdf5Plot', - newscanbuttonsample: 'samples/NewScanButtonSample2' - actorbutton: 'samples/ActorButton', + newscanbuttonsample: 'samples/NewScanButtonSample2', + actorbutton: 'samples/ActorButton' }; export default function YamlComponent({ yamlNode, panel }) { -- GitLab From 62f772d9be53f7795ffb6af8a4e57a80e980b227 Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Thu, 21 Apr 2022 10:21:31 +0200 Subject: [PATCH 5/8] correct fn call --- src/components/samples/ActorButton.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/samples/ActorButton.jsx b/src/components/samples/ActorButton.jsx index 517193a68..66768d4cb 100644 --- a/src/components/samples/ActorButton.jsx +++ b/src/components/samples/ActorButton.jsx @@ -22,7 +22,7 @@ function ActorButton(props) { const onSubmit = newFormData => { return RestService[root.method](root.url, newFormData).catch(error => { - this.props.actions.addToast({ + props.actions.addToast({ type: 'error', title: 'Could not start actor', text: error -- GitLab From ada266e95753db2b3760be4420c1b3290c2d0c6e Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Thu, 21 Apr 2022 13:22:46 +0200 Subject: [PATCH 6/8] add doc --- docs/samplescans.md | 85 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/docs/samplescans.md b/docs/samplescans.md index 6dae775c9..a4404f057 100644 --- a/docs/samplescans.md +++ b/docs/samplescans.md @@ -1,4 +1,6 @@ -The sample scan interface provides a list of data collections and allows one to easily launch an actor against the selected sample +Two components are provided to interact with the server side `samplescans` component. This component allows execution of actors against the current sample. + +The first component, loaded via `sampledclist` provides a list of data collections and allows one to easily launch an actor against the selected sample. ```js import SampleDCList from 'components/samples/SampleDCList'; @@ -14,3 +16,84 @@ const props = { ; ``` + +A second simple component can launch an actor against a sample on click via the `actorbutton` component: + +```js +import ActorButton from 'components/samples/ActorButton'; + +const props = { + operator: true, + actor: 'ct', + title: 'CT', + schemas: { + CtSchema: { + definitions: { + CtSchema: {}, + }, + }, + }, +}; + +
+ +
; +``` + +Optionally certain fields can be displayed: + +```js +import ActorButton from 'components/samples/ActorButton'; + +const props = { + operator: true, + actor: 'ct', + title: 'CT', + params: { + exposure: 1, + }, + schemas: { + CtSchema: { + definitions: { + CtSchema: { + additionalProperties: false, + properties: { + enqueue: { + default: false, + title: 'enqueue', + type: 'boolean', + }, + exposure: { + format: 'float', + title: 'Exposure Time', + type: 'number', + }, + sampleid: { title: 'sampleid', type: 'integer' }, + }, + required: ['exposure'], + type: 'object', + }, + }, + uischema: { + enqueue: { classNames: 'hidden-row', 'ui:widget': 'hidden' }, + sampleid: { classNames: 'hidden-row', 'ui:widget': 'hidden' }, + }, + }, + }, +}; + +
+ +
; +``` + +The yaml configuration for this would look something like: + +```yaml +component: actorbutton +options: + actor: ct + title: 'CT Update' + params: + exposure: 1 +``` -- GitLab From 893bbc40d9c69dab960414ee79be98c01f17428e Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Thu, 21 Apr 2022 13:33:28 +0200 Subject: [PATCH 7/8] tidy --- docs/samplescans.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samplescans.md b/docs/samplescans.md index a4404f057..4971d1116 100644 --- a/docs/samplescans.md +++ b/docs/samplescans.md @@ -12,7 +12,7 @@ const props = { datacollections: [], }; -
+
; ``` -- GitLab From e15c454c7217b0de7f05fde76e476c041c96142e Mon Sep 17 00:00:00 2001 From: Stuart Fisher Date: Thu, 21 Apr 2022 13:36:14 +0200 Subject: [PATCH 8/8] add example yaml --- docs/samplescans.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/samplescans.md b/docs/samplescans.md index 4971d1116..7df0e068f 100644 --- a/docs/samplescans.md +++ b/docs/samplescans.md @@ -17,6 +17,21 @@ const props = {
; ``` +And the example yaml configuration, where the metadata provider is linked to the currently selected sample: + +```yaml +component: sampledclist +options: + selectable: true + providers: + metadata: + datacollections: + namespace: sample + params: + sampleid: $state.currentSample + per_page: 5 +``` + A second simple component can launch an actor against a sample on click via the `actorbutton` component: ```js -- GitLab