From fdcd99b597d0be5df46132d192f2a5a81cba3fed Mon Sep 17 00:00:00 2001 From: pkupczyk <piotr.kupczyk@id.ethz.ch> Date: Tue, 15 Feb 2022 15:52:17 +0100 Subject: [PATCH] SSDM-11169 : Properties overview in the new admin UI - remove property type management and leave just the read-only property type overview (after a discussion with Juan and Caterina) --- .../src/js/common/consts/objectType.js | 2 - openbis_ng_ui/src/js/common/consts/routes.js | 8 - openbis_ng_ui/src/js/common/messages.js | 2 - .../common/browser/BrowserController.js | 16 +- .../src/js/components/types/Types.jsx | 9 - .../types/browser/TypeBrowserController.js | 123 ++-- .../form/propertytype/PropertyTypeForm.jsx | 100 ---- .../propertytype/PropertyTypeFormButtons.jsx | 44 -- .../PropertyTypeFormController.js | 46 -- .../PropertyTypeFormControllerChange.js | 53 -- .../PropertyTypeFormControllerLoad.js | 118 ---- .../PropertyTypeFormControllerSave.js | 87 --- .../PropertyTypeFormControllerValidate.js | 66 --- .../propertytype/PropertyTypeFormFacade.js | 42 -- .../PropertyTypeFormParameters.jsx | 538 ------------------ .../js/components/AppComponentLogin.test.js | 7 +- .../ToolBrowserComponentFilter.test.js | 1 - .../TypeBrowserComponentFilter.test.js | 3 +- 18 files changed, 80 insertions(+), 1185 deletions(-) delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeForm.jsx delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormButtons.jsx delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormController.js delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerChange.js delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerLoad.js delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerSave.js delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerValidate.js delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormFacade.js delete mode 100644 openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormParameters.jsx diff --git a/openbis_ng_ui/src/js/common/consts/objectType.js b/openbis_ng_ui/src/js/common/consts/objectType.js index 56342204ee0..b785167334b 100644 --- a/openbis_ng_ui/src/js/common/consts/objectType.js +++ b/openbis_ng_ui/src/js/common/consts/objectType.js @@ -3,7 +3,6 @@ const NEW_COLLECTION_TYPE = 'newCollectionType' const NEW_DATA_SET_TYPE = 'newDataSetType' const NEW_MATERIAL_TYPE = 'newMaterialType' const NEW_VOCABULARY_TYPE = 'newVocabularyType' -const NEW_PROPERTY_TYPE = 'newPropertyType' const NEW_USER = 'newUser' const NEW_USER_GROUP = 'newUserGroup' const NEW_DYNAMIC_PROPERTY_PLUGIN = 'newDynamicPropertyPlugin' @@ -33,7 +32,6 @@ export default { NEW_DATA_SET_TYPE, NEW_MATERIAL_TYPE, NEW_VOCABULARY_TYPE, - NEW_PROPERTY_TYPE, NEW_USER, NEW_USER_GROUP, NEW_DYNAMIC_PROPERTY_PLUGIN, diff --git a/openbis_ng_ui/src/js/common/consts/routes.js b/openbis_ng_ui/src/js/common/consts/routes.js index acc228a5e4c..5b362e9e13e 100644 --- a/openbis_ng_ui/src/js/common/consts/routes.js +++ b/openbis_ng_ui/src/js/common/consts/routes.js @@ -124,14 +124,6 @@ const routes = { type: objectTypes.OVERVIEW, id: objectTypes.VOCABULARY_TYPE }), - NEW_PROPERTY_TYPE: new Route('/new-property-type/:id', { - page: pages.TYPES, - type: objectTypes.NEW_PROPERTY_TYPE - }), - PROPERTY_TYPE: new Route('/property-type/:id', { - page: pages.TYPES, - type: objectTypes.PROPERTY_TYPE - }), PROPERTY_TYPE_OVERVIEW: new Route('/property-type-overview', { page: pages.TYPES, type: objectTypes.OVERVIEW, diff --git a/openbis_ng_ui/src/js/common/messages.js b/openbis_ng_ui/src/js/common/messages.js index 87eb04627a2..91f669fe320 100644 --- a/openbis_ng_ui/src/js/common/messages.js +++ b/openbis_ng_ui/src/js/common/messages.js @@ -116,7 +116,6 @@ const keys = { NEW_GROUP: 'NEW_GROUP', NEW_MATERIAL_TYPE: 'NEW_MATERIAL_TYPE', NEW_OBJECT_TYPE: 'NEW_OBJECT_TYPE', - NEW_PROPERTY_TYPE: 'NEW_PROPERTY_TYPE', NEW_QUERY: 'NEW_QUERY', NEW_USER: 'NEW_USER', NEW_VOCABULARY_TYPE: 'NEW_VOCABULARY_TYPE', @@ -348,7 +347,6 @@ const messages_en = { [keys.NEW_GROUP]: 'New Group', [keys.NEW_MATERIAL_TYPE]: 'New Material Type', [keys.NEW_OBJECT_TYPE]: 'New Object Type', - [keys.NEW_PROPERTY_TYPE]: 'New Property Type', [keys.NEW_QUERY]: 'New Query', [keys.NEW_USER]: 'New User', [keys.NEW_VOCABULARY_TYPE]: 'New Vocabulary Type', diff --git a/openbis_ng_ui/src/js/components/common/browser/BrowserController.js b/openbis_ng_ui/src/js/components/common/browser/BrowserController.js index cd761932f46..2565f94de6b 100644 --- a/openbis_ng_ui/src/js/components/common/browser/BrowserController.js +++ b/openbis_ng_ui/src/js/components/common/browser/BrowserController.js @@ -43,12 +43,8 @@ export default class BrowserController { load() { return this.doLoadNodes().then(loadedNodes => { - const { - filter, - nodes, - selectedId, - selectedObject - } = this.context.getState() + const { filter, nodes, selectedId, selectedObject } = + this.context.getState() let newNodes = this._createNodes(loadedNodes) newNodes = this._filterNodes(newNodes, filter) @@ -120,12 +116,8 @@ export default class BrowserController { } filterChange(newFilter) { - const { - filter, - nodes, - selectedId, - selectedObject - } = this.context.getState() + const { filter, nodes, selectedId, selectedObject } = + this.context.getState() let initialNodes = null diff --git a/openbis_ng_ui/src/js/components/types/Types.jsx b/openbis_ng_ui/src/js/components/types/Types.jsx index 7f7a66e9c29..2e3a0576fce 100644 --- a/openbis_ng_ui/src/js/components/types/Types.jsx +++ b/openbis_ng_ui/src/js/components/types/Types.jsx @@ -6,7 +6,6 @@ import TypeBrowser from '@src/js/components/types/browser/TypeBrowser.jsx' import TypeSearch from '@src/js/components/types/search/TypeSearch.jsx' import EntityTypeForm from '@src/js/components/types/form/entitytype/EntityTypeForm.jsx' import VocabularyTypeForm from '@src/js/components/types/form/vocabularytype/VocabularyTypeForm.jsx' -import PropertyTypeForm from '@src/js/components/types/form/propertytype/PropertyTypeForm.jsx' import pages from '@src/js/common/consts/pages.js' import objectType from '@src/js/common/consts/objectType.js' import messages from '@src/js/common/messages.js' @@ -48,11 +47,6 @@ class Types extends React.Component { object.type === objectType.NEW_VOCABULARY_TYPE ) { return <VocabularyTypeForm object={object} /> - } else if ( - object.type === objectType.PROPERTY_TYPE || - object.type === objectType.NEW_PROPERTY_TYPE - ) { - return <PropertyTypeForm object={object} /> } else { return <EntityTypeForm object={object} /> } @@ -85,8 +79,6 @@ class Types extends React.Component { messages.get(messages.NEW_MATERIAL_TYPE) + ' ', [objectType.NEW_VOCABULARY_TYPE]: messages.get(messages.NEW_VOCABULARY_TYPE) + ' ', - [objectType.NEW_PROPERTY_TYPE]: - messages.get(messages.NEW_PROPERTY_TYPE) + ' ', [objectType.OBJECT_TYPE]: messages.get(messages.OBJECT_TYPE) + ': ', [objectType.COLLECTION_TYPE]: messages.get(messages.COLLECTION_TYPE) + ': ', @@ -94,7 +86,6 @@ class Types extends React.Component { [objectType.MATERIAL_TYPE]: messages.get(messages.MATERIAL_TYPE) + ': ', [objectType.VOCABULARY_TYPE]: messages.get(messages.VOCABULARY_TYPE) + ': ', - [objectType.PROPERTY_TYPE]: messages.get(messages.PROPERTY_TYPE) + ': ', [objectType.SEARCH]: messages.get(messages.SEARCH) + ': ' } label = prefixes[object.type] + object.id diff --git a/openbis_ng_ui/src/js/components/types/browser/TypeBrowserController.js b/openbis_ng_ui/src/js/components/types/browser/TypeBrowserController.js index 7ea7dee41c2..a0648bcf282 100644 --- a/openbis_ng_ui/src/js/components/types/browser/TypeBrowserController.js +++ b/openbis_ng_ui/src/js/components/types/browser/TypeBrowserController.js @@ -34,10 +34,6 @@ export default class TypeBrowserController extends BrowserController { openbis.searchVocabularies( new openbis.VocabularySearchCriteria(), new openbis.VocabularyFetchOptions() - ), - openbis.searchPropertyTypes( - new openbis.PropertyTypeSearchCriteria(), - new openbis.PropertyTypeFetchOptions() ) ]).then( ([ @@ -45,8 +41,7 @@ export default class TypeBrowserController extends BrowserController { collectionTypes, dataSetTypes, materialTypes, - vocabularyTypes, - propertyTypes + vocabularyTypes ]) => { const _createNodes = (types, typeName, callback) => { return _.map(types, type => { @@ -87,13 +82,6 @@ export default class TypeBrowserController extends BrowserController { node.canRemove = !type.managedInternally || this.isSystemUser() } ) - let propertyTypeNodes = _createNodes( - propertyTypes.getObjects(), - objectType.PROPERTY_TYPE, - (type, node) => { - node.canRemove = !type.managedInternally || this.isSystemUser() - } - ) let nodes = [ { @@ -148,10 +136,7 @@ export default class TypeBrowserController extends BrowserController { object: { type: objectType.OVERVIEW, id: objectType.PROPERTY_TYPE - }, - children: propertyTypeNodes, - childrenType: objectType.NEW_PROPERTY_TYPE, - canAdd: true + } } ] @@ -174,14 +159,14 @@ export default class TypeBrowserController extends BrowserController { } const { type, id } = node.object + const reason = 'deleted via ng_ui' - var operation = this._prepareRemoveOperation(type, id, 'deleted via ng_ui') - - const options = new openbis.SynchronousOperationExecutionOptions() - options.setExecuteInOrder(true) - - return openbis - .executeOperations([operation], options) + return this._prepareRemoveOperations(type, id, reason) + .then(operations => { + const options = new openbis.SynchronousOperationExecutionOptions() + options.setExecuteInOrder(true) + return openbis.executeOperations(operations, options) + }) .then(() => { this.context.dispatch(actions.objectDelete(this.getPage(), type, id)) }) @@ -190,50 +175,86 @@ export default class TypeBrowserController extends BrowserController { }) } - _prepareRemoveOperation(type, id, reason) { + _prepareRemoveOperations(type, id, reason) { + if ( + type === objectType.OBJECT_TYPE || + type === objectType.COLLECTION_TYPE || + type === objectType.DATA_SET_TYPE || + type === objectType.MATERIAL_TYPE + ) { + return this._prepareRemoveEntityTypeOperations(type, id, reason) + } else if (type === objectType.VOCABULARY_TYPE) { + return this._prepareRemoveVocabularyTypeOperations(type, id, reason) + } + } + + _prepareRemoveEntityTypeOperations(type, id, reason) { + const operations = [] + if (type === objectType.OBJECT_TYPE) { const options = new openbis.SampleTypeDeletionOptions() options.setReason(reason) - return new openbis.DeleteSampleTypesOperation( - [new openbis.EntityTypePermId(id)], - options + operations.push( + new openbis.DeleteSampleTypesOperation( + [new openbis.EntityTypePermId(id)], + options + ) ) } else if (type === objectType.COLLECTION_TYPE) { const options = new openbis.ExperimentTypeDeletionOptions() options.setReason(reason) - return new openbis.DeleteExperimentTypesOperation( - [new openbis.EntityTypePermId(id)], - options + operations.push( + new openbis.DeleteExperimentTypesOperation( + [new openbis.EntityTypePermId(id)], + options + ) ) } else if (type === objectType.DATA_SET_TYPE) { const options = new openbis.DataSetTypeDeletionOptions() options.setReason(reason) - return new openbis.DeleteDataSetTypesOperation( - [new openbis.EntityTypePermId(id)], - options + operations.push( + new openbis.DeleteDataSetTypesOperation( + [new openbis.EntityTypePermId(id)], + options + ) ) } else if (type === objectType.MATERIAL_TYPE) { const options = new openbis.MaterialTypeDeletionOptions() options.setReason(reason) - return new openbis.DeleteMaterialTypesOperation( - [new openbis.EntityTypePermId(id)], - options + operations.push( + new openbis.DeleteMaterialTypesOperation( + [new openbis.EntityTypePermId(id)], + options + ) ) - } else if (type === objectType.VOCABULARY_TYPE) { - const options = new openbis.VocabularyDeletionOptions() - options.setReason(reason) - return new openbis.DeleteVocabulariesOperation( + } + + const criteria = new openbis.PropertyTypeSearchCriteria() + criteria.withCode().thatStartsWith(id + '.') + const fo = new openbis.PropertyTypeFetchOptions() + + return openbis.searchPropertyTypes(criteria, fo).then(results => { + const ids = results + .getObjects() + .map(propertyType => propertyType.getPermId()) + if (!_.isEmpty(ids)) { + const options = new openbis.PropertyTypeDeletionOptions() + options.setReason(reason) + operations.push(new openbis.DeletePropertyTypesOperation(ids, options)) + } + return operations + }) + } + + _prepareRemoveVocabularyTypeOperations(type, id, reason) { + const options = new openbis.VocabularyDeletionOptions() + options.setReason(reason) + return Promise.resolve([ + new openbis.DeleteVocabulariesOperation( [new openbis.VocabularyPermId(id)], options ) - } else if (type === objectType.PROPERTY_TYPE) { - const options = new openbis.PropertyTypeDeletionOptions() - options.setReason(reason) - return new openbis.DeletePropertyTypesOperation( - [new openbis.PropertyTypePermId(id)], - options - ) - } + ]) } doGetObservedModifications() { @@ -257,10 +278,6 @@ export default class TypeBrowserController extends BrowserController { [objectType.VOCABULARY_TYPE]: [ objectOperation.CREATE, objectOperation.DELETE - ], - [objectType.PROPERTY_TYPE]: [ - objectOperation.CREATE, - objectOperation.DELETE ] } } diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeForm.jsx b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeForm.jsx deleted file mode 100644 index 78553800a10..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeForm.jsx +++ /dev/null @@ -1,100 +0,0 @@ -import _ from 'lodash' -import React from 'react' -import autoBind from 'auto-bind' -import { connect } from 'react-redux' -import { withStyles } from '@material-ui/core/styles' -import ComponentContext from '@src/js/components/common/ComponentContext.js' -import PageWithTwoPanels from '@src/js/components/common/page/PageWithTwoPanels.jsx' -import PropertyTypeFormController from '@src/js/components/types/form/propertytype/PropertyTypeFormController.js' -import PropertyTypeFormFacade from '@src/js/components/types/form/propertytype/PropertyTypeFormFacade.js' -import PropertyTypeFormParameters from '@src/js/components/types/form/propertytype/PropertyTypeFormParameters.jsx' -import PropertyTypeFormButtons from '@src/js/components/types/form/propertytype/PropertyTypeFormButtons.jsx' -import selectors from '@src/js/store/selectors/selectors.js' -import logger from '@src/js/common/logger.js' - -const styles = () => ({}) - -function mapStateToProps(state) { - return { - session: selectors.getSession(state) - } -} - -class PropertyTypeForm extends React.PureComponent { - constructor(props) { - super(props) - autoBind(this) - - this.state = {} - - if (this.props.controller) { - this.controller = this.props.controller - } else { - this.controller = new PropertyTypeFormController( - new PropertyTypeFormFacade() - ) - } - - this.controller.init(new ComponentContext(this)) - } - - componentDidMount() { - this.controller.load() - } - - render() { - logger.log(logger.DEBUG, 'PropertyTypeForm.render') - - const { loadId, loading, loaded, propertyType } = this.state - - return ( - <PageWithTwoPanels - key={loadId} - loading={loading} - loaded={loaded} - object={propertyType} - renderAdditionalPanel={() => this.renderAdditionalPanel()} - renderButtons={() => this.renderButtons()} - /> - ) - } - - renderAdditionalPanel() { - const { controller } = this - const { propertyType, selection, mode } = this.state - - return ( - <PropertyTypeFormParameters - controller={controller} - propertyType={propertyType} - selection={selection} - mode={mode} - onChange={controller.handleChange} - onSelectionChange={controller.handleSelectionChange} - onBlur={controller.handleBlur} - /> - ) - } - - renderButtons() { - const { controller } = this - const { propertyType, selection, changed, mode } = this.state - - return ( - <PropertyTypeFormButtons - onEdit={controller.handleEdit} - onSave={controller.handleSave} - onCancel={controller.handleCancel} - propertyType={propertyType} - selection={selection} - changed={changed} - mode={mode} - /> - ) - } -} - -export default _.flow( - connect(mapStateToProps), - withStyles(styles) -)(PropertyTypeForm) diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormButtons.jsx b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormButtons.jsx deleted file mode 100644 index 130d378d3d7..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormButtons.jsx +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react' -import { connect } from 'react-redux' -import PageButtons from '@src/js/components/common/page/PageButtons.jsx' -import users from '@src/js/common/consts/users.js' -import selectors from '@src/js/store/selectors/selectors.js' -import logger from '@src/js/common/logger.js' - -function mapStateToProps(state) { - return { - session: selectors.getSession(state) - } -} - -class PropertyTypeFormButtons extends React.PureComponent { - constructor(props) { - super(props) - } - - render() { - logger.log(logger.DEBUG, 'PropertyTypeFormButtons.render') - - const { mode, onEdit, onSave, onCancel, changed, propertyType } = this.props - - return ( - <PageButtons - mode={mode} - changed={changed} - onEdit={this.isInternal() && !this.isSystemUser() ? null : onEdit} - onSave={onSave} - onCancel={propertyType.id ? onCancel : null} - /> - ) - } - - isInternal() { - return this.props.propertyType.internal.value - } - - isSystemUser() { - return this.props.session && this.props.session.userName === users.SYSTEM - } -} - -export default connect(mapStateToProps)(PropertyTypeFormButtons) diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormController.js b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormController.js deleted file mode 100644 index ce7c71aac00..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormController.js +++ /dev/null @@ -1,46 +0,0 @@ -import PageController from '@src/js/components/common/page/PageController.js' -import PropertyTypeFormControllerLoad from '@src/js/components/types/form/propertytype/PropertyTypeFormControllerLoad.js' -import PropertyTypeFormControllerValidate from '@src/js/components/types/form/propertytype/PropertyTypeFormControllerValidate.js' -import PropertyTypeFormControllerChange from '@src/js/components/types/form/propertytype/PropertyTypeFormControllerChange.js' -import PropertyTypeFormControllerSave from '@src/js/components/types/form/propertytype/PropertyTypeFormControllerSave.js' -import pages from '@src/js/common/consts/pages.js' -import objectTypes from '@src/js/common/consts/objectType.js' - -export default class PropertyTypeFormController extends PageController { - constructor(facade) { - super(facade) - } - - getPage() { - return pages.TYPES - } - - getNewObjectType() { - return objectTypes.NEW_PROPERTY_TYPE - } - - getExistingObjectType() { - return objectTypes.PROPERTY_TYPE - } - - load() { - return new PropertyTypeFormControllerLoad(this).execute() - } - - validate(autofocus) { - return new PropertyTypeFormControllerValidate(this).execute(autofocus) - } - - handleChange(type, params) { - return new PropertyTypeFormControllerChange(this).execute(type, params) - } - - handleSave() { - return new PropertyTypeFormControllerSave(this).execute() - } - - getDictionaries() { - const { dictionaries } = this.context.getState() - return dictionaries || {} - } -} diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerChange.js b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerChange.js deleted file mode 100644 index 9bbc80837d1..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerChange.js +++ /dev/null @@ -1,53 +0,0 @@ -import _ from 'lodash' -import PageControllerChange from '@src/js/components/common/page/PageControllerChange.js' -import FormUtil from '@src/js/components/common/form/FormUtil.js' -import openbis from '@src/js/services/openbis.js' - -export default class PropertyTypeFormControllerChange extends PageControllerChange { - async execute(type, params) { - await this.context.setState(oldState => { - const { oldObject, newObject } = FormUtil.changeObjectField( - oldState.propertyType, - params.field, - params.value - ) - - this._handleChangePropertyDataType(oldObject, newObject) - - return { - propertyType: newObject - } - }) - await this.controller.changed(true) - } - - _handleChangePropertyDataType(oldProperty, newProperty) { - const oldDataType = oldProperty.dataType.value - const newDataType = newProperty.dataType.value - - if (oldDataType !== newDataType) { - _.assign(newProperty, { - vocabulary: { - ...newProperty.vocabulary, - visible: newDataType === openbis.DataType.CONTROLLEDVOCABULARY - }, - materialType: { - ...newProperty.materialType, - visible: newDataType === openbis.DataType.MATERIAL - }, - sampleType: { - ...newProperty.sampleType, - visible: newDataType === openbis.DataType.SAMPLE - }, - schema: { - ...newProperty.schema, - visible: newDataType === openbis.DataType.XML - }, - transformation: { - ...newProperty.transformation, - visible: newDataType === openbis.DataType.XML - } - }) - } - } -} diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerLoad.js b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerLoad.js deleted file mode 100644 index 8c1226a4290..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerLoad.js +++ /dev/null @@ -1,118 +0,0 @@ -import _ from 'lodash' -import PageControllerLoad from '@src/js/components/common/page/PageControllerLoad.js' -import FormUtil from '@src/js/components/common/form/FormUtil.js' -import users from '@src/js/common/consts/users.js' -import openbis from '@src/js/services/openbis.js' - -export default class PropertyTypeFormControllerLoad extends PageControllerLoad { - async load(object, isNew) { - return Promise.all([ - this._loadDictionaries(), - this._loadPropertyType(object, isNew) - ]) - } - - async _loadDictionaries() { - const [vocabularies, materialTypes, sampleTypes] = await Promise.all([ - this.facade.loadVocabularies(), - this.facade.loadMaterialTypes(), - this.facade.loadSampleTypes() - ]) - - await this.context.setState(() => ({ - dictionaries: { - vocabularies, - materialTypes, - sampleTypes - } - })) - } - - async _loadPropertyType(object, isNew) { - let loadedPropertyType = null - - if (!isNew) { - loadedPropertyType = await this.facade.loadPropertyType(object.id) - if (!loadedPropertyType) { - return - } - } - - const propertyType = this._createPropertyType(loadedPropertyType) - - return this.context.setState({ - propertyType: propertyType, - original: { - propertyType: propertyType.original - } - }) - } - - _createPropertyType(loadedPropertyType) { - const internal = _.get(loadedPropertyType, 'managedInternally', false) - const dataType = _.get(loadedPropertyType, 'dataType', null) - - const propertyType = { - id: _.get(loadedPropertyType, 'code', null), - code: FormUtil.createField({ - value: _.get(loadedPropertyType, 'code', null), - enabled: loadedPropertyType === null - }), - label: FormUtil.createField({ - value: _.get(loadedPropertyType, 'label', null), - enabled: !internal || this.isSystemUser() - }), - description: FormUtil.createField({ - value: _.get(loadedPropertyType, 'description', null), - enabled: !internal || this.isSystemUser() - }), - dataType: FormUtil.createField({ - value: dataType, - enabled: !internal || this.isSystemUser() - }), - internal: FormUtil.createField({ - value: internal, - visible: this.isSystemUser(), - enabled: loadedPropertyType === null && this.isSystemUser() - }), - schema: FormUtil.createField({ - value: _.get(loadedPropertyType, 'schema', null), - visible: dataType === openbis.DataType.XML, - enabled: !internal || this.isSystemUser() - }), - transformation: FormUtil.createField({ - value: _.get(loadedPropertyType, 'transformation', null), - visible: dataType === openbis.DataType.XML, - enabled: !internal || this.isSystemUser() - }), - vocabulary: FormUtil.createField({ - value: _.get(loadedPropertyType, 'vocabulary.code', null), - visible: dataType === openbis.DataType.CONTROLLEDVOCABULARY, - enabled: loadedPropertyType === null - }), - materialType: FormUtil.createField({ - value: _.get(loadedPropertyType, 'materialType.code', null), - visible: dataType === openbis.DataType.MATERIAL, - enabled: loadedPropertyType === null - }), - sampleType: FormUtil.createField({ - value: _.get(loadedPropertyType, 'sampleType.code', null), - visible: dataType === openbis.DataType.SAMPLE, - enabled: loadedPropertyType === null - }) - } - - if (loadedPropertyType) { - propertyType.original = _.cloneDeep(propertyType) - } - - return propertyType - } - - isSystemUser() { - return ( - this.context.getProps().session && - this.context.getProps().session.userName === users.SYSTEM - ) - } -} diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerSave.js b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerSave.js deleted file mode 100644 index e7931f7dd28..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerSave.js +++ /dev/null @@ -1,87 +0,0 @@ -import PageControllerSave from '@src/js/components/common/page/PageControllerSave.js' -import FormUtil from '@src/js/components/common/form/FormUtil.js' -import openbis from '@src/js/services/openbis.js' - -export default class PropertyTypeFormControllerSave extends PageControllerSave { - async save() { - const state = this.context.getState() - const propertyType = this._preparePropertyType(state.propertyType) - const operations = [] - - if (propertyType.original) { - operations.push(this._updatePropertyTypeOperation(propertyType)) - } else { - operations.push(this._createPropertyTypeOperation(propertyType)) - } - - const options = new openbis.SynchronousOperationExecutionOptions() - options.setExecuteInOrder(true) - await this.facade.executeOperations(operations, options) - - return propertyType.code.value - } - - _preparePropertyType(propertyType) { - const code = propertyType.code.value - return FormUtil.trimFields({ - ...propertyType, - code: { - value: code ? code.toUpperCase() : null - } - }) - } - - _createPropertyTypeOperation(propertyType) { - const creation = new openbis.PropertyTypeCreation() - creation.setCode(propertyType.code.value) - creation.setManagedInternally(propertyType.internal.value) - creation.setLabel(propertyType.label.value) - creation.setDescription(propertyType.description.value) - creation.setDataType(propertyType.dataType.value) - creation.setSchema(propertyType.schema.value) - creation.setTransformation(propertyType.transformation.value) - - if ( - propertyType.dataType.value === openbis.DataType.CONTROLLEDVOCABULARY && - propertyType.vocabulary.value - ) { - creation.setVocabularyId( - new openbis.VocabularyPermId(propertyType.vocabulary.value) - ) - } - if ( - propertyType.dataType.value === openbis.DataType.MATERIAL && - propertyType.materialType.value - ) { - creation.setMaterialTypeId( - new openbis.EntityTypePermId( - propertyType.materialType.value, - openbis.EntityKind.MATERIAL - ) - ) - } - if ( - propertyType.dataType.value === openbis.DataType.SAMPLE && - propertyType.sampleType.value - ) { - creation.setSampleTypeId( - new openbis.EntityTypePermId( - propertyType.sampleType.value, - openbis.EntityKind.SAMPLE - ) - ) - } - return new openbis.CreatePropertyTypesOperation([creation]) - } - - _updatePropertyTypeOperation(propertyType) { - const update = new openbis.PropertyTypeUpdate() - update.setTypeId(new openbis.PropertyTypePermId(propertyType.code.value)) - update.setLabel(propertyType.label.value) - update.setDescription(propertyType.description.value) - update.setSchema(propertyType.schema.value) - update.setTransformation(propertyType.transformation.value) - update.convertToDataType(propertyType.dataType.value) - return new openbis.UpdatePropertyTypesOperation([update]) - } -} diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerValidate.js b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerValidate.js deleted file mode 100644 index 455fb46ac25..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormControllerValidate.js +++ /dev/null @@ -1,66 +0,0 @@ -import PageControllerValidate from '@src/js/components/common/page/PageConrollerValidate.js' -import messages from '@src/js/common/messages.js' - -export default class PropertyTypeFormControllerValidate extends PageControllerValidate { - validate(validator) { - const { propertyType } = this.context.getState() - - const newPropertyType = this._validatePropertyType(validator, propertyType) - - return { - propertyType: newPropertyType - } - } - - async select(firstError) { - await this.setSelection({ - params: { - part: firstError.name - } - }) - } - - _validatePropertyType(validator, propertyType) { - validator.validateNotEmpty( - propertyType, - 'code', - messages.get(messages.CODE) - ) - - if (propertyType.internal.value) { - validator.validateInternalCode( - propertyType, - 'code', - messages.get(messages.CODE) - ) - } else { - validator.validateCode(propertyType, 'code', messages.get(messages.CODE)) - } - - validator.validateNotEmpty( - propertyType, - 'label', - messages.get(messages.LABEL) - ) - validator.validateNotEmpty( - propertyType, - 'description', - messages.get(messages.DESCRIPTION) - ) - validator.validateNotEmpty( - propertyType, - 'dataType', - messages.get(messages.DATA_TYPE) - ) - - if (propertyType.vocabulary.visible) { - validator.validateNotEmpty( - propertyType, - 'vocabulary', - messages.get(messages.VOCABULARY_TYPE) - ) - } - - return validator.withErrors(propertyType) - } -} diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormFacade.js b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormFacade.js deleted file mode 100644 index 6d0d34b9cf4..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormFacade.js +++ /dev/null @@ -1,42 +0,0 @@ -import openbis from '@src/js/services/openbis.js' - -export default class PropertyTypeFormFacade { - async loadPropertyType(code) { - const id = new openbis.PropertyTypePermId(code) - const fo = new openbis.PropertyTypeFetchOptions() - fo.withVocabulary() - fo.withMaterialType() - fo.withSampleType() - return openbis.getPropertyTypes([id], fo).then(map => { - return map[code] - }) - } - - async loadVocabularies() { - let criteria = new openbis.VocabularySearchCriteria() - let fo = new openbis.VocabularyFetchOptions() - return openbis - .searchVocabularies(criteria, fo) - .then(result => result.objects) - } - - async loadMaterialTypes() { - let criteria = new openbis.MaterialTypeSearchCriteria() - let fo = new openbis.MaterialTypeFetchOptions() - return openbis - .searchMaterialTypes(criteria, fo) - .then(result => result.objects) - } - - async loadSampleTypes() { - let criteria = new openbis.SampleTypeSearchCriteria() - let fo = new openbis.SampleTypeFetchOptions() - return openbis - .searchSampleTypes(criteria, fo) - .then(result => result.objects) - } - - async executeOperations(operations, options) { - return openbis.executeOperations(operations, options) - } -} diff --git a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormParameters.jsx b/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormParameters.jsx deleted file mode 100644 index 890d046999f..00000000000 --- a/openbis_ng_ui/src/js/components/types/form/propertytype/PropertyTypeFormParameters.jsx +++ /dev/null @@ -1,538 +0,0 @@ -import _ from 'lodash' -import React from 'react' -import { connect } from 'react-redux' -import { withStyles } from '@material-ui/core/styles' -import Container from '@src/js/components/common/form/Container.jsx' -import Header from '@src/js/components/common/form/Header.jsx' -import TextField from '@src/js/components/common/form/TextField.jsx' -import CheckboxField from '@src/js/components/common/form/CheckboxField.jsx' -import SelectField from '@src/js/components/common/form/SelectField.jsx' -import Message from '@src/js/components/common/form/Message.jsx' -import DataType from '@src/js/components/common/dto/DataType.js' -import openbis from '@src/js/services/openbis.js' -import selectors from '@src/js/store/selectors/selectors.js' -import users from '@src/js/common/consts/users.js' -import messages from '@src/js/common/messages.js' -import logger from '@src/js/common/logger.js' -const styles = theme => ({ - field: { - paddingBottom: theme.spacing(1) - } -}) - -function mapStateToProps(state) { - return { - session: selectors.getSession(state) - } -} - -class PropertyTypeFormParameters extends React.PureComponent { - constructor(props) { - super(props) - this.state = {} - this.references = { - code: React.createRef(), - label: React.createRef(), - description: React.createRef(), - dataType: React.createRef(), - vocabulary: React.createRef(), - materialType: React.createRef(), - sampleType: React.createRef(), - schema: React.createRef(), - transformation: React.createRef(), - internal: React.createRef() - } - this.handleChange = this.handleChange.bind(this) - this.handleFocus = this.handleFocus.bind(this) - this.handleBlur = this.handleBlur.bind(this) - } - - componentDidMount() { - this.focus() - } - - componentDidUpdate(prevProps) { - const prevSelection = prevProps.selection - const selection = this.props.selection - - if (prevSelection !== selection) { - this.focus() - } - } - - focus() { - if (this.props.selection) { - const { part } = this.props.selection.params - if (part) { - const reference = this.references[part] - if (reference && reference.current) { - reference.current.focus() - } - } - } - } - - handleChange(event) { - this.props.onChange(null, { - field: event.target.name, - value: event.target.value - }) - } - - handleFocus(event) { - this.props.onSelectionChange(null, { - part: event.target.name - }) - } - - handleBlur() { - this.props.onBlur() - } - - render() { - logger.log(logger.DEBUG, 'PropertyTypeFormParameters.render') - - return ( - <Container> - {this.renderHeader()} - {this.renderMessageInternal()} - {this.renderCode()} - {this.renderDataType()} - {this.renderVocabulary()} - {this.renderMaterialType()} - {this.renderSampleType()} - {this.renderSchema()} - {this.renderTransformation()} - {this.renderLabel()} - {this.renderDescription()} - {this.renderInternal()} - </Container> - ) - } - - renderHeader() { - const { propertyType } = this.props - const message = propertyType.original - ? messages.PROPERTY_TYPE - : messages.NEW_PROPERTY_TYPE - return <Header>{messages.get(message)}</Header> - } - - renderMessageInternal() { - const { propertyType } = this.props - - if (propertyType.internal.value) { - const { classes, session } = this.props - - if (session && session.userName === users.SYSTEM) { - return ( - <div className={classes.field}> - <Message type='lock'> - {messages.get(messages.PROPERTY_IS_INTERNAL)} - </Message> - </div> - ) - } else { - return ( - <div className={classes.field}> - <Message type='lock'> - {messages.get(messages.PROPERTY_IS_INTERNAL)} - {propertyType.internal.value - ? ' ' + - messages.get(messages.PROPERTY_PARAMETERS_CANNOT_BE_CHANGED) - : ''} - </Message> - </div> - ) - } - } else { - return null - } - } - - renderCode() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.code } - - if (!visible) { - return null - } - - const { mode, classes } = this.props - return ( - <div className={classes.field}> - <TextField - reference={this.references.code} - label={messages.get(messages.CODE)} - name='code' - mandatory={true} - error={error} - disabled={!enabled} - value={value} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderDataType() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { - ...propertyType.dataType - } - - if (!visible) { - return null - } - - const options = [] - - if (propertyType.original) { - const { - dataType: { value: originalValue } - } = propertyType.original - - const SUFFIX = ' (' + messages.get(messages.CONVERTED) + ')' - options.push({ - label: new DataType(originalValue).getLabel(), - value: originalValue - }) - if (originalValue !== openbis.DataType.VARCHAR) { - options.push({ - label: new DataType(openbis.DataType.VARCHAR).getLabel() + SUFFIX, - value: openbis.DataType.VARCHAR - }) - } - if (originalValue !== openbis.DataType.MULTILINE_VARCHAR) { - options.push({ - label: - new DataType(openbis.DataType.MULTILINE_VARCHAR).getLabel() + - SUFFIX, - value: openbis.DataType.MULTILINE_VARCHAR - }) - } - if (originalValue === openbis.DataType.TIMESTAMP) { - options.push({ - label: new DataType(openbis.DataType.DATE).getLabel() + SUFFIX, - value: openbis.DataType.DATE - }) - } - if (originalValue === openbis.DataType.INTEGER) { - options.push({ - label: new DataType(openbis.DataType.REAL).getLabel() + SUFFIX, - value: openbis.DataType.REAL - }) - } - } else { - openbis.DataType.values.map(dataType => { - options.push({ - label: new DataType(dataType).getLabel(), - value: dataType - }) - }) - } - - const { mode, classes } = this.props - return ( - <div className={classes.field}> - <SelectField - reference={this.references.dataType} - label={messages.get(messages.DATA_TYPE)} - name='dataType' - mandatory={true} - error={error} - disabled={!enabled} - value={value} - options={options} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderVocabulary() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.vocabulary } - - if (!visible) { - return null - } - - const { mode, classes, controller } = this.props - const { vocabularies } = controller.getDictionaries() - - let options = [] - - if (vocabularies) { - options = vocabularies.map(vocabulary => { - return { - label: vocabulary.code, - value: vocabulary.code - } - }) - } - - return ( - <div className={classes.field}> - <SelectField - reference={this.references.vocabulary} - label={messages.get(messages.VOCABULARY_TYPE)} - name='vocabulary' - mandatory={true} - error={error} - disabled={!enabled} - value={value} - options={options} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderMaterialType() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.materialType } - - if (!visible) { - return null - } - - const { mode, classes, controller } = this.props - const { materialTypes } = controller.getDictionaries() - - let options = [] - - if (materialTypes) { - options = materialTypes.map(materialType => { - return { - label: materialType.code, - value: materialType.code - } - }) - } - - return ( - <div className={classes.field}> - <SelectField - reference={this.references.materialType} - label={messages.get(messages.MATERIAL_TYPE)} - name='materialType' - error={error} - disabled={!enabled} - value={value} - options={options} - emptyOption={{ - label: '(' + messages.get(messages.ALL) + ')', - selectable: true - }} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderSampleType() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.sampleType } - - if (!visible) { - return null - } - - const { mode, classes, controller } = this.props - const { sampleTypes } = controller.getDictionaries() - - let options = [] - - if (sampleTypes) { - options = sampleTypes.map(sampleType => { - return { - label: sampleType.code, - value: sampleType.code - } - }) - } - - return ( - <div className={classes.field}> - <SelectField - reference={this.references.sampleType} - label={messages.get(messages.OBJECT_TYPE)} - name='sampleType' - error={error} - disabled={!enabled} - value={value} - options={options} - emptyOption={{ - label: '(' + messages.get(messages.ALL) + ')', - selectable: true - }} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderSchema() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.schema } - - if (!visible) { - return null - } - - const { mode, classes } = this.props - - return ( - <div className={classes.field}> - <TextField - reference={this.references.schema} - label={messages.get(messages.XML_SCHEMA)} - name='schema' - error={error} - disabled={!enabled} - value={value} - multiline={true} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderTransformation() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { - ...propertyType.transformation - } - - if (!visible) { - return null - } - - const { mode, classes } = this.props - - return ( - <div className={classes.field}> - <TextField - reference={this.references.transformation} - label={messages.get(messages.XSLT_SCRIPT)} - name='transformation' - error={error} - disabled={!enabled} - value={value} - multiline={true} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderLabel() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.label } - - if (!visible) { - return null - } - - const { mode, classes } = this.props - return ( - <div className={classes.field}> - <TextField - reference={this.references.label} - label={messages.get(messages.LABEL)} - name='label' - mandatory={true} - error={error} - disabled={!enabled} - value={value} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderDescription() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.description } - - if (!visible) { - return null - } - - const { mode, classes } = this.props - return ( - <div className={classes.field}> - <TextField - reference={this.references.description} - label={messages.get(messages.DESCRIPTION)} - name='description' - mandatory={true} - error={error} - disabled={!enabled} - value={value} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } - - renderInternal() { - const { propertyType } = this.props - const { visible, enabled, error, value } = { ...propertyType.internal } - - if (!visible) { - return null - } - - const { mode, classes } = this.props - return ( - <div className={classes.field}> - <CheckboxField - reference={this.references.internal} - label={messages.get(messages.INTERNAL)} - name='internal' - error={error} - disabled={!enabled} - value={value} - mode={mode} - onChange={this.handleChange} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - /> - </div> - ) - } -} - -export default _.flow( - connect(mapStateToProps), - withStyles(styles) -)(PropertyTypeFormParameters) diff --git a/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js b/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js index b480cda823b..c03cd6cc01f 100644 --- a/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js +++ b/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js @@ -14,7 +14,7 @@ describe(AppComponentTest.SUITE, () => { async function testLogin() { const app = await common.mount() - app.expectJSON({ + await app.expectJSON({ login: { user: { value: null, @@ -35,7 +35,7 @@ async function testLogin() { await common.login(app) - app.expectJSON({ + await app.expectJSON({ login: null, menu: { tabs: [ @@ -63,7 +63,8 @@ async function testLogin() { { level: 0, text: 'Collection Types' }, { level: 0, text: 'Data Set Types' }, { level: 0, text: 'Material Types' }, - { level: 0, text: 'Vocabulary Types' } + { level: 0, text: 'Vocabulary Types' }, + { level: 0, text: 'Property Types' } ] }, content: { diff --git a/openbis_ng_ui/srcTest/js/components/tools/browser/ToolBrowserComponentFilter.test.js b/openbis_ng_ui/srcTest/js/components/tools/browser/ToolBrowserComponentFilter.test.js index f65073d1d49..f9b6656dfff 100644 --- a/openbis_ng_ui/srcTest/js/components/tools/browser/ToolBrowserComponentFilter.test.js +++ b/openbis_ng_ui/srcTest/js/components/tools/browser/ToolBrowserComponentFilter.test.js @@ -1,6 +1,5 @@ import ToolBrowserComponentTest from '@srcTest/js/components/tools/browser/ToolBrowserComponentTest.js' import ToolBrowserTestData from '@srcTest/js/components/tools/browser/ToolBrowserTestData.js' -import ImportType from '@src/js/components/tools/form/import/ImportType.js' import openbis from '@srcTest/js/services/openbis.js' let common = null diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js index d492b88bc3b..ebdef9e6caf 100644 --- a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js @@ -52,7 +52,8 @@ async function testFilter() { { level: 1, text: fixture.TEST_MATERIAL_TYPE_DTO.code }, { level: 0, text: 'Vocabulary Types' }, { level: 1, text: fixture.ANOTHER_VOCABULARY_DTO.code }, - { level: 1, text: fixture.TEST_VOCABULARY_DTO.code } + { level: 1, text: fixture.TEST_VOCABULARY_DTO.code }, + { level: 0, text: 'Property Types' } ] }) } -- GitLab