@hisptz/react-ui
Version:
A collection of reusable complex DHIS2 react ui components.
47 lines (42 loc) • 1.32 kB
JavaScript
import { useDataEngine } from "@dhis2/app-runtime";
import _ from "lodash";
import PropTypes from "prop-types";
import React from "react";
import Error from "../../Shared/Componets/Error/ErrorAPIResult";
import Loader from "../../Shared/Componets/Loaders/Loader";
import { useGetFunctionsDetails } from "../../Utils/Hooks/FunctionDictionary";
import FunctionPage from "./index";
export default function FunctionPage2(_ref) {
var _data$0$rules, _data$;
let {
id
} = _ref;
const engine = useDataEngine();
const functionId = id.split(".")[0];
const ruleId = id.split(".")[1];
const {
loading,
error,
data
} = useGetFunctionsDetails([functionId], engine);
const ruleObj = _.filter((_data$0$rules = (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.rules) !== null && _data$0$rules !== void 0 ? _data$0$rules : [], e => {
return (e === null || e === void 0 ? void 0 : e.id) === ruleId;
});
if (loading) {
return /*#__PURE__*/React.createElement(Loader, {
text: ""
});
}
if (error) {
return /*#__PURE__*/React.createElement(Error, {
error: error
});
}
return /*#__PURE__*/React.createElement(FunctionPage, {
ruleObj: ruleObj[0],
functionObj: data[0]
});
}
FunctionPage2.propTypes = {
id: PropTypes.string.isRequired
};