Skip to content

Commit

Permalink
fix build fail(UISelectExtended initialization issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
kajambiya committed Sep 27, 2023
1 parent 6c0dcb1 commit ec3a0df
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import debounce from 'lodash-es/debounce';
import { useTranslation } from 'react-i18next';
import { getRegisteredDataSource } from '../../../registry/registry';
import { useDataSourceConfig } from '../../../hooks/useDataSourceConfig';
import { getControlTemplate } from '../../../registry/inbuilt-components/inbuiltControls';

const UISelectExtended: React.FC<OHRIFormFieldProps> = ({ question, handler, onChange }) => {
const { t } = useTranslation();
Expand All @@ -29,11 +30,17 @@ const UISelectExtended: React.FC<OHRIFormFieldProps> = ({ question, handler, onC
const [inputValue, setInputValue] = useState('');
const isProcessingSelection = useRef(false);
const [dataSource, setDataSource] = useState(null);
const [config, setConfig] = useState({});

const config = useDataSourceConfig(question);
//const config = {}; //useDataSourceConfig(question);

useEffect(() => {
const datasourceName = question.questionOptions?.datasource?.name;
setConfig(
datasourceName
? question.questionOptions.datasource?.config
: getControlTemplate(question.questionOptions.rendering)?.datasource?.config,
);
getRegisteredDataSource(datasourceName ? datasourceName : question.questionOptions.rendering).then(ds =>
setDataSource(ds),
);
Expand Down
22 changes: 0 additions & 22 deletions src/hooks/useDataSourceConfig.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions src/registry/inbuilt-components/control-templates.ts

This file was deleted.

20 changes: 18 additions & 2 deletions src/registry/inbuilt-components/inbuiltControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ import OHRIToggle from '../../components/inputs/toggle/ohri-toggle.component';
import UISelectExtended from '../../components/inputs/ui-select-extended/ui-select-extended';
import { OHRIRepeat } from '../../components/repeat/ohri-repeat.component';
import { RegistryItem } from '../registry';
import { controlTemplates } from './control-templates';

/**
* @internal
*/
const controlTemplates = [
{
name: 'drug',
baseControlComponent: UISelectExtended,
datasource: {
name: 'drug_datasource',
config: {
class: '8d490dfc-c2cc-11de-8d13-0010c6dffd0f',
},
},
},
];

export const inbuiltControls: Array<RegistryItem<React.ComponentType<OHRIFormFieldProps>>> = [
{
name: 'OHRIText',
Expand Down Expand Up @@ -111,7 +123,11 @@ export const inbuiltControls: Array<RegistryItem<React.ComponentType<OHRIFormFie
},
...controlTemplates.map(template => ({
name: `${template.name}Control`,
component: UISelectExtended,//template.baseControlComponent,
component: template.baseControlComponent,
type: template.name.toLowerCase(),
})),
];

export const getControlTemplate = (name: string) => {
return controlTemplates.find(template => template.name === name);
};
3 changes: 1 addition & 2 deletions src/registry/registry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { DataSource, FieldValidator, OHRIFormFieldProps, PostSubmissionAction, SubmissionHandler } from '../api/types';
import { getGlobalStore } from '@openmrs/esm-framework';
import { OHRIFormsStore } from '../constants';
import { inbuiltControls } from './inbuilt-components/inbuiltControls';
import { getControlTemplate, inbuiltControls } from './inbuilt-components/inbuiltControls';
import { inbuiltFieldSubmissionHandlers } from './inbuilt-components/inbuiltFieldSubmissionHandlers';
import { inbuiltValidators } from './inbuilt-components/inbuiltValidators';
import { inbuiltDataSources } from './inbuilt-components/inbuiltDataSources';
import { getControlTemplate } from './inbuilt-components/control-templates';

/**
* @internal
Expand Down

0 comments on commit ec3a0df

Please sign in to comment.