@iapps/ng-dhis2-ui 1.2.112 → 1.2.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6499,66 +6499,13 @@ const buildReadableFullName = (unit) => {
|
|
|
6499
6499
|
return pathParts.join(' / ');
|
|
6500
6500
|
};
|
|
6501
6501
|
const OrgUnitFormField = (props) => {
|
|
6502
|
-
// const { onSelectOrgUnit, label, required, selected, disabled, key, customOrgUnitRoots } = props;
|
|
6503
|
-
// const d2 = (window as unknown as D2Window)?.d2Web;
|
|
6504
|
-
// const classes = useDynamicStyles(orgUnitFieldStyles);
|
|
6505
|
-
// const config = useMemo(() => {
|
|
6506
|
-
// return d2.systemInfo?.toInitObject();
|
|
6507
|
-
// }, []);
|
|
6508
|
-
// TODO: Improvements
|
|
6509
6502
|
const { onSelectOrgUnit, label, required, selected, disabled, key, field, customOrgUnitRoots, } = props;
|
|
6510
6503
|
const d2 = window?.d2Web;
|
|
6511
6504
|
const classes = useDynamicStyles$2(orgUnitFieldStyles);
|
|
6512
6505
|
const config = useMemo(() => d2.systemInfo?.toInitObject(), []);
|
|
6513
|
-
// TODO: Improvements
|
|
6514
|
-
// New state to hold full orgUnit info from customOrgUnitRoots
|
|
6515
|
-
// const [configuredRootInfo, setConfiguredRootInfo] = useState<
|
|
6516
|
-
// { id: string; name: string; code?: string; path: string; level: number }[]
|
|
6517
|
-
// >([]);
|
|
6518
6506
|
const [configuredRootInfo, setConfiguredRootInfo] = useState([]);
|
|
6519
6507
|
const [configuredRootsLoading, setConfiguredRootsLoading] = useState(false);
|
|
6520
|
-
// Strike-through (fallback) current user roots
|
|
6521
6508
|
const [useCustomRoots, setUseCustomRoots] = useState(customOrgUnitRoots && customOrgUnitRoots.length ? true : false);
|
|
6522
|
-
// TODO: START | Deprecated Approach that doesn't support passing ID of Organisation Unit as root
|
|
6523
|
-
// const rootOrgUnits = useMemo(() => {
|
|
6524
|
-
// return d2.currentUser?.organisationUnits || [];
|
|
6525
|
-
// }, []);
|
|
6526
|
-
// TODO: END | Deprecated Approach that doesn't support passing ID of Organisation Unit as root
|
|
6527
|
-
// TODO: Improvements
|
|
6528
|
-
// Fetch matching configured roots on mount or when key changes:
|
|
6529
|
-
// useEffect(() => {
|
|
6530
|
-
// const matchList =
|
|
6531
|
-
// customOrgUnitRoots?.filter((entry) => entry.field === (field || key)) ||
|
|
6532
|
-
// [];
|
|
6533
|
-
// if (matchList?.length > 0) {
|
|
6534
|
-
// setUseCustomRoots(true);
|
|
6535
|
-
// Promise.all(
|
|
6536
|
-
// (matchList || []).map((entry) =>
|
|
6537
|
-
// d2.httpInstance
|
|
6538
|
-
// .get(
|
|
6539
|
-
// `organisationUnits/${entry.orgUnit}.json?fields=id,displayName,name,code,path,level`
|
|
6540
|
-
// )
|
|
6541
|
-
// .then((res) => {
|
|
6542
|
-
// const u = res.data as OrgUnitResponse;
|
|
6543
|
-
// return {
|
|
6544
|
-
// id: u.id,
|
|
6545
|
-
// name: u.displayName || u.name,
|
|
6546
|
-
// code: u.code,
|
|
6547
|
-
// path: u.path,
|
|
6548
|
-
// level: u.level,
|
|
6549
|
-
// };
|
|
6550
|
-
// })
|
|
6551
|
-
// )
|
|
6552
|
-
// )
|
|
6553
|
-
// .then(setConfiguredRootInfo)
|
|
6554
|
-
// .catch((err) =>
|
|
6555
|
-
// console.warn(
|
|
6556
|
-
// `[OrgUnitFormField] Failed to fetch customOrgUnitRoots:`,
|
|
6557
|
-
// err
|
|
6558
|
-
// )
|
|
6559
|
-
// );
|
|
6560
|
-
// }
|
|
6561
|
-
// }, [customOrgUnitRoots, key, field, d2.httpInstance]);
|
|
6562
6509
|
useEffect(() => {
|
|
6563
6510
|
const matchList = customOrgUnitRoots?.filter((entry) => entry.field === (field || key)) ||
|
|
6564
6511
|
[];
|
|
@@ -6567,7 +6514,7 @@ const OrgUnitFormField = (props) => {
|
|
|
6567
6514
|
setConfiguredRootsLoading(true);
|
|
6568
6515
|
Promise.allSettled(matchList.map(async (orgUnitConfig) => {
|
|
6569
6516
|
try {
|
|
6570
|
-
const orgUnitResponse = await d2.httpInstance.get(`organisationUnits/${orgUnitConfig.orgUnit}.json?fields=id,displayName,name,code,path,level,ancestors[displayName],children[id,displayName,name,code,path,level,ancestors[displayName],children[id,displayName,name,code,path,level,ancestors[displayName]]]&paging=false`);
|
|
6517
|
+
const orgUnitResponse = await d2.httpInstance.get(`organisationUnits/${orgUnitConfig.orgUnit}.json?fields=id,displayName,name,code,path,level,ancestors[displayName],children[id,displayName,name,code,path,level,ancestors[displayName],children[id,displayName,name,code,path,level,ancestors[displayName],children[id,displayName,name,code,path,level,ancestors[displayName]]]]&paging=false`);
|
|
6571
6518
|
const rootOrgUnitData = orgUnitResponse.data;
|
|
6572
6519
|
const allDescendantOrgUnits = flattenChildren([rootOrgUnitData]);
|
|
6573
6520
|
const matchingConfig = customOrgUnitRoots?.find((config) => config.orgUnit === orgUnitConfig.orgUnit);
|
|
@@ -6599,6 +6546,7 @@ const OrgUnitFormField = (props) => {
|
|
|
6599
6546
|
const allFacilities = settledResults
|
|
6600
6547
|
.filter((result) => result.status === 'fulfilled')
|
|
6601
6548
|
.flatMap((result) => result.value);
|
|
6549
|
+
console.log("ALL FACILITIES::: ", allFacilities);
|
|
6602
6550
|
setConfiguredRootInfo(allFacilities);
|
|
6603
6551
|
setConfiguredRootsLoading(false);
|
|
6604
6552
|
})
|
|
@@ -6608,28 +6556,6 @@ const OrgUnitFormField = (props) => {
|
|
|
6608
6556
|
});
|
|
6609
6557
|
}
|
|
6610
6558
|
}, [customOrgUnitRoots, key, field, d2.httpInstance]);
|
|
6611
|
-
// const rootOrgUnits = useMemo(() => {
|
|
6612
|
-
// if (customOrgUnitRoots && customOrgUnitRoots.length > 0) {
|
|
6613
|
-
// return customOrgUnitRoots.map((id) => ({ id }));
|
|
6614
|
-
// }
|
|
6615
|
-
// return d2.currentUser?.organisationUnits || [];
|
|
6616
|
-
// }, [customOrgUnitRoots]);
|
|
6617
|
-
// const getExpandedItems = () => {
|
|
6618
|
-
// if (rootOrgUnits && rootOrgUnits.length === 1) {
|
|
6619
|
-
// return [`/${rootOrgUnits[0].id}`];
|
|
6620
|
-
// } else if (rootOrgUnits?.length > 1) {
|
|
6621
|
-
// return rootOrgUnits.map((root) => root.path);
|
|
6622
|
-
// }
|
|
6623
|
-
// return undefined;
|
|
6624
|
-
// };
|
|
6625
|
-
// TODO: Improvements
|
|
6626
|
-
// Decide which roots to render
|
|
6627
|
-
// const rootOrgUnits = useMemo(() => {
|
|
6628
|
-
// if (useCustomRoots && configuredRootInfo.length > 0) {
|
|
6629
|
-
// return configuredRootInfo.map((u) => u);
|
|
6630
|
-
// }
|
|
6631
|
-
// return d2.currentUser?.organisationUnits || [];
|
|
6632
|
-
// }, [useCustomRoots, configuredRootInfo, d2.currentUser]);
|
|
6633
6559
|
const rootOrgUnits = useMemo(() => {
|
|
6634
6560
|
if (useCustomRoots) {
|
|
6635
6561
|
if (configuredRootsLoading) {
|
|
@@ -6749,9 +6675,6 @@ const OrgUnitFormField = (props) => {
|
|
|
6749
6675
|
onSelectOrgUnit(event.id);
|
|
6750
6676
|
} })));
|
|
6751
6677
|
};
|
|
6752
|
-
const handleBlur = () => {
|
|
6753
|
-
// onBlur && onBlur(null);
|
|
6754
|
-
};
|
|
6755
6678
|
return (config && (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false },
|
|
6756
6679
|
React__default.createElement("div", null,
|
|
6757
6680
|
label && (React__default.createElement("div", { className: classes.orgUnitFieldLabel },
|