Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Oct 12, 2024
1 parent 3eb00a4 commit 5048e74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/components/view-editor/view-editor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import InteractiveBuilder from '../interactive-builder/interactive-builder.compo
import { type Schema } from '../../types';

import styles from './view-editor.scss';
import { updateSchemaInConfig } from '../../helpers';

interface TranslationFnProps {
t: TFunction;
Expand Down Expand Up @@ -59,7 +60,7 @@ const ContentPackagesEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
const renderSchemaChanges = useCallback(() => {
if (!stringifiedSchema) {
showSnackbar({
title: t('errorRendering', 'Error rendering'),
title: t('renderingError', 'Rendering error'),
kind: 'error',
subtitle: t('renderingErrorMessage', 'There was an error rendering the clinical view'),
});
Expand Down Expand Up @@ -162,16 +163,15 @@ const ContentPackagesEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
if (schema && schemaId) {
const existingSchema = localStorage.getItem(schemaId);
if (existingSchema) {
// If it exists, update the schema
localStorage.setItem(schemaId, JSON.stringify(schema));
updateSchemaInConfig(schemaId, schema);
showSnackbar({
title: t('clinicalViewUpdated', 'Clinical view updated'),
kind: 'success',
subtitle: t('updateSuccessMessage', 'Clinical view updated successfully'),
});
setIsSaving(false);
} else {
localStorage.setItem(schemaId, JSON.stringify(schema));
updateSchemaInConfig(schemaId, schema);
showSnackbar({
title: t('clinicalViewCreated', 'Clinical view saved'),
kind: 'success',
Expand All @@ -189,7 +189,7 @@ const ContentPackagesEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
}
};

const handlePreviewPackage = () => {
const handlePreviewClinicalView = () => {
window.open(window.getOpenmrsSpaBase() + `patient/${patientUuid}/chart/Patient%20Summary`);
};

Expand Down Expand Up @@ -280,7 +280,7 @@ const ContentPackagesEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
? t('updateSchema', 'Update Schema')
: t('saveClinicalView', 'Save clinical view')}
</Button>
<Button disabled={!navGroupTitle || isSaving} onClick={handlePreviewPackage}>
<Button disabled={!navGroupTitle || isSaving} onClick={handlePreviewClinicalView}>
{schema && t('previewClinicalView', 'Preview clinical view')}
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Type } from '@openmrs/esm-framework';
export const configSchema = {
patientUuid: {
_type: Type.String,
_description: 'UUID for the stock item category',
_description: 'UUID for the patient',
_default: '6cea3475-67d0-4ce9-b947-7cfd407c9168',
},
};
Expand Down
4 changes: 4 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

0 comments on commit 5048e74

Please sign in to comment.