Skip to content

Commit

Permalink
feat: labimotion-2.0.0 (#2261)
Browse files Browse the repository at this point in the history
 update labimotion to v2-rc:

- chore:  updated react-boostrap 
- feat: LabIMotion Vocabulary (Lab-Vocab)
- feat: Generic Layers: reuse set of fields across multiple templates. 

see   LabIMotion/labimotion#37 for the features

Code changes: 

* db migration for lab-vocab and generic layer
* ELN generic react-components update and linting
* unified labimotion api namespace
* dependencies updates:

  -- Bumps [Labimotion](https://github.com/labimotion/labimotion) from 1.4.1 to 2.0.0.rc2
LabIMotion/labimotion@v1.4.1...2.0.0.rc2
https://my.diffend.io/gems/labimotion/1.4.1/2.0.0.rc2


  -- Bumps [chem-generic-ui](https://github.com/LabIMotion/chem-generic-ui/) from 1.4.9 to 2.0.0-rc15
LabIMotion/chem-generic-ui@v1.4.9...v2.0.0-rc15
https://www.npmjs.com/package/chem-generic-ui/v/2.0.0-rc15
  • Loading branch information
phuang26 authored Jan 10, 2025
1 parent a38a5b0 commit 80bc4eb
Show file tree
Hide file tree
Showing 34 changed files with 1,499 additions and 1,254 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ gem 'kaminari-grape'
# gem 'ketcherails', git: 'https://github.com/complat/ketcher-rails.git', branch: 'upgrade-to-rails-6'
gem 'ketcherails', git: 'https://github.com/complat/ketcher-rails.git', ref: 'd4ae864a0e2d9e853eac8e4fc4ce7e3ab8174f80'

gem 'labimotion', '1.4.1'
gem 'labimotion', '2.0.0.rc2'

gem 'mimemagic', '0.3.10'
gem 'mime-types'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ GEM
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
labimotion (1.4.1)
labimotion (2.0.0.rc2)
rails (~> 6.1.7)
language_server-protocol (3.17.0.3)
latex-decode (0.4.0)
Expand Down Expand Up @@ -909,7 +909,7 @@ DEPENDENCIES
kaminari
kaminari-grape
ketcherails!
labimotion (= 1.4.1)
labimotion (= 2.0.0.rc2)
launchy
listen
memory_profiler
Expand Down
7 changes: 1 addition & 6 deletions app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@ def to_json_camel_case(val)
mount Chemotion::CalendarEntryAPI
mount Chemotion::CommentAPI
mount Chemotion::CellLineAPI
mount Labimotion::ConverterAPI
mount Labimotion::GenericKlassAPI
mount Labimotion::GenericElementAPI
mount Labimotion::GenericDatasetAPI
mount Labimotion::SegmentAPI
mount Labimotion::LabimotionHubAPI
mount Labimotion::LabimotionAPI
mount Chemotion::InventoryAPI
mount Chemotion::AffiliationAPI
mount Chemotion::AdminDeviceAPI
Expand Down
4 changes: 2 additions & 2 deletions app/api/helpers/container_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def create_or_update_containers(children, parent_container, current_user={})
if child[:container_type] == 'dataset' && child[:dataset].present? && child[:dataset]['changed']
klass_id = child[:dataset]['dataset_klass_id']
properties = child[:dataset]['properties']
container.save_dataset(dataset_klass_id: klass_id, properties: properties)
container.save_dataset(dataset_klass_id: klass_id, properties: properties, element: parent_container&.root&.containable, current_user: current_user) # rubocop:disable Layout/LineLength
end
create_or_update_containers(child[:children], container)
create_or_update_containers(child[:children], container, current_user)
end
end

Expand Down
21 changes: 10 additions & 11 deletions app/assets/stylesheets/legacy/generic_element.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,6 @@ $color-default: #777;
}
}

.input-form {
.input-group-addon {
font-weight: bold;
}
.help {
font-size: 80%;
margin: 6px;
font-style: italic;
}
}

.g-ds-note {
color: black !important;
float: left !important;
Expand Down Expand Up @@ -490,3 +479,13 @@ $color-default: #777;
top: 0px;
z-index: 10;
}

.custom-nav-link {
color: #007bff !important;
text-decoration: none;
}

.custom-nav-link:hover {
text-decoration: underline;
color: #0056b3;
}
131 changes: 45 additions & 86 deletions app/javascript/src/apps/generic/GenericDatasetsAdmin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable prefer-object-spread */
import React from 'react';
import ReactDOM from 'react-dom';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { orderBy } from 'lodash';
import { Constants, Designer } from 'chem-generic-ui';
import SyncBtn from 'src/apps/generic/SyncButton';
import LoadingModal from 'src/components/common/LoadingModal';
import Notifications from 'src/components/Notifications';
import GenericDSsFetcher from 'src/fetchers/GenericDSsFetcher';
Expand All @@ -22,7 +22,6 @@ export default class GenericDatasetsAdmin extends React.Component {
elements: [],
show: { tab: '', modal: '' },
revisions: [],
repoData: [],
user: {},
};
this.handleShowState = this.handleShowState.bind(this);
Expand All @@ -31,41 +30,29 @@ export default class GenericDatasetsAdmin extends React.Component {
this.handleSubmit = this.handleSubmit.bind(this);
this.delRevision = this.delRevision.bind(this);
this.fetchRevisions = this.fetchRevisions.bind(this);
this.handleCreateRepo = this.handleCreateRepo.bind(this);
this.handleShowRepo = this.handleShowRepo.bind(this);
}

componentDidMount() {
this.fetchElements();
UsersFetcher.fetchCurrentUser()
.then(result => {
.then((result) => {
if (!result.error) {
this.setState({ user: result.user });
}
})
.catch(errorMessage => {
.catch((errorMessage) => {
console.log(errorMessage);
});
}

getShowState(att, val) {
return { ...this.state.show, [att]: val };
}

fetchElements() {
GenericDSsFetcher.listDatasetKlass().then(result => {
this.setState({ elements: result.klass });
});
}

handleActivateKlass(e) {
const act = e.is_active ? 'De-activate' : 'Activate';
GenericDSsFetcher.deActivateKlass({
id: e.id,
is_active: !e.is_active,
klass: 'DatasetKlass',
})
.then(result => {
.then((result) => {
if (result.error) {
notification({
title: `${act} Dataset fail`,
Expand All @@ -82,7 +69,7 @@ export default class GenericDatasetsAdmin extends React.Component {
// this.fetchElements();
}
})
.catch(errorMessage => {
.catch((errorMessage) => {
console.log(errorMessage);
});
}
Expand All @@ -91,6 +78,36 @@ export default class GenericDatasetsAdmin extends React.Component {
this.setState({ show: this.getShowState(att, val) }, cb);
}

async handleSubmit(_element, _release = 'draft') {
const [element, release] = [_element, _release];
element.release = release;
LoadingActions.start();
const result = await submit(GenericDSsFetcher, { update: Constants.GENERIC_TYPES.DATASET, element, release });
if (result.isSuccess) {
notification(result);
this.fetchElements();
// eslint-disable-next-line react/no-unused-state
this.setState({ element: result.response }, () => LoadingActions.stop());
} else {
notification(result);
}
LoadingActions.stop();
}

getShowState(att, val) {
const { show } = this.state;
return { ...show, [att]: val };
}

fetchElements() {
LoadingActions.start();
GenericDSsFetcher.listDatasetKlass().then((result) => {
this.setState({ elements: result.klass });
}).finally(() => {
LoadingActions.stop();
});
}

closeModal(cb = () => {}) {
this.handleShowState('modal', '', cb);
}
Expand All @@ -99,7 +116,7 @@ export default class GenericDatasetsAdmin extends React.Component {
const element = _element;
if (element?.id) {
GenericDSsFetcher.fetchKlassRevisions(element.id, 'DatasetKlass').then(
result => {
(result) => {
let curr = Object.assign({}, { ...element.properties_template });
curr = Object.assign(
{},
Expand All @@ -116,10 +133,10 @@ export default class GenericDatasetsAdmin extends React.Component {
delRevision(params) {
const { id, data, uuid } = params;
GenericDSsFetcher.deleteKlassRevision({
id: id,
id,
klass_id: data?.id,
klass: 'DatasetKlass',
}).then(response => {
}).then((response) => {
if (response.error) {
notification({
title: 'Delete Revision',
Expand All @@ -137,59 +154,8 @@ export default class GenericDatasetsAdmin extends React.Component {
});
}

handleShowRepo() {
LoadingActions.start();
GenericDSsFetcher.fetchRepo().then(result => {
if (result.error) {
notification({
title: 'Cannot connect to Chemotion Repository',
lvl: 'error',
msg: result.error,
});
LoadingActions.stop();
} else {
this.setState(
{ repoData: result, show: this.getShowState('modal', 'NewRepo') },
() => LoadingActions.stop()
);
}

});
}

handleCreateRepo(element) {
GenericDSsFetcher.createRepo({ identifier: element['identifier'] }).then(
result => {
if (result?.status === 'success') {
this.setState({ elements: result?.klass || this.state.elements });
}
notification({
title: 'Sync from LabIMotion Hub',
lvl: result?.status || 'error',
msg: result?.message || 'Unknown error',
});
}
);
this.closeModal();
}

async handleSubmit(_element, _release = 'draft') {
const [element, release] = [_element, _release];
element.release = release;
LoadingActions.start();
const result = await submit(GenericDSsFetcher, { update: Constants.GENERIC_TYPES.DATASET, element, release });
if (result.isSuccess) {
notification(result);
this.fetchElements();
this.setState({ element: result.response }, () => LoadingActions.stop());
} else {
notification(result);
}
LoadingActions.stop();
}

renderGrid() {
const { elements } = this.state;
const { elements, revisions } = this.state;
const els = orderBy(elements, ['is_active', 'label'], ['desc', 'asc']);
return (
<Designer
Expand All @@ -199,12 +165,13 @@ export default class GenericDatasetsAdmin extends React.Component {
fnActive={this.handleActivateKlass}
fnDerive={() => {}}
fnUpdate={() => {}}
fnRefresh={this.fetchElements}
preview={{
fnDelRevisions: this.delRevision,
fnRevisions: this.fetchRevisions,
revisions: this.state.revisions,
revisions,
}}
genericType="Dataset"
genericType={Constants.GENERIC_TYPES.DATASET}
gridData={els}
/>
);
Expand All @@ -219,17 +186,8 @@ export default class GenericDatasetsAdmin extends React.Component {
return (
<div className="vw-90 my-auto mx-auto">
<GenericMenu userName={user.name} text={FN_ID} />
<div className="mt-5 pt-5">
<div className="mt-3">
<FunctionLocation name={FN_ID} />
<SyncBtn
data={this.state.repoData}
fnCreate={this.handleCreateRepo}
fnModalClose={this.closeModal}
fnModalOpen={this.handleShowRepo}
genericType={Constants.GENERIC_TYPES.DATASET}
klasses={this.state.klasses}
showModal={this.state.show.modal === 'NewRepo'}
/>
{this.renderGrid()}
</div>
<Notifications />
Expand All @@ -241,11 +199,12 @@ export default class GenericDatasetsAdmin extends React.Component {

document.addEventListener('DOMContentLoaded', () => {
const domElement = document.getElementById(`${FN_ID}Admin`);
if (domElement)
if (domElement) {
ReactDOM.render(
<DndProvider backend={HTML5Backend}>
<GenericDatasetsAdmin />
</DndProvider>,
domElement
);
}
});
Loading

0 comments on commit 80bc4eb

Please sign in to comment.