diff --git a/packages/apps/esm-implementer-tools-app/src/backend-dependencies/openmrs-backend-dependencies.ts b/packages/apps/esm-implementer-tools-app/src/backend-dependencies/openmrs-backend-dependencies.ts index f6c9e8244..c8677ec5b 100644 --- a/packages/apps/esm-implementer-tools-app/src/backend-dependencies/openmrs-backend-dependencies.ts +++ b/packages/apps/esm-implementer-tools-app/src/backend-dependencies/openmrs-backend-dependencies.ts @@ -1,5 +1,6 @@ import { isVersionSatisfied, openmrsFetch } from '@openmrs/esm-framework'; import difference from 'lodash-es/difference'; +import { useMemo, useState } from 'react'; export type ResolvedBackendModuleType = 'missing' | 'version-mismatch' | 'okay'; @@ -155,3 +156,21 @@ export async function checkModules(): Promise> export function hasInvalidDependencies(frontendModules: Array) { return frontendModules.some((m) => m.dependencies.some((n) => n.type !== 'okay')); } + +export function useBackendDependencyCheck(moduleName: string) { + const [backendDependencies, setBackendDependencies] = useState>([]); + + useMemo(async () => { + const dependencies = await initInstalledBackendModules(); + setBackendDependencies(dependencies); + }, []); + + const isPresent = useMemo(() => { + if (backendDependencies) { + return backendDependencies.some((module) => module.uuid === moduleName); + } + return false; + }, [backendDependencies, moduleName]); + + return isPresent; +} diff --git a/packages/apps/esm-implementer-tools-app/src/configuration/configuration.component.tsx b/packages/apps/esm-implementer-tools-app/src/configuration/configuration.component.tsx index 1acccb9b7..2a9a97b55 100644 --- a/packages/apps/esm-implementer-tools-app/src/configuration/configuration.component.tsx +++ b/packages/apps/esm-implementer-tools-app/src/configuration/configuration.component.tsx @@ -1,13 +1,16 @@ import React, { useMemo, useState } from 'react'; import { Button, Column, FlexGrid, Row, TextInput, Toggle } from '@carbon/react'; import { useTranslation } from 'react-i18next'; -import { ChevronDown, ChevronUp, Download, TrashCan } from '@carbon/react/icons'; +import { ChevronDown, ChevronUp, Download, TrashCan, Upload } from '@carbon/react/icons'; import cloneDeep from 'lodash-es/cloneDeep'; import isEmpty from 'lodash-es/isEmpty'; import type { Config } from '@openmrs/esm-framework/src/internal'; import { getExtensionInternalStore, implementerToolsConfigStore, + navigate, + showNotification, + showToast, temporaryConfigStore, useStore, useStoreWithActions, @@ -17,6 +20,8 @@ import { Description } from './interactive-editor/description.component'; import type { ImplementerToolsStore } from '../store'; import { implementerToolsStore } from '../store'; import styles from './configuration.styles.scss'; +import { saveConfig } from './configuration.resource'; +import { useBackendDependencyCheck } from '../backend-dependencies/openmrs-backend-dependencies'; const JsonEditor = React.lazy(() => import('./json-editor/json-editor.component')); @@ -62,6 +67,7 @@ export interface ConfigurationProps {} export const Configuration: React.FC = () => { const { t } = useTranslation(); + const isSpaModulePresent = useBackendDependencyCheck('spa'); const { isUIEditorEnabled, toggleIsUIEditorEnabled, @@ -158,6 +164,43 @@ export const Configuration: React.FC = () => { > {t('clearConfig', 'Clear Local Config')} + {isSpaModulePresent ? ( + + ) : null}