@hisptz/react-ui
Version:
A collection of reusable complex DHIS2 react ui components.
73 lines (67 loc) • 4.2 kB
JavaScript
import { useDataEngine } from "@dhis2/app-runtime";
import i18n from "@dhis2/d2-i18n";
import { DataTable, TableHead, TableBody, DataTableCell, DataTableRow, DataTableColumnHeader } from "@dhis2/ui";
import React from "react";
import Error from "../../../../Shared/Componets/Error/ErrorAPIResult";
import Loader from "../../../../Shared/Componets/Loaders/Loader";
import { displayType, getAllId } from "../../../../Utils/Functions/FunctionDictionary";
import { dateTimeDisplay } from "../../../../Utils/Functions/Shared";
import { useGetIdDetails } from "../../../../Utils/Hooks/FunctionDictionary";
export default function DataSource(_ref) {
var _JSON$stringify, _idDetails, _idDetails2;
let {
json
} = _ref;
const jsonToUse = (_JSON$stringify = JSON.stringify(json)) === null || _JSON$stringify === void 0 ? void 0 : _JSON$stringify.replace(/\s/g, "");
const arrayIdToUse = getAllId(jsonToUse);
const engine = useDataEngine();
const {
loading,
error,
data
} = useGetIdDetails(arrayIdToUse, engine);
if (loading) {
return /*#__PURE__*/React.createElement(Loader, {
text: ""
});
}
if (error) {
return /*#__PURE__*/React.createElement(Error, {
error: error
});
}
if ((data === null || data === void 0 ? void 0 : (_idDetails = data.idDetails) === null || _idDetails === void 0 ? void 0 : _idDetails.length) === 0) {
return /*#__PURE__*/React.createElement(React.Fragment, null);
}
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h3", null, i18n.t("Data Sources"), " "), /*#__PURE__*/React.createElement("p", null, i18n.t("Function have rules calculating from multiple data sources. Here are few data sources observed")), /*#__PURE__*/React.createElement(DataTable, null, /*#__PURE__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(DataTableRow, null, /*#__PURE__*/React.createElement(DataTableColumnHeader, {
bordered: true
}, i18n.t("Id")), /*#__PURE__*/React.createElement(DataTableColumnHeader, {
bordered: true
}, i18n.t("Name")), /*#__PURE__*/React.createElement(DataTableColumnHeader, null, i18n.t("Description")), /*#__PURE__*/React.createElement(DataTableColumnHeader, null, i18n.t("Code")), /*#__PURE__*/React.createElement(DataTableColumnHeader, null, i18n.t("Type")), /*#__PURE__*/React.createElement(DataTableColumnHeader, null, i18n.t("More details")), /*#__PURE__*/React.createElement(DataTableColumnHeader, null, i18n.t("Last updated")))), /*#__PURE__*/React.createElement(TableBody, null, data === null || data === void 0 ? void 0 : (_idDetails2 = data.idDetails) === null || _idDetails2 === void 0 ? void 0 : _idDetails2.map(e => {
var _e$description, _e$code;
return /*#__PURE__*/React.createElement(DataTableRow, {
key: e.id
}, /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, e === null || e === void 0 ? void 0 : e.id), /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, e === null || e === void 0 ? void 0 : e.displayName), /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, (_e$description = e === null || e === void 0 ? void 0 : e.description) !== null && _e$description !== void 0 ? _e$description : "No description"), /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, (_e$code = e === null || e === void 0 ? void 0 : e.code) !== null && _e$code !== void 0 ? _e$code : "no code"), /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, displayType(e === null || e === void 0 ? void 0 : e.href)), /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, /*#__PURE__*/React.createElement("i", null, " ", /*#__PURE__*/React.createElement("a", {
style: {
textDecoration: "none"
},
href: (e === null || e === void 0 ? void 0 : e.href) + ".json",
target: "_blank",
rel: "noreferrer"
}, (e === null || e === void 0 ? void 0 : e.href) + ".json"), " ")), /*#__PURE__*/React.createElement(DataTableCell, {
bordered: true
}, dateTimeDisplay(e === null || e === void 0 ? void 0 : e.lastUpdated)));
}))));
}