diff --git a/openbis_ng_ui/src/js/common/consts/ids.js b/openbis_ng_ui/src/js/common/consts/ids.js index c374f4f1db3625bb498f5d4c19736c8244825a30..09ca5e052aa25b03b70497c518168e3bfa2da540 100644 --- a/openbis_ng_ui/src/js/common/consts/ids.js +++ b/openbis_ng_ui/src/js/common/consts/ids.js @@ -7,6 +7,8 @@ const USER_ROLES_GRID_ID = 'user_roles_grid' const USER_GROUP_USERS_GRID_ID = 'user_group_users_grid' const USER_GROUP_ROLES_GRID_ID = 'user_group_roles_grid' const VOCABULARY_TERMS_GRID_ID = 'vocabulary_terms_grid' +const PLUGINS_GRID_ID = 'plugins_grid' +const QUERIES_GRID_ID = 'queries_grid' export default { WEB_APP_ID, @@ -17,5 +19,7 @@ export default { USER_ROLES_GRID_ID, USER_GROUP_USERS_GRID_ID, USER_GROUP_ROLES_GRID_ID, - VOCABULARY_TERMS_GRID_ID + VOCABULARY_TERMS_GRID_ID, + PLUGINS_GRID_ID, + QUERIES_GRID_ID } diff --git a/openbis_ng_ui/src/js/components/common/link/PluginLink.jsx b/openbis_ng_ui/src/js/components/common/link/PluginLink.jsx new file mode 100644 index 0000000000000000000000000000000000000000..f578e7645bac9e8089a3f440301816d5f18bb339 --- /dev/null +++ b/openbis_ng_ui/src/js/components/common/link/PluginLink.jsx @@ -0,0 +1,42 @@ +import React from 'react' +import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' +import pages from '@src/js/common/consts/pages.js' +import objectTypes from '@src/js/common/consts/objectType.js' +import openbis from '@src/js/services/openbis.js' +import logger from '@src/js/common/logger.js' + +class PluginLink extends React.PureComponent { + render() { + logger.log(logger.DEBUG, 'PluginLink.render') + + const { pluginName, pluginType } = this.props + + if (pluginName && pluginType) { + let objectType = null + + if (pluginType === openbis.PluginType.DYNAMIC_PROPERTY) { + objectType = objectTypes.DYNAMIC_PROPERTY_PLUGIN + } else if (pluginType === openbis.PluginType.ENTITY_VALIDATION) { + objectType = objectTypes.ENTITY_VALIDATION_PLUGIN + } else { + throw new Error('Unsupported plugin type: ' + pluginType) + } + + return ( + <LinkToObject + page={pages.TOOLS} + object={{ + type: objectType, + id: pluginName + }} + > + {pluginName} + </LinkToObject> + ) + } else { + return null + } + } +} + +export default PluginLink diff --git a/openbis_ng_ui/src/js/components/common/link/QueryLink.jsx b/openbis_ng_ui/src/js/components/common/link/QueryLink.jsx new file mode 100644 index 0000000000000000000000000000000000000000..f503cd6081ccb4ba0b2deab94b37c508c118e197 --- /dev/null +++ b/openbis_ng_ui/src/js/components/common/link/QueryLink.jsx @@ -0,0 +1,31 @@ +import React from 'react' +import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' +import pages from '@src/js/common/consts/pages.js' +import objectTypes from '@src/js/common/consts/objectType.js' +import logger from '@src/js/common/logger.js' + +class QueryLink extends React.PureComponent { + render() { + logger.log(logger.DEBUG, 'QueryLink.render') + + const { queryName } = this.props + + if (queryName) { + return ( + <LinkToObject + page={pages.TOOLS} + object={{ + type: objectTypes.QUERY, + id: queryName + }} + > + {queryName} + </LinkToObject> + ) + } else { + return null + } + } +} + +export default QueryLink diff --git a/openbis_ng_ui/src/js/components/common/link/UserGroupLink.jsx b/openbis_ng_ui/src/js/components/common/link/UserGroupLink.jsx new file mode 100644 index 0000000000000000000000000000000000000000..c12d3ad6fcbcc20135a4e3a9ddec5004a8f2e897 --- /dev/null +++ b/openbis_ng_ui/src/js/components/common/link/UserGroupLink.jsx @@ -0,0 +1,31 @@ +import React from 'react' +import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' +import pages from '@src/js/common/consts/pages.js' +import objectTypes from '@src/js/common/consts/objectType.js' +import logger from '@src/js/common/logger.js' + +class UserGroupLink extends React.PureComponent { + render() { + logger.log(logger.DEBUG, 'UserGroupLink.render') + + const { groupCode } = this.props + + if (groupCode) { + return ( + <LinkToObject + page={pages.USERS} + object={{ + type: objectTypes.USER_GROUP, + id: groupCode + }} + > + {groupCode} + </LinkToObject> + ) + } else { + return null + } + } +} + +export default UserGroupLink diff --git a/openbis_ng_ui/src/js/components/common/link/UserLink.jsx b/openbis_ng_ui/src/js/components/common/link/UserLink.jsx new file mode 100644 index 0000000000000000000000000000000000000000..671e2130c6b854a64cc6df18bebf0c0b2c76915f --- /dev/null +++ b/openbis_ng_ui/src/js/components/common/link/UserLink.jsx @@ -0,0 +1,31 @@ +import React from 'react' +import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' +import pages from '@src/js/common/consts/pages.js' +import objectTypes from '@src/js/common/consts/objectType.js' +import logger from '@src/js/common/logger.js' + +class UserLink extends React.PureComponent { + render() { + logger.log(logger.DEBUG, 'UserLink.render') + + const { userId } = this.props + + if (userId) { + return ( + <LinkToObject + page={pages.USERS} + object={{ + type: objectTypes.USER, + id: userId + }} + > + {userId} + </LinkToObject> + ) + } else { + return null + } + } +} + +export default UserLink diff --git a/openbis_ng_ui/src/js/components/tools/common/PluginsGrid.jsx b/openbis_ng_ui/src/js/components/tools/common/PluginsGrid.jsx new file mode 100644 index 0000000000000000000000000000000000000000..5ad39f722a5fa6f8589e492da998c0b35fe41b7b --- /dev/null +++ b/openbis_ng_ui/src/js/components/tools/common/PluginsGrid.jsx @@ -0,0 +1,86 @@ +import _ from 'lodash' +import React from 'react' +import autoBind from 'auto-bind' +import { withStyles } from '@material-ui/core/styles' +import Grid from '@src/js/components/common/grid/Grid.jsx' +import PluginLink from '@src/js/components/common/link/PluginLink.jsx' +import UserLink from '@src/js/components/common/link/UserLink.jsx' +import logger from '@src/js/common/logger.js' + +const styles = () => ({}) + +class PluginsGrid extends React.PureComponent { + constructor(props) { + super(props) + autoBind(this) + } + + render() { + logger.log(logger.DEBUG, 'PluginsGrid.render') + + const { + id, + rows, + selectedRowId, + onSelectedRowChange, + controllerRef + } = this.props + + return ( + <Grid + id={id} + controllerRef={controllerRef} + header='Plugins' + columns={[ + { + name: 'name', + label: 'Name', + sort: 'asc', + getValue: ({ row }) => row.name.value, + renderValue: ({ row }) => { + return ( + <PluginLink + pluginName={row.name.value} + pluginType={row.pluginType.value} + /> + ) + } + }, + { + name: 'description', + label: 'Description', + getValue: ({ row }) => row.description.value + }, + { + name: 'pluginType', + label: 'Plugin Type', + getValue: ({ row }) => row.pluginType.value + }, + { + name: 'pluginKind', + label: 'Plugin Kind', + getValue: ({ row }) => row.pluginKind.value + }, + { + name: 'entityKind', + label: 'Entity Kind', + getValue: ({ row }) => row.entityKind.value + }, + { + name: 'registrator', + label: 'Registrator', + getValue: ({ row }) => row.registrator.value, + renderValue: ({ value }) => { + return <UserLink userId={value} /> + } + } + ]} + rows={rows} + selectedRowId={selectedRowId} + onSelectedRowChange={onSelectedRowChange} + /> + ) + } +} + +export default _.flow(withStyles(styles))(PluginsGrid) diff --git a/openbis_ng_ui/src/js/components/tools/common/QueriesGrid.jsx b/openbis_ng_ui/src/js/components/tools/common/QueriesGrid.jsx new file mode 100644 index 0000000000000000000000000000000000000000..876c6236ba3ae089896a1519fb36a6adadfad5de --- /dev/null +++ b/openbis_ng_ui/src/js/components/tools/common/QueriesGrid.jsx @@ -0,0 +1,86 @@ +import _ from 'lodash' +import React from 'react' +import autoBind from 'auto-bind' +import { withStyles } from '@material-ui/core/styles' +import Grid from '@src/js/components/common/grid/Grid.jsx' +import QueryLink from '@src/js/components/common/link/QueryLink.jsx' +import UserLink from '@src/js/components/common/link/UserLink.jsx' +import logger from '@src/js/common/logger.js' + +const styles = () => ({}) + +class QueriesGrid extends React.PureComponent { + constructor(props) { + super(props) + autoBind(this) + } + + render() { + logger.log(logger.DEBUG, 'QueriesGrid.render') + + const { + id, + rows, + selectedRowId, + onSelectedRowChange, + controllerRef + } = this.props + + return ( + <Grid + id={id} + controllerRef={controllerRef} + header='Queries' + columns={[ + { + name: 'name', + label: 'Name', + sort: 'asc', + getValue: ({ row }) => row.name.value, + renderValue: ({ value }) => { + return <QueryLink queryName={value} /> + } + }, + { + name: 'description', + label: 'Description', + getValue: ({ row }) => row.description.value + }, + { + name: 'database', + label: 'Database', + getValue: ({ row }) => row.database.value + }, + { + name: 'queryType', + label: 'Query Type', + getValue: ({ row }) => row.queryType.value + }, + { + name: 'entityTypeCodePattern', + label: 'Entity Type Pattern', + getValue: ({ row }) => row.entityTypeCodePattern.value + }, + { + name: 'publicFlag', + label: 'Public', + getValue: ({ row }) => row.publicFlag.value + }, + { + name: 'registrator', + label: 'Registrator', + getValue: ({ row }) => row.registrator.value, + renderValue: ({ value }) => { + return <UserLink userId={value} /> + } + } + ]} + rows={rows} + selectedRowId={selectedRowId} + onSelectedRowChange={onSelectedRowChange} + /> + ) + } +} + +export default _.flow(withStyles(styles))(QueriesGrid) diff --git a/openbis_ng_ui/src/js/components/tools/search/ToolSearch.jsx b/openbis_ng_ui/src/js/components/tools/search/ToolSearch.jsx index b3bb7f3e0e02b5bbfa4a068c784833f45da4915f..e70696207d96f4417fe1ea6ea6c5b5a1d01756df 100644 --- a/openbis_ng_ui/src/js/components/tools/search/ToolSearch.jsx +++ b/openbis_ng_ui/src/js/components/tools/search/ToolSearch.jsx @@ -1,9 +1,182 @@ +import _ from 'lodash' +import autoBind from 'auto-bind' import React from 'react' +import GridContainer from '@src/js/components/common/grid/GridContainer.jsx' +import PluginsGrid from '@src/js/components/tools/common/PluginsGrid.jsx' +import QueriesGrid from '@src/js/components/tools/common/QueriesGrid.jsx' +import FormUtil from '@src/js/components/common/form/FormUtil.js' +import ids from '@src/js/common/consts/ids.js' +import store from '@src/js/store/store.js' +import actions from '@src/js/store/actions/actions.js' +import openbis from '@src/js/services/openbis.js' import logger from '@src/js/common/logger.js' -export default class ToolSearch extends React.Component { +class ToolSearch extends React.Component { + constructor(props) { + super(props) + autoBind(this) + + this.state = { + loaded: false, + selection: null + } + } + + componentDidMount() { + Promise.all([this.loadPlugins(), this.loadQueries()]) + .then(([plugins, queries]) => { + this.setState(() => ({ + loaded: true, + plugins, + queries + })) + }) + .catch(error => { + store.dispatch(actions.errorChange(error)) + }) + } + + loadPlugins() { + let query = this.props.objectId + + let criteria = new openbis.PluginSearchCriteria() + criteria.withName().thatContains(query) + + let fo = new openbis.PluginFetchOptions() + fo.withScript() + fo.withRegistrator() + + return openbis.searchPlugins(criteria, fo).then(result => { + return result.objects + .filter(plugin => { + return ( + plugin.pluginType === openbis.PluginType.DYNAMIC_PROPERTY || + plugin.pluginType === openbis.PluginType.ENTITY_VALIDATION + ) + }) + .map(plugin => { + const entityKinds = _.get(plugin, 'entityKinds', []) + + return { + id: _.get(plugin, 'name'), + name: FormUtil.createField({ value: _.get(plugin, 'name') }), + description: FormUtil.createField({ + value: _.get(plugin, 'description') + }), + pluginType: FormUtil.createField({ + value: _.get(plugin, 'pluginType') + }), + pluginKind: FormUtil.createField({ + value: _.get(plugin, 'pluginKind') + }), + entityKind: FormUtil.createField({ + value: entityKinds.length === 1 ? entityKinds[0] : null + }), + script: FormUtil.createField({ value: _.get(plugin, 'script') }), + registrator: FormUtil.createField({ + value: _.get(plugin, 'registrator.userId') + }) + } + }) + }) + } + + loadQueries() { + let query = this.props.objectId + + let criteria = new openbis.QuerySearchCriteria() + criteria.withName().thatContains(query) + + let fo = new openbis.QueryFetchOptions() + fo.withRegistrator() + + return openbis.searchQueries(criteria, fo).then(result => { + return result.objects.map(query => ({ + id: _.get(query, 'name'), + name: FormUtil.createField({ value: _.get(query, 'name') }), + description: FormUtil.createField({ + value: _.get(query, 'description') + }), + database: FormUtil.createField({ + value: _.get(query, 'databaseLabel') + }), + queryType: FormUtil.createField({ + value: _.get(query, 'queryType') + }), + entityTypeCodePattern: FormUtil.createField({ + value: _.get(query, 'entityTypeCodePattern') + }), + sql: FormUtil.createField({ + value: _.get(query, 'sql') + }), + publicFlag: FormUtil.createField({ + value: _.get(query, 'publicFlag') + }), + registrator: FormUtil.createField({ + value: _.get(query, 'registrator.userId') + }) + })) + }) + } + + handleClickContainer() { + this.setState({ + selection: null + }) + } + + handleSelectedPluginRowChange(row) { + if (row) { + this.setState({ + selection: { + type: 'plugin', + id: row.id + } + }) + } + } + + handleSelectedQueryRowChange(row) { + if (row) { + this.setState({ + selection: { + type: 'query', + id: row.id + } + }) + } + } + render() { logger.log(logger.DEBUG, 'ToolSearch.render') - return 'ToolSearch' + + if (!this.state.loaded) { + return null + } + + const { selection } = this.state + + return ( + <GridContainer onClick={this.handleClickContainer}> + <PluginsGrid + id={ids.PLUGINS_GRID_ID} + rows={this.state.plugins} + onSelectedRowChange={this.handleSelectedPluginRowChange} + selectedRowId={ + selection && selection.type === 'plugin' ? selection.id : null + } + /> + <QueriesGrid + id={ids.QUERIES_GRID_ID} + rows={this.state.queries} + onSelectedRowChange={this.handleSelectedQueryRowChange} + selectedRowId={ + selection && selection.type === 'query' ? selection.id : null + } + /> + </GridContainer> + ) } } + +export default ToolSearch diff --git a/openbis_ng_ui/src/js/components/users/common/RolesGrid.jsx b/openbis_ng_ui/src/js/components/users/common/RolesGrid.jsx index adea59c6accdc0eb828ac8fc04e7fe4fc9886314..da74beb3844426fec4dadef0781cbe1836f47d73 100644 --- a/openbis_ng_ui/src/js/components/users/common/RolesGrid.jsx +++ b/openbis_ng_ui/src/js/components/users/common/RolesGrid.jsx @@ -3,10 +3,8 @@ import React from 'react' import autoBind from 'auto-bind' import { withStyles } from '@material-ui/core/styles' import Grid from '@src/js/components/common/grid/Grid.jsx' -import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' +import UserGroupLink from '@src/js/components/common/link/UserGroupLink.jsx' import openbis from '@src/js/services/openbis.js' -import pages from '@src/js/common/consts/pages.js' -import objectTypes from '@src/js/common/consts/objectType.js' import ids from '@src/js/common/consts/ids.js' import logger from '@src/js/common/logger.js' @@ -175,25 +173,8 @@ class RolesGrid extends React.PureComponent { return row.role.value } - renderInheritedFromValue({ value, row }) { - if (value) { - return this.renderDefault({ - value: ( - <LinkToObject - page={pages.USERS} - object={{ - type: objectTypes.USER_GROUP, - id: row.inheritedFrom.value - }} - > - {row.inheritedFrom.value} - </LinkToObject> - ), - row - }) - } else { - return null - } + renderInheritedFromValue({ value }) { + return <UserGroupLink groupCode={value} /> } renderLevelValue({ value, row }) { diff --git a/openbis_ng_ui/src/js/components/users/common/GroupsGrid.jsx b/openbis_ng_ui/src/js/components/users/common/UserGroupsGrid.jsx similarity index 61% rename from openbis_ng_ui/src/js/components/users/common/GroupsGrid.jsx rename to openbis_ng_ui/src/js/components/users/common/UserGroupsGrid.jsx index 8de99df3f26745990f0f310bc7d38da5de014c13..f84e3f85a3a2f5d012b306adfba5ff2fa22468a7 100644 --- a/openbis_ng_ui/src/js/components/users/common/GroupsGrid.jsx +++ b/openbis_ng_ui/src/js/components/users/common/UserGroupsGrid.jsx @@ -1,8 +1,6 @@ import React from 'react' import Grid from '@src/js/components/common/grid/Grid.jsx' -import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' -import pages from '@src/js/common/consts/pages.js' -import objectTypes from '@src/js/common/consts/objectType.js' +import UserGroupLink from '@src/js/components/common/link/UserGroupLink.jsx' import logger from '@src/js/common/logger.js' export default class GroupsGrid extends React.PureComponent { @@ -29,21 +27,7 @@ export default class GroupsGrid extends React.PureComponent { sort: 'asc', getValue: ({ row }) => row.code.value, renderValue: ({ value }) => { - if (value) { - return ( - <LinkToObject - page={pages.USERS} - object={{ - type: objectTypes.USER_GROUP, - id: value - }} - > - {value} - </LinkToObject> - ) - } else { - return '' - } + return <UserGroupLink groupCode={value} /> } }, { diff --git a/openbis_ng_ui/src/js/components/users/common/UsersGrid.jsx b/openbis_ng_ui/src/js/components/users/common/UsersGrid.jsx index 24492c79af4bd32d8022e0210149c886ada803b7..a103f250610e8725bf2c92b36409abd23cdd94f7 100644 --- a/openbis_ng_ui/src/js/components/users/common/UsersGrid.jsx +++ b/openbis_ng_ui/src/js/components/users/common/UsersGrid.jsx @@ -3,9 +3,7 @@ import React from 'react' import autoBind from 'auto-bind' import { withStyles } from '@material-ui/core/styles' import Grid from '@src/js/components/common/grid/Grid.jsx' -import LinkToObject from '@src/js/components/common/form/LinkToObject.jsx' -import pages from '@src/js/common/consts/pages.js' -import objectTypes from '@src/js/common/consts/objectType.js' +import UserLink from '@src/js/components/common/link/UserLink.jsx' import logger from '@src/js/common/logger.js' const styles = () => ({}) @@ -39,21 +37,7 @@ class UsersGrid extends React.PureComponent { sort: 'asc', getValue: ({ row }) => row.userId.value, renderValue: ({ value }) => { - if (value) { - return ( - <LinkToObject - page={pages.USERS} - object={{ - type: objectTypes.USER, - id: value - }} - > - {value} - </LinkToObject> - ) - } else { - return '' - } + return <UserLink userId={value} /> } }, { diff --git a/openbis_ng_ui/src/js/components/users/form/UserFormGridGroups.jsx b/openbis_ng_ui/src/js/components/users/form/UserFormGridGroups.jsx index 323767eafdf04c8aacba20af39c1b2a6594ffe59..5d666968c9d37ad83a51d92b0469562692ea248d 100644 --- a/openbis_ng_ui/src/js/components/users/form/UserFormGridGroups.jsx +++ b/openbis_ng_ui/src/js/components/users/form/UserFormGridGroups.jsx @@ -1,5 +1,5 @@ import React from 'react' -import GroupsGrid from '@src/js/components/users/common/GroupsGrid.jsx' +import UserGroupsGrid from '@src/js/components/users/common/UserGroupsGrid.jsx' import ids from '@src/js/common/consts/ids.js' import logger from '@src/js/common/logger.js' @@ -7,6 +7,6 @@ export default class UserFormGridGroups extends React.PureComponent { render() { logger.log(logger.DEBUG, 'UserFormGridGroups.render') - return <GroupsGrid {...this.props} id={ids.USER_USER_GROUPS_GRID_ID} /> + return <UserGroupsGrid {...this.props} id={ids.USER_USER_GROUPS_GRID_ID} /> } } diff --git a/openbis_ng_ui/src/js/components/users/search/UserSearch.jsx b/openbis_ng_ui/src/js/components/users/search/UserSearch.jsx index 11a55d0a7fcc199917d82f60ed23cd9b0e416439..b50048eb9610bbe941b36bbe5830901dc6b43524 100644 --- a/openbis_ng_ui/src/js/components/users/search/UserSearch.jsx +++ b/openbis_ng_ui/src/js/components/users/search/UserSearch.jsx @@ -3,7 +3,7 @@ import autoBind from 'auto-bind' import React from 'react' import GridContainer from '@src/js/components/common/grid/GridContainer.jsx' import UsersGrid from '@src/js/components/users/common/UsersGrid.jsx' -import GroupsGrid from '@src/js/components/users/common/GroupsGrid.jsx' +import UserGroupsGrid from '@src/js/components/users/common/UserGroupsGrid.jsx' import FormUtil from '@src/js/components/common/form/FormUtil.js' import ids from '@src/js/common/consts/ids.js' import store from '@src/js/store/store.js' @@ -135,7 +135,7 @@ class UserSearch extends React.Component { selection && selection.type === 'user' ? selection.id : null } /> - <GroupsGrid + <UserGroupsGrid id={ids.USER_GROUPS_GRID_ID} rows={this.state.groups} onSelectedRowChange={this.handleSelectedGroupRowChange}