Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1589 | concept locale type can be free text…
Browse files Browse the repository at this point in the history
… for non-OpenMRS schema
  • Loading branch information
snyaggarwal committed May 26, 2023
1 parent 9125b7a commit a8e7849
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common/utils.js
Expand Up @@ -895,7 +895,7 @@ export const sortValuesBySourceSummary = (data, summary, summaryField, isLocale)
let values = orderBy(_data, ['resultType', 'name'], ['desc', 'asc'])

if(isLocale) {
values = uniqBy([{...find(values, {id: summary.default_locale}), resultType: 'Suggested'}, ...orderBy(filter(values, val => summary.supported_locales.includes(val.id)).map(val => ({...val, resultType: 'Suggested'})), ['name'], ['asc']), ...values], 'id')
values = uniqBy([{...find(values, {id: summary.default_locale}), resultType: 'Suggested'}, ...orderBy(filter(values, val => (summary.supported_locales || []).includes(val.id)).map(val => ({...val, resultType: 'Suggested'})), ['name'], ['asc']), ...values], 'id')
}

return values
Expand Down
12 changes: 11 additions & 1 deletion src/components/concepts/ConceptForm.jsx
Expand Up @@ -9,7 +9,7 @@ import {
import APIService from '../../services/APIService';
import {
arrayToObject, fetchDatatypes, fetchNameTypes, sortValuesBySourceSummary,
fetchDescriptionTypes, fetchConceptClasses, recordGAUpsertEvent
fetchDescriptionTypes, fetchConceptClasses, recordGAUpsertEvent, toParentURI
} from '../../common/utils';
import { ERROR_RED } from '../../common/constants';
import LocaleForm from './LocaleForm';
Expand Down Expand Up @@ -63,6 +63,14 @@ class ConceptForm extends React.Component {
this.fetchConceptToCreate()
if(!this.props.edit)
this.setState({parent: this.props.source})
else
this.fetchParent()
}

fetchParent = () => {
if(!this.props.source && this.props.edit && this.props.concept) {
APIService.new().overrideURL(toParentURI(this.props.concept.url)).get().then(response => this.setState({parent: response.data}))
}
}

fetchConceptToCreate() {
Expand Down Expand Up @@ -535,6 +543,7 @@ class ConceptForm extends React.Component {
types={nameTypes}
onDelete={this.onDeleteNameLocale}
sourceVersionSummary={this.props.sourceVersionSummary}
source={this.state.parent}
/>
</div>
))
Expand Down Expand Up @@ -562,6 +571,7 @@ class ConceptForm extends React.Component {
types={descriptionTypes}
onDelete={this.onDeleteDescLocale}
sourceVersionSummary={this.props.sourceVersionSummary}
source={this.state.parent}
/>
</div>
))
Expand Down
13 changes: 9 additions & 4 deletions src/components/concepts/LocaleForm.jsx
Expand Up @@ -2,15 +2,15 @@ import React from 'react';
import Autocomplete from '@mui/material/Autocomplete';
import { TextField, Checkbox, IconButton, FormControlLabel } from '@mui/material';
import { Delete as DeleteIcon } from '@mui/icons-material';
import { find, get, orderBy, uniqBy } from 'lodash'
import { find, get, orderBy, uniqBy, isString } from 'lodash'
import { ERROR_RED } from '../../common/constants';
import LocaleAutoComplete from '../common/LocaleAutoComplete';
import GroupHeader from '../common/GroupHeader';
import GroupItems from '../common/GroupItems';

const LocaleForm = ({
localeAttr, index, onTextFieldChange, onAutoCompleteChange, onCheckboxChange, types,
onDelete, error, locale, sourceVersionSummary
onDelete, error, locale, sourceVersionSummary, source
}) => {
const isName = localeAttr === 'fields.names';
const nameAttr = isName ? 'name' : 'description';
Expand Down Expand Up @@ -39,6 +39,9 @@ const LocaleForm = ({
setSelectedLocale({id: locale.locale, name: locale.locale})
}, [locale])


const isOpenMRSValidationSchema = source?.custom_validation_schema?.toLowerCase() === 'openmrs'

return (
<div className='col-md-12' style={{border: `1px solid ${borderColor}`, borderRadius: '4px', paddingBottom: '15px', width: '100%'}}>
<div className='col-md-12 no-side-padding' style={{marginTop: '15px', width: '100%'}}>
Expand All @@ -56,11 +59,13 @@ const LocaleForm = ({
</div>
<div className="col-md-6 no-left-padding">
<Autocomplete
freeSolo={!isOpenMRSValidationSchema}
autoSelect={!isOpenMRSValidationSchema}
openOnFocus
value={selectedLocaleType}
id={`${idPrefix}.${typeAttr}`}
options={formattedTypes}
getOptionLabel={(option) => option.name}
getOptionLabel={(option) => isString(option) ? option : option.name}
fullWidth
groupBy={option => option.resultType}
renderGroup={params => (
Expand All @@ -70,7 +75,7 @@ const LocaleForm = ({
</li>
)}
renderInput={(params) => <TextField {...params} size='small' label="Type" variant="outlined" fullWidth />}
onChange={(event, item) => onAutoCompleteChange(`${idPrefix}.${typeAttr}`, item)}
onChange={(event, item) => onAutoCompleteChange(`${idPrefix}.${typeAttr}`, isOpenMRSValidationSchema ? item : isString(item) ? {id: item} : item)}
/>
</div>
<div className="col-md-6 no-left-padding" style={{marginTop: '15px'}}>
Expand Down

0 comments on commit a8e7849

Please sign in to comment.