diff --git a/src/components/view-editor/view-editor.component.tsx b/src/components/view-editor/view-editor.component.tsx index 397574d..b6b7627 100644 --- a/src/components/view-editor/view-editor.component.tsx +++ b/src/components/view-editor/view-editor.component.tsx @@ -5,12 +5,13 @@ import { Column, CopyButton, Grid, IconButton, Button, FileUploader } from '@car import { type TFunction, useTranslation } from 'react-i18next'; import { ArrowLeft, Maximize, Minimize, Download } from '@carbon/react/icons'; import Header from '../header/header.component'; -import { ConfigurableLink, showSnackbar } from '@openmrs/esm-framework'; +import { type ConfigObject, ConfigurableLink, showSnackbar, useConfig } from '@openmrs/esm-framework'; import SchemaEditor from '../schema-editor/schema-editor.component'; import InteractiveBuilder from '../interactive-builder/interactive-builder.component'; import { type Schema } from '../../types'; import styles from './view-editor.scss'; +import { updateSchemaInConfig } from '../../helpers'; interface TranslationFnProps { t: TFunction; @@ -25,6 +26,7 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => { const { clinicalViewId } = useParams(); // Extract 'id' from the URL const location = useLocation(); // To check if it's in 'edit' mode + const { patientUuid } = useConfig(); useEffect(() => { if (clinicalViewId && location.pathname.includes('edit')) { @@ -33,7 +35,7 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => { }, [clinicalViewId, location]); const loadSchema = (id: string) => { - const savedSchema = localStorage.getItem(`packageJSON_${id}`); + const savedSchema = localStorage.getItem(id); if (savedSchema) { const parsedSchema: Schema = JSON.parse(savedSchema); setSchema(parsedSchema); @@ -56,10 +58,18 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => { }, []); const renderSchemaChanges = useCallback(() => { + if (!stringifiedSchema) { + showSnackbar({ + title: t('renderingError', 'Rendering error'), + kind: 'error', + subtitle: t('renderingErrorMessage', 'There was an error rendering the clinical view'), + }); + return; + } const parsedJson: Schema = JSON.parse(stringifiedSchema); updateSchema(parsedJson); setStringifiedSchema(JSON.stringify(parsedJson, null, 2)); - }, [stringifiedSchema, updateSchema]); + }, [stringifiedSchema, updateSchema, t]); const inputDummySchema = useCallback(() => { const dummySchema: Schema = { @@ -147,14 +157,13 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => { return ''; }; - const handleSavePackage = () => { + const handleSaveClinicalView = () => { setIsSaving(true); - if (schema && schema.id) { - const existingSchema = localStorage.getItem(`packageJSON_${schema.id}`); - + const schemaId = Object.keys(schema)?.[0]; + if (schema && schemaId) { + const existingSchema = localStorage.getItem(schemaId); if (existingSchema) { - // If it exists, update the schema - localStorage.setItem(`packageJSON_${schema.id}`, JSON.stringify(schema)); + updateSchemaInConfig(schemaId, schema); showSnackbar({ title: t('clinicalViewUpdated', 'Clinical view updated'), kind: 'success', @@ -162,7 +171,7 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => { }); setIsSaving(false); } else { - localStorage.setItem(`packageJSON_${schema.id}`, JSON.stringify(schema)); + updateSchemaInConfig(schemaId, schema); showSnackbar({ title: t('clinicalViewCreated', 'Clinical view saved'), kind: 'success', @@ -180,6 +189,10 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => { } }; + const handlePreviewClinicalView = () => { + window.open(window.getOpenmrsSpaBase() + `patient/${patientUuid}/chart/Patient%20Summary`); + }; + const navGroupTitle = getNavGroupTitle(schema); const sanitizedTitle = navGroupTitle?.replace(/\s+/g, '_'); @@ -262,11 +275,14 @@ const ContentPackagesEditorContent: React.FC = ({ t }) => {
{t('interactiveBuilder', 'Interactive Builder')}
- +
diff --git a/src/components/view-editor/view-editor.scss b/src/components/view-editor/view-editor.scss index 2f8ca96..eb1547c 100644 --- a/src/components/view-editor/view-editor.scss +++ b/src/components/view-editor/view-editor.scss @@ -111,4 +111,5 @@ button { .topBtns { display: flex; align-items: center; + gap: layout.$spacing-03; } diff --git a/src/config-schema.ts b/src/config-schema.ts index 1524652..05d73e1 100644 --- a/src/config-schema.ts +++ b/src/config-schema.ts @@ -1,3 +1,13 @@ -export const configSchema = {}; +import { Type } from '@openmrs/esm-framework'; -export interface ConfigObject {} +export const configSchema = { + patientUuid: { + _type: Type.String, + _description: 'UUID for the patient', + _default: '6cea3475-67d0-4ce9-b947-7cfd407c9168', + }, +}; + +export interface ConfigObject { + patientUuid: string; +} diff --git a/src/helpers.ts b/src/helpers.ts index 996fd23..33eef29 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -23,3 +23,7 @@ export const toCamelCase = (str: string) => { export const isValidSlotName = (slotName: string) => { return /^[a-zA-Z0-9-]+$/.test(slotName); }; + +export const updateSchemaInConfig = (schemaId, schema) => { + localStorage.setItem(schemaId, JSON.stringify(schema)); +}; diff --git a/translations/am.json b/translations/am.json index 91f490d..b02f5a2 100644 --- a/translations/am.json +++ b/translations/am.json @@ -70,9 +70,12 @@ "noSubmenusText": "ምንም የተጨማሪ እይታ አልተጨምረም። አዲስ ንብረት ይጨምሩ.", "noWidgetsAvailable": "No widgets available", "packageCreated": "አዲስ ፓኬጅ ተፈጠር", + "previewClinicalView": "Preview clinical view", "programIdentifier": "የፕሮግራም መለያ", "programIdentifierPlaceholder": "ምሳሌ ፡ የHiv እና መነሻ አገልግሎት", "renderChanges": "ለውጦችን ይወረድ", + "renderingError": "Rendering error", + "renderingErrorMessage": "There was an error rendering the clinical view", "save": "ይደርስ", "saveClinicalView": "ክሊኒካል እይታ ይደርስ", "savingErrorMessage": "የክሊኒካል እይታ ማስታወሻ ወንጀል አለ", diff --git a/translations/en.json b/translations/en.json index cb41c9a..86f468f 100644 --- a/translations/en.json +++ b/translations/en.json @@ -70,9 +70,12 @@ "noSubmenusText": "No submenus views added yet. Click the button to add a new submenu link.", "noWidgetsAvailable": "No widgets available", "packageCreated": "New package created", + "previewClinicalView": "Preview clinical view", "programIdentifier": "Program Identifier", "programIdentifierPlaceholder": "e.g. Hiv Care and Treatment", "renderChanges": "Render changes", + "renderingError": "Rendering error", + "renderingErrorMessage": "There was an error rendering the clinical view", "save": "Save", "saveClinicalView": "Save clinical view", "savingErrorMessage": "There was an error saving a clinical view", diff --git a/translations/es.json b/translations/es.json index a4e182d..86d00d3 100644 --- a/translations/es.json +++ b/translations/es.json @@ -70,9 +70,12 @@ "noSubmenusText": "No se han agregado vistas de submenú. Haz clic en el botón para agregar un nuevo enlace de submenú.", "noWidgetsAvailable": "No widgets available", "packageCreated": "Nuevo paquete creado", + "previewClinicalView": "Preview clinical view", "programIdentifier": "Identificador del programa", "programIdentifierPlaceholder": "p. ej., Cuidado y tratamiento del VIH", "renderChanges": "Renderizar cambios", + "renderingError": "Rendering error", + "renderingErrorMessage": "There was an error rendering the clinical view", "save": "Guardar", "saveClinicalView": "Guardar vista clínica", "savingErrorMessage": "Hubo un error al guardar una vista clínica", diff --git a/translations/fr.json b/translations/fr.json index 3f742e8..df9f189 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -70,9 +70,12 @@ "noSubmenusText": "Aucun sous-menu ajouté. Cliquez sur le bouton pour ajouter un nouveau lien de sous-menu.", "noWidgetsAvailable": "No widgets available", "packageCreated": "Nouveau package créé", + "previewClinicalView": "Preview clinical view", "programIdentifier": "Identifiant du programme", "programIdentifierPlaceholder": "p. ex., Soins et traitement du VIH", "renderChanges": "Rendre les modifications", + "renderingError": "Rendering error", + "renderingErrorMessage": "There was an error rendering the clinical view", "save": "Enregistrer", "saveClinicalView": "Enregistrer la vue clinique", "savingErrorMessage": "Une erreur s'est produite lors de l'enregistrement d'une vue clinique", diff --git a/translations/he.json b/translations/he.json index 675e4eb..1674d49 100644 --- a/translations/he.json +++ b/translations/he.json @@ -70,9 +70,12 @@ "noSubmenusText": "אין תתי תפריטים שנוספו עדיין. לחץ על הכפתור כדי להוסיף קישור לתפריט משנה חדש.", "noWidgetsAvailable": "No widgets available", "packageCreated": "חבילה חדשה נוצרה", + "previewClinicalView": "Preview clinical view", "programIdentifier": "מזהה תוכנית", "programIdentifierPlaceholder": "למשל, טיפול וטיפול ב-HIV", "renderChanges": "הצג שינויים", + "renderingError": "Rendering error", + "renderingErrorMessage": "There was an error rendering the clinical view", "save": "שמור", "saveClinicalView": "שמור תצוגה קלינית", "savingErrorMessage": "הייתה שגיאה בשמירה של תצוגה קלינית", diff --git a/translations/km.json b/translations/km.json index 71edace..434681f 100644 --- a/translations/km.json +++ b/translations/km.json @@ -70,9 +70,12 @@ "noSubmenusText": "មិនមានមាតិកាសម្រាប់បន្ថែមទេ។ ចុចប៊ូតុងដើម្បីបន្ថែមតំណទៅម៉ឺនុយរងថ្មីមួយ។", "noWidgetsAvailable": "No widgets available", "packageCreated": "កញ្ចប់ថ្មីត្រូវបានបង្កើត", + "previewClinicalView": "Preview clinical view", "programIdentifier": "លេខសម្គាល់កម្មវិធី", "programIdentifierPlaceholder": "ឧ. ការថែទាំនិងការព្យាបាល HIV", "renderChanges": "បង្ហាញការប្រែប្រែ", + "renderingError": "Rendering error", + "renderingErrorMessage": "There was an error rendering the clinical view", "save": "រក្សាទុក", "saveClinicalView": "រក្សាទុកទស្សនៈគ្លីនិក", "savingErrorMessage": "មានកំហុសក្នុងការរក្សាទុកទស្សនៈគ្លីនិក",