Skip to content

Commit

Permalink
refactor: replace useRulesEngineOrgUnit with useReduxOrgUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip committed Oct 17, 2023
1 parent 3ca1205 commit 2748440
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 52 deletions.
4 changes: 2 additions & 2 deletions packages/rules-engine/src/rulesEngine.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ export type OrgUnitGroup = $ReadOnly<{|
code: string,
|}>;

export type OrgUnit = $ReadOnly<{|
export type OrgUnit = $ReadOnly<{
id: string,
name: string,
code: string,
groups: Array<OrgUnitGroup>,
|}>;
}>;

export type RulesEngineInput = {|
programRulesContainer: ProgramRulesContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EnrollmentRegistrationEntryComponent } from './EnrollmentRegistrationEn
import type { OwnProps } from './EnrollmentRegistrationEntry.types';
import { useLifecycle } from './hooks';
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
import { useRulesEngineOrgUnit } from '../../../hooks';
import { useReduxOrgUnit } from '../../../redux/organisationUnits';
import { dataEntryHasChanges } from '../../DataEntry/common/dataEntryHasChanges';
import { useMetadataForRegistrationForm } from '../common/TEIAndEnrollment/useMetadataForRegistrationForm';

Expand All @@ -18,7 +18,7 @@ export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({
...passOnProps
}) => {
const orgUnitId = useCurrentOrgUnitInfo().id;
const { orgUnit, error } = useRulesEngineOrgUnit(orgUnitId);
const { orgUnit, error } = useReduxOrgUnit(orgUnitId);
const { teiId, ready, skipDuplicateCheck } = useLifecycle(selectedScopeId, id, trackedEntityInstanceAttributes, orgUnit);
const {
formId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DataEntry } from './DataEntry/DataEntry.container';
import { EventsList } from './RecentlyAddedEventsList/RecentlyAddedEventsList.container';
import { useScopeTitleText } from '../../../../hooks/useScopeTitleText';
import { useCurrentProgramInfo } from '../../../../hooks/useCurrentProgramInfo';
import { useRulesEngineOrgUnit } from '../../../../hooks/useRulesEngineOrgUnit';
import { useReduxOrgUnit } from '../../../../redux/organisationUnits';
import { useLocationQuery } from '../../../../utils/routing';
import { useRulesEngine } from './useRulesEngine';
import type { PlainProps } from './NewEventDataEntryWrapper.types';
Expand Down Expand Up @@ -48,7 +48,7 @@ const NewEventDataEntryWrapperPlain = ({
}: PlainProps) => {
const { id: programId } = useCurrentProgramInfo();
const orgUnitId = useLocationQuery().orgUnitId;
const { orgUnit, error } = useRulesEngineOrgUnit(orgUnitId);
const { orgUnit, error } = useReduxOrgUnit(orgUnitId);
const rulesReady = useRulesEngine({ programId, orgUnit, formFoundation });
const titleText = useScopeTitleText(programId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useScopeInfo } from '../../../hooks/useScopeInfo';
import { scopeTypes } from '../../../metaData';
import { TrackedEntityInstanceDataEntry } from '../TrackedEntityInstance';
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
import { useReduxOrgUnit } from '../../../redux/organisationUnits';
import type { Props, PlainProps } from './TeiRegistrationEntry.types';
import { DiscardDialog } from '../../Dialogs/DiscardDialog.component';
import { withSaveHandler } from '../../DataEntry';
Expand Down Expand Up @@ -54,7 +55,9 @@ const TeiRegistrationEntryPlain =
const [showWarning, setShowWarning] = useState(false);
const { scopeType } = useScopeInfo(selectedScopeId);
const { formId, formFoundation } = useMetadataForRegistrationForm({ selectedScopeId });
const orgUnit = useCurrentOrgUnitInfo();
const { id: orgUnitId } = useCurrentOrgUnitInfo();
const { orgUnit } = useReduxOrgUnit(id); // [DHIS2-15814] Change this to new hook
const orgUnitName = orgUnit ? orgUnit.name : '';

const handleOnCancel = () => {
if (!isUserInteractionInProgress) {
Expand All @@ -68,9 +71,9 @@ const TeiRegistrationEntryPlain =
const url =
scopeType === scopeTypes.TRACKER_PROGRAM
?
buildUrlQueryString({ programId: selectedScopeId, orgUnitId: orgUnit.id })
buildUrlQueryString({ programId: selectedScopeId, orgUnitId })
:
buildUrlQueryString({ orgUnitId: orgUnit.id });
buildUrlQueryString({ orgUnitId });
return push(`/?${url}`);
};

Expand Down Expand Up @@ -114,7 +117,7 @@ const TeiRegistrationEntryPlain =
</Button>
</div>
<InfoIconText>
{translatedTextWithStylesForTei(trackedEntityName.toLowerCase(), orgUnit.name)}
{translatedTextWithStylesForTei(trackedEntityName.toLowerCase(), orgUnitName)}
</InfoIconText>

<DiscardDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
updateTeiDisplayName,
} from '../EnrollmentPage.actions';
import { useTrackerProgram } from '../../../../hooks/useTrackerProgram';
import { useRulesEngineOrgUnit } from '../../../../hooks/useRulesEngineOrgUnit';
import { useReduxOrgUnit } from '../../../../redux/organisationUnits';
import { EnrollmentPageDefaultComponent } from './EnrollmentPageDefault.component';
import {
useProgramMetadata,
Expand All @@ -33,7 +33,7 @@ export const EnrollmentPageDefault = () => {
const history = useHistory();
const dispatch = useDispatch();
const { enrollmentId, programId, teiId, orgUnitId } = useLocationQuery();
const { orgUnit, error } = useRulesEngineOrgUnit(orgUnitId);
const { orgUnit, error } = useReduxOrgUnit(orgUnitId);

const program = useTrackerProgram(programId);
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useCommonEnrollmentDomainData, useRuleEffects } from '../../common/Enro
import type { Props } from './ProgramStageSelector.types';
import { useProgramFromIndexedDB } from '../../../../utils/cachedDataHooks/useProgramFromIndexedDB';
import { useLocationQuery, buildUrlQueryString } from '../../../../utils/routing';
import { useRulesEngineOrgUnit } from '../../../../hooks/useRulesEngineOrgUnit';
import { useReduxOrgUnit } from '../../../../redux/organisationUnits';
import { useTrackerProgram } from '../../../../hooks/useTrackerProgram';


Expand All @@ -24,7 +24,7 @@ export const ProgramStageSelector = ({ programId, orgUnitId, teiId, enrollmentId
isError: programError,
} = useProgramFromIndexedDB(programId);

const { orgUnit } = useRulesEngineOrgUnit(orgUnitId);
const { orgUnit } = useReduxOrgUnit(orgUnitId);
const programRules = useTrackerProgram(programId);

const ruleEffects = useRuleEffects({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ViewEventSectionHeader } from '../Section/ViewEventSectionHeader.compon
import { EditEventDataEntry } from '../../../WidgetEventEdit/EditEventDataEntry/EditEventDataEntry.container';
import { ViewEventDataEntry } from '../../../WidgetEventEdit/ViewEventDataEntry/ViewEventDataEntry.container';
import type { ProgramStage } from '../../../../metaData';
import { useRulesEngineOrgUnit } from '../../../../hooks/useRulesEngineOrgUnit';
import { useReduxOrgUnit } from '../../../../redux/organisationUnits';
import { NoticeBox } from '../../../NoticeBox';

const getStyles = () => ({
Expand Down Expand Up @@ -60,7 +60,7 @@ const EventDetailsSectionPlain = (props: Props) => {
eventAccess,
...passOnProps } = props;
const orgUnitId = useSelector(({ viewEventPage }) => viewEventPage.loadedValues?.orgUnit?.id);
const { orgUnit, error } = useRulesEngineOrgUnit(orgUnitId);
const { orgUnit, error } = useReduxOrgUnit(orgUnitId);

if (error) {
return error.errorComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { spacersNum, Button, colors, IconEdit24, IconArrowLeft24 } from '@dhis2/
import { withStyles } from '@material-ui/core';
import i18n from '@dhis2/d2-i18n';
import { ConditionalTooltip } from 'capture-core/components/ConditionalTooltip';
import { useEnrollmentEditEventPageMode, useRulesEngineOrgUnit, useAvailableProgramStages } from 'capture-core/hooks';
import { useEnrollmentEditEventPageMode, useAvailableProgramStages } from 'capture-core/hooks';
import { useReduxOrgUnit } from 'capture-core/redux/organisationUnits';
import type { Props } from './widgetEventEdit.types';
import { startShowEditEventDataEntry } from './WidgetEventEdit.actions';
import { Widget } from '../Widget';
Expand Down Expand Up @@ -59,7 +60,7 @@ export const WidgetEventEditPlain = ({
}: Props) => {
const dispatch = useDispatch();
const { currentPageMode } = useEnrollmentEditEventPageMode(eventStatus);
const { orgUnit, error } = useRulesEngineOrgUnit(orgUnitId);
const { orgUnit, error } = useReduxOrgUnit(orgUnitId);

const eventAccess = getProgramEventAccess(programId, programStage.id);
const availableProgramStages = useAvailableProgramStages(programStage, teiId, enrollmentId, programId);
Expand Down
1 change: 0 additions & 1 deletion src/core_modules/capture-core/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export { useSearchOptions } from './useSearchOptions';
export { useTrackedEntityTypesWithCorrelatedPrograms } from './useTrackedEntityTypesWithCorrelatedPrograms';
export { useCurrentTrackedEntityTypeId } from './useCurrentTrackedEntityTypeId';
export { useEnrollmentEditEventPageMode } from './useEnrollmentEditEventPageMode';
export { useRulesEngineOrgUnit } from './useRulesEngineOrgUnit';
export { useAvailableProgramStages } from './useAvailableProgramStages';
export { useScopeInfo } from './useScopeInfo';
export { useScopeTitleText } from './useScopeTitleText';
33 changes: 0 additions & 33 deletions src/core_modules/capture-core/hooks/useRulesEngineOrgUnit.js

This file was deleted.

0 comments on commit 2748440

Please sign in to comment.