Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cllde8 committed Jan 30, 2024
1 parent bead103 commit c21d391
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 556 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ yarn add chem-generic-ui

## Engage with Us

Feel free to utilize the [Discussions](https://github.com/LabIMotion/chem-generic-ui/discussions) section to share any inquiries, concerns, suggestions, ideas, or even express your interest in collaboration. We welcome your participation! :sun_with_face:
Feel free to utilize the [Discussions](https://github.com/LabIMotion/labimotion/discussions) section to share any inquiries, concerns, suggestions, ideas, or even express your interest in collaboration. We welcome your participation! :sun_with_face:

## License

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chem-generic-ui",
"version": "1.0.11",
"version": "1.1.1",
"main": "./dist/bundle.js",
"license": "AGPL-3.0",
"private": false,
Expand Down Expand Up @@ -72,7 +72,6 @@
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jest-extended": "^4.0.1",
"jsdoc-to-markdown": "^8.0.0",
"postcss": "^8.4.31",
"postcss-cli": "^9.1.0",
"postcss-loader": "^6.2.1",
Expand Down
14 changes: 14 additions & 0 deletions src/assets/field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@
}
}

@mixin gu-ontology-select-code {
border-radius: 0.375rem;
float: right;
}

.gu-ontology-select-code-prefix {
@include gu-ontology-select-code;
background-color: $color-bs-primary !important;
}

.gu-ontology-select-code-short {
@include gu-ontology-select-code;
background-color: $color-bs-info !important;
}
26 changes: 24 additions & 2 deletions src/components/elements/ElementField.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ import GroupFields from './GroupFields';
import TextFormula from './TextFormula';
import TableDef from './TableDef';
import ConditionFieldBtn from '../designer/template/ConditionFieldBtn';
import TermLink from '../fields/TermLink';
import {
renderDatetimeRange,
renderDummyFieldGroup,
renderNameField,
renderTextFieldGroup,
renderOwnRow,
renderRequired,
renderReadonly,
} from './Fields';

class ElementField extends Component {
Expand All @@ -40,6 +43,7 @@ class ElementField extends Component {
this.handleChange = this.handleChange.bind(this);
this.handelDelete = this.handelDelete.bind(this);
this.handleMove = this.handleMove.bind(this);
this.handleOntChange = this.handleOntChange.bind(this);
this.handleAddDummy = this.handleAddDummy.bind(this);
this.updSubField = this.updSubField.bind(this);
this.handlePanelToggle = this.handlePanelToggle.bind(this);
Expand All @@ -54,7 +58,6 @@ class ElementField extends Component {
};

handleChange(e, orig, fe, lk, fc, tp) {
const { value } = e;
if (
(tp === FieldTypes.F_SELECT || tp === FieldTypes.F_SYSTEM_DEFINED) &&
e === null
Expand All @@ -73,6 +76,18 @@ class ElementField extends Component {
this.props.onMove(l, f, isUp);
}

handleOntChange(_params) {
const { field: fieldObject, layer } = this.props;
this.handleChange(
{ value: _params?.data },
fieldObject['field'],
fieldObject.field,
layer.key,
'ontology', // 'field',
'select' // 'Ontology' // 'text'
);
}

handleAddDummy(_params) {
this.props.onDummyAdd(_params);
}
Expand Down Expand Up @@ -346,6 +361,7 @@ class ElementField extends Component {
<Badge className="bg-bs-field-display">{f.field || ''}</Badge>
&nbsp;
<Badge className="bg-bs-field-display">{f.type || ''}</Badge>
{TermLink(fieldObject.ontology)}
</Panel.Title>
<ButtonGroup bsSize="xsmall">
<ConditionFieldBtn
Expand Down Expand Up @@ -383,12 +399,13 @@ class ElementField extends Component {
<Panel.Body>
<Form horizontal className="default_style">
{renderDummyFieldGroup({ layer, fieldObject })}
{renderTextFieldGroup({
{renderNameField({
layer,
fieldObject,
label: 'Field Name',
field: 'field',
fnChange: this.handleChange,
fnOntChange: this.handleOntChange,
})}
{renderTextFieldGroup({
layer,
Expand Down Expand Up @@ -542,6 +559,11 @@ class ElementField extends Component {
fnChange: this.handleChange,
})
: null}
{renderReadonly({
layer,
fieldObject,
fnChange: this.handleChange,
})}
{[FieldTypes.F_INTEGER, FieldTypes.F_TEXT].includes(f.type)
? renderTextFieldGroup({
layer,
Expand Down
64 changes: 62 additions & 2 deletions src/components/elements/Fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
FormGroup,
} from 'react-bootstrap';
import { FieldTypes } from 'generic-ui-core';
import OntologySelect from './OntologySelect';
import { ButtonOntologySelect } from '../fields/ModalOntologySelect';

export const renderDatetimeRange = ({ fieldObject }) =>
[FieldTypes.F_DATETIME_RANGE].includes(fieldObject.type) ? (
Expand Down Expand Up @@ -45,6 +47,43 @@ export const renderDummyFieldGroup = ({ layer, fieldObject }) =>
</FormGroup>
) : null;

export const renderNameField = ({
layer,
fieldObject,
label,
field,
fnChange,
fnOntChange,
}) => (
<FormGroup className="gu-form-group">
<Col sm={3}>
<span className="gu-form-group-label">{label}</span>
</Col>
<Col sm={9} style={{ display: 'inline-flex' }}>
<FormControl
type="text"
name={`f_${field}`}
defaultValue={fieldObject[field]}
disabled={field === 'field'}
onChange={event =>
fnChange(
event,
fieldObject[field],
fieldObject.field,
layer.key,
field,
'text'
)
}
/>
<ButtonOntologySelect
modalComponent={<OntologySelect fnSelected={fnOntChange} defaultValue={fieldObject?.ontology} />}
customClass={fieldObject?.ontology ? 'gu-ontology-selected' : null}
/>
</Col>
</FormGroup>
);

export const renderTextFieldGroup = ({
layer,
fieldObject,
Expand Down Expand Up @@ -78,7 +117,14 @@ export const renderTextFieldGroup = ({
</FormGroup>
);

export const renderCheck = ({ layer, fieldObject, fnChange, label, field }) => (
export const renderCheck = ({
layer,
fieldObject,
fnChange,
label,
field,
note,
}) => (
<FormGroup className="gu-form-group">
<Col sm={3}>
<span className="gu-form-group-label">{label}</span>
Expand All @@ -97,7 +143,9 @@ export const renderCheck = ({ layer, fieldObject, fnChange, label, field }) => (
'checkbox'
)
}
/>
>
{note}
</Checkbox>
</Col>
</FormGroup>
);
Expand Down Expand Up @@ -127,3 +175,15 @@ export const renderRequired = ({ layer, fieldObject, fnChange }) =>
field: 'required',
})
: null;

export const renderReadonly = ({ layer, fieldObject, fnChange }) =>
[FieldTypes.F_TEXT].includes(fieldObject.type)
? renderCheck({
layer,
fieldObject,
fnChange,
label: 'Readonly',
field: 'readonly',
note: "When in 'Read-Only' mode, it displays as plain text with a placeholder if available.",
})
: null;
113 changes: 113 additions & 0 deletions src/components/elements/OntologySelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import React, { useState, useEffect } from 'react';
import AsyncSelect from 'react-select/async';

const TS_BASE = 'https://service.tib.eu/ts4tib/api/select';
const TS_PARAM = [
'rows=20',
'collection=nfdi4chem',
'obsoletes=false',
'local=false',
'fieldList=id,iri,label,short_form,obo_id,ontology_name,ontology_prefix,description,type',
].join('&');

const constructOption = data => {
if (data) {
const desc = data.description?.join('') || '';
return {
value: data.id,
label: (
<>
{data.label}
<span>
<span className="gu-ontology-select-code-short badge">
{data.short_form}
</span>
&nbsp;
<span className="gu-ontology-select-code-prefix badge">
{data.ontology_prefix}
</span>
{desc ? (
<>
<br />
<span style={{ fontSize: '11px' }}>{desc}</span>
</>
) : null}
</span>
</>
),
};
}
return data;
};

const constructOptions = data => {
if (!data) {
return [];
}
return data.map(d => {
const option = Object.assign(constructOption(d), { data: d });
return option;
});
};

const OntologySelect = props => {
const { fnSelected, defaultValue } = props;
const [data, setData] = useState(null);

const fetchData = async inputValue => {
try {
if (!inputValue.trim() || inputValue.length < 2) {
return [];
}

const response = await fetch(`${TS_BASE}?q=${inputValue}&${TS_PARAM}`);
if (!response.ok) {
throw new Error('Network request failed');
}
const result = await response.json();
return constructOptions(result?.response?.docs);
} catch (error) {
console.error('Error fetching data:', error);
return [];
}
};

useEffect(() => {
fetchData('').then(setData);
}, []);

return (
<AsyncSelect
backspaceRemoves
isClearable
value={defaultValue}
valueKey="value"
labelKey="label"
loadOptions={(inputValue, callback) => {
fetchData(inputValue).then(options => callback(options));
}}
onChange={selected => {
fnSelected(selected);
}}
styles={{
container: baseStyles => {
return {
...baseStyles,
width: '100%',
};
},
control: base => {
return {
...base,
height: '36px',
minHeight: '36px',
minWidth: '200px',
border: '1px solid #ccc',
};
},
}}
/>
);
};

export default OntologySelect;
15 changes: 5 additions & 10 deletions src/components/elements/SegmentAttrForm.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/* eslint-disable react/forbid-prop-types */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { v4 as uuid } from 'uuid';
import {
Form,
FormControl,
FormGroup,
InputGroup,
Button,
} from 'react-bootstrap';
import { Form, FormControl, FormGroup, InputGroup } from 'react-bootstrap';

export default class SegmentAttrForm extends Component {
render() {
const { element, editable, klasses } = this.props;

const klassOptions = klasses?.map(k => (
<option key={uuid()} value={k.id}>
<option key={k.id} value={k.id}>
{k.label}
</option>
));
Expand Down Expand Up @@ -49,8 +43,9 @@ export default class SegmentAttrForm extends Component {
<InputGroup>
<InputGroup.Addon>Assign to Element</InputGroup.Addon>
<FormControl
key={element?.element_klass?.id}
componentClass="select"
value={element?.element_klass?.id}
defaultValue={element?.element_klass?.id}
inputRef={ref => {
this.k_klass = ref;
}}
Expand Down
Loading

0 comments on commit c21d391

Please sign in to comment.