Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-2485: Allow view only field for visit location in the start visit form #1403

Merged
merged 14 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/esm-patient-chart-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export const esmPatientChartSchema = {
'An array of concept UUIDs. If an observation has a concept UUID that matches any of the ones in this array, it will be hidden from the observations list in the Encounters summary table.',
_default: [],
},
viewOnlyVisitLocationField: {
brandones marked this conversation as resolved.
Show resolved Hide resolved
_type: Type.Boolean,
_description: 'Whether the visit location field in the start visit form should be view only',
brandones marked this conversation as resolved.
Show resolved Hide resolved
_default: false,
},
};

export interface ChartConfig {
Expand All @@ -133,6 +138,7 @@ export interface ChartConfig {
alt: string;
name: string;
};
viewOnlyVisitLocationField: boolean;
}

export const configSchema = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React, { useState } from 'react';
import styles from './visit-form.scss';
import { Location, OpenmrsResource, useLayoutType, useSession } from '@openmrs/esm-framework';
import { ComboBox, InlineNotification } from '@carbon/react';
import { Location, OpenmrsResource, useConfig, useSession } from '@openmrs/esm-framework';
import { ComboBox } from '@carbon/react';
import { useDefaultLoginLocation } from '../hooks/useDefaultLocation';
import { useTranslation } from 'react-i18next';
import { useLocations } from '../hooks/useLocations';
import isEmpty from 'lodash/isEmpty';
import { useFormContext, Controller } from 'react-hook-form';
import { VisitFormData } from './visit-form.component';
import { ChartConfig } from '../../config-schema';

const LocationSelector = () => {
const { t } = useTranslation();
const session = useSession();
const [searchTerm, setSearchTerm] = useState('');
const selectedSessionLocation = useSession().sessionLocation;
const { locations, isLoading: isLoadingLocations, error } = useLocations(searchTerm);
const { defaultFacility, isLoading: loadingDefaultFacility } = useDefaultLoginLocation();
const config = useConfig() as ChartConfig;
const viewOnlyVisitLocationField = config?.viewOnlyVisitLocationField;
const locationsToShow: Array<OpenmrsResource> =
!loadingDefaultFacility && !isEmpty(defaultFacility)
? [defaultFacility]
Expand All @@ -34,24 +38,29 @@ const LocationSelector = () => {
<section data-testid="combo">
<div className={styles.sectionTitle}>{t('visitLocation', 'Visit Location')}</div>
<div className={`${styles.selectContainer} ${styles.sectionField}`}>
<Controller
name="visitLocation"
control={control}
render={({ field: { onBlur, onChange, value } }) => (
<ComboBox
titleText={t('selectLocation', 'Select a location')}
aria-label={t('selectLocation', 'Select a location')}
id="location"
invalidText="Required"
items={locationsToShow}
selectedItem={value}
onChange={({ selectedItem }) => onChange(selectedItem)}
onBlur={onBlur}
itemToString={(loc: Location) => loc?.display}
onInputChange={(loc) => handleSearch(loc)}
/>
)}
/>
{!viewOnlyVisitLocationField ? (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @brandones !
I see that the config prop was renamed but it wasn't updated in here.
I'll create a new PR for this.

Thank you for the changes and review @brandones @denniskigen !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, I'm sorry I missed that. My bad. Thank you Vineet.

<Controller
name="visitLocation"
control={control}
render={({ field: { onBlur, onChange, value } }) => (
<ComboBox
titleText={t('selectLocation', 'Select a location')}
aria-label={t('selectLocation', 'Select a location')}
id="location"
invalidText="Required"
items={locationsToShow}
selectedItem={value}
onChange={({ selectedItem }) => onChange(selectedItem)}
onBlur={onBlur}
itemToString={(loc: Location) => loc?.display}
onInputChange={(loc) => handleSearch(loc)}
disabled={viewOnlyVisitLocationField}
brandones marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
/>
) : (
<p className={styles.bodyShort02}>{session?.sessionLocation?.display}</p>
)}
</div>
</section>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use '@carbon/styles/scss/spacing';
@use '@carbon/styles/scss/type';
@import '~@openmrs/esm-styleguide/src/vars';
@import '../../root.scss';

.container {
margin: spacing.$spacing-05;
Expand Down Expand Up @@ -81,6 +82,11 @@
margin-top: spacing.$spacing-04;
}

.label {
@include type.type-style("label-01");
color: $text-02;
}

:global(.omrs-breakpoint-lt-desktop) {
.container {
& section {
Expand All @@ -99,4 +105,3 @@
}
}
}

2 changes: 2 additions & 0 deletions packages/esm-patient-flags-app/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"editFlags": "Editar banderas",
"enabledFlag": "Bandera activada",
"enablingFlag": "Activando bandera...",
"flagCountfalsemany": "{count} risk flag{plural}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does #1413 solve the issue of this specific translation randomly showing up in unrelated diffs? Perhaps rebasing against main might fix it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually is the wrong key, instead of false, it should be _

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'LL fix this asap

"flagCountfalseone": "{count} bandera de riesgo",
"flagCountfalseother": "{count} banderas de riesgo",
"flagDisabled": "Bandera desactivada",
Expand All @@ -19,6 +20,7 @@
"flagEnabledSuccessfully": "Bandera activada con éxito",
"flagEnableError": "Error al activar la bandera",
"loading": "Cargando",
"matchesForSearchTermfalsemany": "{count} flag{plural}",
"matchesForSearchTermfalseone": "{count} bandera",
"matchesForSearchTermfalseother": "{count} banderas",
"noFlagsFound": "Lo siento, no se encontraron banderas que coincidan con su búsqueda",
Expand Down
Loading