-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from EyeSeeTea/poc/use-data-approval-as-plugin
[Proof of Concept] Use data approval as plugin
- Loading branch information
Showing
6 changed files
with
185 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
|
||
type Callback = () => void; | ||
|
||
type UseBooleanReturn = [boolean, UseBooleanActions]; | ||
|
||
interface UseBooleanActions { | ||
set: (newValue: boolean) => void; | ||
toggle: Callback; | ||
enable: Callback; | ||
disable: Callback; | ||
} | ||
|
||
export function useBooleanState(initialValue: boolean): UseBooleanReturn { | ||
const [value, setValue] = React.useState(initialValue); | ||
|
||
const actions = React.useMemo(() => { | ||
return { | ||
set: (newValue: boolean) => setValue(newValue), | ||
enable: () => setValue(true), | ||
disable: () => setValue(false), | ||
toggle: () => setValue(value_ => !value_), | ||
}; | ||
}, [setValue]); | ||
|
||
return [value, actions]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,41 @@ | ||
import React from "react"; | ||
import { LinearProgress } from "@material-ui/core"; | ||
import { useAppContext } from "../../contexts/api-context"; | ||
// @ts-ignore | ||
import { CssVariables } from "@dhis2/ui"; | ||
// @ts-ignore | ||
import { SelectionProvider } from "approval-app/es/selection-context"; | ||
// @ts-ignore | ||
import { AppProvider } from "approval-app/es/app-context"; | ||
// @ts-ignore | ||
import { Layout } from "approval-app/es/app/layout.js"; | ||
// @ts-ignore | ||
import { Display } from "approval-app/es/data-workspace/display"; | ||
// @ts-ignore | ||
import { useSelectionContext } from "approval-app/es/selection-context"; | ||
import { Plugin } from "@dhis2/app-runtime/build/cjs/experimental"; | ||
import { OrganisationUnit } from "../../models/Project"; | ||
|
||
export interface DataApprovalTableProps { | ||
dataSetId: string; | ||
orgUnitId: string; | ||
orgUnit: OrganisationUnit; | ||
period: { startDate: string; endDate: string }; | ||
attributeOptionComboId: string; | ||
} | ||
|
||
const DataApprovalTable: React.FC<DataApprovalTableProps> = props => { | ||
return ( | ||
<> | ||
<CssVariables spacers colors theme /> | ||
export function useDhis2Url(path: string) { | ||
const { api, isDev } = useAppContext(); | ||
return (isDev ? "/dhis2" : api.baseUrl) + path; | ||
} | ||
|
||
<AppProvider> | ||
<SelectionProvider disableHistory={true}> | ||
<DataValuesTableContents {...props} /> | ||
</SelectionProvider> | ||
</AppProvider> | ||
</> | ||
); | ||
export const DataApprovalTable: React.FunctionComponent<DataApprovalTableProps> = props => { | ||
const { config } = useAppContext(); | ||
const pluginBaseUrl = useDhis2Url("/dhis-web-approval/plugin.html"); | ||
|
||
const params = { | ||
dataSet: props.dataSetId, | ||
ou: props.orgUnit.path, | ||
ouDisplayName: props.orgUnit.displayName, | ||
pe: props.period.startDate.replace(/-/g, ""), | ||
wf: config.dataApprovalWorkflows.project.id, | ||
hideSelectors: "true", | ||
filter: `ao:${props.attributeOptionComboId}`, | ||
}; | ||
const pluginUrl = pluginBaseUrl + "#/?" + new URLSearchParams(params).toString(); | ||
|
||
return <Plugin width="1000" pluginSource={pluginUrl} showAlertsInPlugin={true} />; | ||
}; | ||
|
||
const DataValuesTableContents: React.FC<DataApprovalTableProps> = props => { | ||
const { orgUnitId, dataSetId, period, attributeOptionComboId } = props; | ||
const selection = useSelectionContext(); | ||
const isSelectionFilled = selection.orgUnit && selection.period; | ||
|
||
React.useEffect(() => { | ||
if (isSelectionFilled) return; | ||
selection.selectOrgUnit({ id: orgUnitId }); | ||
selection.selectPeriod(period); | ||
selection.selectFilter(`ao:${attributeOptionComboId}`); | ||
}, [selection, isSelectionFilled, orgUnitId, period, attributeOptionComboId]); | ||
|
||
if (!isSelectionFilled) return <LinearProgress />; | ||
|
||
return ( | ||
<Layout.Container> | ||
<Layout.Content> | ||
<Display dataSetId={dataSetId} /> | ||
</Layout.Content> | ||
</Layout.Container> | ||
); | ||
const styles = { | ||
iframe: { border: "none", overflow: "hidden" }, | ||
}; | ||
|
||
export default React.memo(DataApprovalTable); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2820,40 +2820,48 @@ | |
classnames "^2.3.1" | ||
prop-types "^15.7.2" | ||
|
||
"@dhis2/[email protected]": | ||
version "3.2.1" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-3.2.1.tgz#c8c8ec386b1e27502c42c9481eb8b97947bebe7f" | ||
integrity sha512-sQ3PAla1wlp8kzy8hOkhzfDtIP1+0r7pbKB2l9QxfDAlQntOy1aUC3hx8JIPPx5hB9hX1lwf0EPbuYH9zp+LDA== | ||
dependencies: | ||
"@dhis2/app-service-alerts" "3.2.1" | ||
"@dhis2/app-service-config" "3.2.1" | ||
"@dhis2/app-service-data" "3.2.1" | ||
"@dhis2/app-service-offline" "3.2.1" | ||
|
||
"@dhis2/[email protected]": | ||
version "3.2.1" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-alerts/-/app-service-alerts-3.2.1.tgz#7118e157b1b60b6d08df899ed3d2bef6efb056c7" | ||
integrity sha512-XITsLOCVqxl3nFLp5oYbuwuyL9RVvQu1U5z5TXFD4B/9sZE2zdNw9FagzQkQbAWoeiNDVsoHbB4KP7rZhyDQ+Q== | ||
|
||
"@dhis2/[email protected]": | ||
version "3.2.1" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-config/-/app-service-config-3.2.1.tgz#9e915bad721bb4cf6c6f9242ca2d959b21f78a8a" | ||
integrity sha512-AzPrUuQ4MOXEpYUm5iMbCaxkjnzQVej4n5exNirolVEqUaE2NyGYYDqXp0GhxHq/q5QIhbSKqLL8NES/kDOusw== | ||
|
||
"@dhis2/[email protected]": | ||
version "3.2.1" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-data/-/app-service-data-3.2.1.tgz#a0a3df618f99966a3511260c7ceed41cd236d4e7" | ||
integrity sha512-UW3e/Gr/hBNkT/gSlJ/h49rUYJ1ws+6osNZ7Q9hI5JOGHlqPtmKcWhuHfLUMeljRs2Bvan7f5duAycssSddt0A== | ||
"@dhis2/[email protected]": | ||
version "3.10.4" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-3.10.4.tgz#6064ac728770cc94c4d1975db32bd38533655cc6" | ||
integrity sha512-W/d0WcYYcKAeE5/xCunZEMYUSD1fxG+JDQdRDEUsH5y5hB8i/4o2QQrZK8xa19Z3xQJhaW5ypWWqIQVjTJT2Ww== | ||
dependencies: | ||
"@dhis2/app-service-alerts" "3.10.4" | ||
"@dhis2/app-service-config" "3.10.4" | ||
"@dhis2/app-service-data" "3.10.4" | ||
"@dhis2/app-service-offline" "3.10.4" | ||
"@dhis2/app-service-plugin" "3.10.4" | ||
|
||
"@dhis2/[email protected]": | ||
version "3.10.4" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-alerts/-/app-service-alerts-3.10.4.tgz#a7cce660015d79980679175e677cf6c6c3f4c7eb" | ||
integrity sha512-DmSLx/kHOHpgGiL8zG0oa6D3MeCY3wPMDGqj+Gfegr654Lmyf4d2vLI7HSZUSOCdraP/fSYTypsdZmWYoXoLBQ== | ||
|
||
"@dhis2/[email protected]": | ||
version "3.10.4" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-config/-/app-service-config-3.10.4.tgz#2bede4df9b036350200cbc085a2a68439fa4fa0a" | ||
integrity sha512-SCFdNxJKpiBjYsU9s0R+u9GrXjzmUEpGpudmC5eQqNV6ajLiebe/pS2jcSPFzjUtHVQMADk0X8TkERoOBqWcxA== | ||
|
||
"@dhis2/[email protected]": | ||
version "3.10.4" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-data/-/app-service-data-3.10.4.tgz#dcd993a24d2edd97e7ad8a042a682e60582740ff" | ||
integrity sha512-RaoWniioCe33PcPZoDuO66qOrIt0JeeCN8RzmCDrRVGvGmlDTZ3hNuWm9CnsAvO1U6sYDiulKPqrEQu8YKMG0w== | ||
dependencies: | ||
react-query "^3.13.11" | ||
|
||
"@dhis2/app-service-offline@3.2.1": | ||
version "3.2.1" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-offline/-/app-service-offline-3.2.1.tgz#92b6f1c9c15505b6d333adb1623b05ba78879469" | ||
integrity sha512-NmxwwP2udTUvEydxvG+COk0bSmlMU9oaX9ji3UblINUewR93oB+APKAks+pAD9CCK3t6P+npGSUyFpQWyzaQMg== | ||
"@dhis2/app-service-offline@3.10.4": | ||
version "3.10.4" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-offline/-/app-service-offline-3.10.4.tgz#dcdaf3a76c6c7a71f28c89a403ec130bf10fcdf3" | ||
integrity sha512-SUUS+sw3FjR0TMdKSSOVzL8IfPA185gSTHQ1WE4tLc2zE92elvxLL9FuSUuTbu+l1Kr4nRQNLh8muOMWKGnWDg== | ||
dependencies: | ||
lodash "^4.17.21" | ||
|
||
"@dhis2/[email protected]": | ||
version "3.10.4" | ||
resolved "https://registry.yarnpkg.com/@dhis2/app-service-plugin/-/app-service-plugin-3.10.4.tgz#f5412a1320393042012dd75713e3215e51628554" | ||
integrity sha512-GW6xa/5y2yFXvhtLConnaOxKqyu6VPZWRBaQR73/bRRmFcnd7hlMkZ2M0GWSjoW4QHLXlLhXHFsgHPETBftkPg== | ||
dependencies: | ||
post-robot "^10.0.46" | ||
|
||
"@dhis2/[email protected]": | ||
version "1.0.8" | ||
resolved "https://registry.yarnpkg.com/@dhis2/d2-i18n-extract/-/d2-i18n-extract-1.0.8.tgz#9d98690d522a51895c8ef3fe7136f026b0f8dacd" | ||
|
@@ -3757,6 +3765,48 @@ | |
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60" | ||
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA== | ||
|
||
"@krakenjs/belter@^2.0.0": | ||
version "2.5.0" | ||
resolved "https://registry.yarnpkg.com/@krakenjs/belter/-/belter-2.5.0.tgz#c2ead14df28b83b63d5a467e7d5960877f247210" | ||
integrity sha512-c+vOJr5ojEPsH7s28XRLNkUamaXsnyM1Fs7PaYM9tUMnMUILnZ2a3jnOmXZwHYpT0eAciRHddX1333OlCR2e7Q== | ||
dependencies: | ||
"@krakenjs/cross-domain-safe-weakmap" "^2.0.2" | ||
"@krakenjs/cross-domain-utils" "^3.0.2" | ||
"@krakenjs/zalgo-promise" "^2.0.0" | ||
|
||
"@krakenjs/cross-domain-safe-weakmap@^2.0.0", "@krakenjs/cross-domain-safe-weakmap@^2.0.2": | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/@krakenjs/cross-domain-safe-weakmap/-/cross-domain-safe-weakmap-2.0.3.tgz#eb607534c14bd8bc2f3456d993618361fb38489f" | ||
integrity sha512-WsGi6347ddZ9Y0HoBuTYCX2QTAHxYVaUs2T/0n8XJKXZOEJPnLWlW6eYAOgyyuUsYusWMAkYv00fvfxAlTU8/w== | ||
dependencies: | ||
"@krakenjs/cross-domain-utils" "^3.0.2" | ||
|
||
"@krakenjs/cross-domain-utils@^3.0.0", "@krakenjs/cross-domain-utils@^3.0.2": | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/@krakenjs/cross-domain-utils/-/cross-domain-utils-3.1.0.tgz#c4863099acf36f05941345de1381ada1e207315c" | ||
integrity sha512-if+mVTg56ZyLt8wn3ZbTw0IzNjbQvvj5X7lfcBlVfYdZ93TXgHa6Rt9nqdm1rZmvqb8Ct6L29Bp7SNC3xzLfUw== | ||
|
||
"@krakenjs/post-robot@^11.0.0": | ||
version "11.0.0" | ||
resolved "https://registry.yarnpkg.com/@krakenjs/post-robot/-/post-robot-11.0.0.tgz#98a285b70db2bac2c58f297cd8403a4cc2518a6a" | ||
integrity sha512-t+IlQCrwzLa1IWxEvdfr9r/xgOmQoykVQ1rtEukw1LYVHPU3p3eDDC5djODE7ErWYDbkYncrHcbDEh6Gc/G9wQ== | ||
dependencies: | ||
"@krakenjs/belter" "^2.0.0" | ||
"@krakenjs/cross-domain-safe-weakmap" "^2.0.0" | ||
"@krakenjs/cross-domain-utils" "^3.0.0" | ||
"@krakenjs/universal-serialize" "^2.0.0" | ||
"@krakenjs/zalgo-promise" "^2.0.0" | ||
|
||
"@krakenjs/universal-serialize@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@krakenjs/universal-serialize/-/universal-serialize-2.0.0.tgz#c4a508ec53f6b412b1032e78c570b87f4f2c7763" | ||
integrity sha512-Qd9W2iaP5lMTzXPETomBDAaqbgHYkEjJKcQ+3eNC8EwWGCHFk3/+uQ41B+QYfSZqRoz8AEjdNHOps7nDEypAyw== | ||
|
||
"@krakenjs/zalgo-promise@^2.0.0": | ||
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/@krakenjs/zalgo-promise/-/zalgo-promise-2.0.1.tgz#36b4225a566f0a0903a8d771a11a9efc131c6987" | ||
integrity sha512-n30eknZjD7z8/joFqjI8FIDZ0yJPZHcQBce1B3tAumwNZL0C42Ta/w37MfthxHV61JHEFGfy7b727h/kzagJDA== | ||
|
||
"@material-ui/[email protected]": | ||
version "4.12.3" | ||
resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-4.12.3.tgz#80d665caf0f1f034e52355c5450c0e38b099d3ca" | ||
|
@@ -6032,6 +6082,15 @@ bcrypt-pbkdf@^1.0.0: | |
dependencies: | ||
tweetnacl "^0.14.3" | ||
|
||
belter@^1.0.41: | ||
version "1.0.190" | ||
resolved "https://registry.yarnpkg.com/belter/-/belter-1.0.190.tgz#491857550ef240d9c66b56fc637991f5c3089966" | ||
integrity sha512-jz05FHrO+bwitdI6JxV5ESyRdVhTcwMWQ7L4o+q/R4LNJFQrG58sp9EiwsSjhbihhiyYFcmmCMRRagxte6igtw== | ||
dependencies: | ||
cross-domain-safe-weakmap "^1" | ||
cross-domain-utils "^2" | ||
zalgo-promise "^1" | ||
|
||
bfj@^7.0.2: | ||
version "7.0.2" | ||
resolved "https://registry.yarnpkg.com/bfj/-/bfj-7.0.2.tgz#1988ce76f3add9ac2913fd8ba47aad9e651bfbb2" | ||
|
@@ -7249,6 +7308,20 @@ cronstrue@^1.81.0: | |
resolved "https://registry.yarnpkg.com/cronstrue/-/cronstrue-1.110.0.tgz#cffbef09855141e518341ed5a4b575a5a4811638" | ||
integrity sha512-+ABuGZl/nqf/0TemAsPlMSGaB9xEobWhctfRGEqEvH3g6pB/2FGbsUHQPSL8Wt1W3nmOHe1w8GWjacN5k8d3hg== | ||
|
||
cross-domain-safe-weakmap@^1, cross-domain-safe-weakmap@^1.0.1: | ||
version "1.0.29" | ||
resolved "https://registry.yarnpkg.com/cross-domain-safe-weakmap/-/cross-domain-safe-weakmap-1.0.29.tgz#0847975c27d9e1cc840f24c1745311958df98022" | ||
integrity sha512-VLoUgf2SXnf3+na8NfeUFV59TRZkIJqCIATaMdbhccgtnTlSnHXkyTRwokngEGYdQXx8JbHT9GDYitgR2sdjuA== | ||
dependencies: | ||
cross-domain-utils "^2.0.0" | ||
|
||
cross-domain-utils@^2, cross-domain-utils@^2.0.0: | ||
version "2.0.38" | ||
resolved "https://registry.yarnpkg.com/cross-domain-utils/-/cross-domain-utils-2.0.38.tgz#2eaf321c4dfdb61596805ca4233fde4400cb6377" | ||
integrity sha512-zZfi3+2EIR9l4chrEiXI2xFleyacsJf8YMLR1eJ0Veb5FTMXeJ3DpxDjZkto2FhL/g717WSELqbptNSo85UJDw== | ||
dependencies: | ||
zalgo-promise "^1.0.11" | ||
|
||
[email protected], cross-spawn@^7.0.0, cross-spawn@^7.0.2: | ||
version "7.0.3" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" | ||
|
@@ -13861,6 +13934,17 @@ posix-character-classes@^0.1.0: | |
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" | ||
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= | ||
|
||
post-robot@^10.0.46: | ||
version "10.0.46" | ||
resolved "https://registry.yarnpkg.com/post-robot/-/post-robot-10.0.46.tgz#39cea5b51033729390fc7c90be3285cd285f0377" | ||
integrity sha512-EgVJiuvI4iRWDZvzObWes0X/n8olWBEJWxlSw79zmhpgkigX8UsVL4VOBhVtoJKwf0Y9qP9g2zOONw1rv80QbA== | ||
dependencies: | ||
belter "^1.0.41" | ||
cross-domain-safe-weakmap "^1.0.1" | ||
cross-domain-utils "^2.0.0" | ||
universal-serialize "^1.0.4" | ||
zalgo-promise "^1.0.3" | ||
|
||
postcss-attribute-case-insensitive@^4.0.1: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/postcss-attribute-case-insensitive/-/postcss-attribute-case-insensitive-4.0.2.tgz#d93e46b504589e94ac7277b0463226c68041a880" | ||
|
@@ -17417,6 +17501,11 @@ unique-string@^1.0.0: | |
dependencies: | ||
crypto-random-string "^1.0.0" | ||
|
||
universal-serialize@^1.0.4: | ||
version "1.0.10" | ||
resolved "https://registry.yarnpkg.com/universal-serialize/-/universal-serialize-1.0.10.tgz#3279bb30f47290ea479f45135620f98fa9d3f3a6" | ||
integrity sha512-FdouA4xSFa0fudk1+z5vLWtxZCoC0Q9lKYV3uUdFl7DttNfolmiw2ASr5ddY+/Yz6Isr68u3IqC9XMSwMP+Pow== | ||
|
||
universalify@^0.1.0, universalify@^0.1.2: | ||
version "0.1.2" | ||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" | ||
|
@@ -18377,6 +18466,11 @@ yocto-queue@^0.1.0: | |
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" | ||
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== | ||
|
||
zalgo-promise@^1, zalgo-promise@^1.0.11, zalgo-promise@^1.0.3: | ||
version "1.0.48" | ||
resolved "https://registry.yarnpkg.com/zalgo-promise/-/zalgo-promise-1.0.48.tgz#9e33eef502d5ed9f5a09fc5728c833c3e87afa2e" | ||
integrity sha512-LLHANmdm53+MucY9aOFIggzYtUdkSBFxUsy4glTTQYNyK6B3uCPWTbfiGvSrEvLojw0mSzyFJ1/RRLv+QMNdzQ== | ||
|
||
zip-stream@^4.1.0: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-4.1.0.tgz#51dd326571544e36aa3f756430b313576dc8fc79" | ||
|