Skip to content

Commit

Permalink
feat: migration
Browse files Browse the repository at this point in the history
Added schema for old scorecard configuration
  • Loading branch information
nnkogift committed Sep 30, 2024
1 parent 0ba5af8 commit 5f12a84
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 57 deletions.
6 changes: 0 additions & 6 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-09-24T10:31:52.171Z\n"
"PO-Revision-Date: 2024-09-24T10:31:52.171Z\n"

msgid "Could not determine scorecard's access"
msgstr "Could not determine scorecard's access"
"POT-Creation-Date: 2024-09-24T12:03:10.128Z\n"
"PO-Revision-Date: 2024-09-24T12:03:10.128Z\n"

msgid "Scorecard deleted successfully"
msgstr "Scorecard deleted successfully"
Expand Down
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"@dhis2/app-service-datastore": "^1.0.0-alpha.2",
"@dhis2/multi-calendar-dates": "^1.2.4",
"@dhis2/ui": "^9.11.0",
"@hisptz/dhis2-analytics": "^2.0.26",
"@hisptz/dhis2-ui": "^2.0.21",
"@hisptz/dhis2-analytics": "^2.0.30",
"@hisptz/dhis2-ui": "^2.0.23",
"@hisptz/dhis2-utils": "^2.0.5",
"@hookform/resolvers": "^3.9.0",
"@iapps/function-analytics": "^1.0.0-beta.23",
Expand Down
1 change: 0 additions & 1 deletion packages/app/src/locales/en/translations.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"Could not determine scorecard's access": "Could not determine scorecard's access",
"Scorecard deleted successfully": "Scorecard deleted successfully",
"Confirm scorecard delete": "Confirm scorecard delete",
"Are you sure you want to delete scorecard ": "Are you sure you want to delete scorecard ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { RHFDHIS2FormField } from "@hisptz/dhis2-ui";
import React, { useMemo } from "react";
import { useWatch } from "react-hook-form";

export default function TargetsField(props: any) {
export default function TargetsField(props: { name: string; path: string; }) {
const { name, path } = props ?? {};
const [legendDefinitions, highIsGood] = useWatch({
name: [`legendDefinitions`, `${path}.highIsGood`],
name: [`legendDefinitions`, `${path}.highIsGood`]
});
const nonDefaultLegendDefinitions = useMemo(
() =>
legendDefinitions.filter(
(legendDefinition: any) => !legendDefinition.isDefault,
(legendDefinition: any) => !legendDefinition.isDefault
),
[legendDefinitions],
[legendDefinitions]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export default function DataSourceSelectorModal({
"indicator",
"dataElement",
"dataSet",
"programIndicator",
"customFunction"
"programIndicator"
]}
selected={selectedItems}
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function PreviewScorecardTable() {
const columns = useMemo(() => [...dataGroups], [dataGroups]);
return (
<div className="column" style={{ width: "100%", overflowX: "auto" }}>
<DataTable bordered width={"100%"}>
<DataTable width={"100%"}>
<DataTableHead>
<DataTableRow>
<DataTableCell
Expand Down Expand Up @@ -63,7 +63,7 @@ export default function PreviewScorecardTable() {
{dataSources.length > 1 &&
`/${dataSources?.[1]?.label}`}
</DataTableCell>
),
)
)}
</tr>
</table>
Expand All @@ -72,7 +72,7 @@ export default function PreviewScorecardTable() {
</DataTableRow>
</DataTableHead>
<DataTableBody>
<DataTableRow bordered>
<DataTableRow>
<DataTableCell
width={"100%"}
className={"min-width-200"}
Expand All @@ -92,8 +92,8 @@ export default function PreviewScorecardTable() {
>
<table
style={{
borders: "none",
borderSpacing: 0,
border: "none",
borderSpacing: 0
}}
>
<DataTableRow>
Expand All @@ -103,7 +103,7 @@ export default function PreviewScorecardTable() {
key={config.id}
config={config}
/>
),
)
)}
</DataTableRow>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default function DataConfigurationScorecardForm() {
<div className="col-md-8 p-16 h-100">
<Suspense fallback={<ContainerLoader />}>
<PreviewArea />
<InstructionArea />
</Suspense>
<InstructionArea />
</div>
</div>
</SelectedDataStateProvider>
Expand Down
89 changes: 89 additions & 0 deletions packages/app/src/modules/ScorecardMigration/schemas/old.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { z } from "zod";


const oldLegendSet = z.object({
color: z.string(),
max: z.union([z.string(), z.number()]),
min: z.union([z.string(), z.number()])
});

const oldIndicator = z.object({
id: z.string(),
title: z.string(),
type: z.string().optional(),
weight: z.number().optional(),
legendset: z.array(oldLegendSet),
high_is_good: z.boolean().optional(),
legend_display: z.boolean().optional(),
arrow_settings: z.object({
effective_gap: z.number().optional(),
display: z.boolean().optional()
})

});

const oldIndicatorHolder = z.object({
holder_id: z.union([z.string(), z.number()]),
indicators: z.array(oldIndicator)
});

const oldIndicatorGroup = z.object({
id: z.string(),
style: z.object({
color: z.string().optional(),
backgroundColor: z.string().optional()
}).optional(),
name: z.string().optional(),
title: z.string().optional(),
indicator_holder_ids: z.array(z.number())
});

const oldDataSourceSchema = z.object({
title: z.string(),
id: z.string(),
weight: z.number(),
legends: z.array(z.object({
min: z.union([z.string(), z.number()]),
max: z.union([z.string(), z.number()]),
color: z.string()
})),
high_is_good: z.boolean().optional(),
legend_display: z.boolean().optional(),
arrow_settings: z.object({
display: z.boolean().optional(),
effective_gap: z.boolean().optional()
})

});

export const oldScorecardSchema = z.object({
id: z.string(),
header: z.object({
title: z.string(),
sub_title: z.string(),
description: z.string(),
template: z.object({
content: z.string(),
display: z.boolean().optional()
})
}),
legendset_definitions: z.array(z.object({
color: z.string(),
definition: z.string(),
default: z.boolean().optional()
})),
empty_rows: z.boolean().optional(),
show_average_in_row: z.boolean().optional(),
average_selection: z.string().optional(),
highlighted_indicators: z.object({
display: z.boolean().optional(),
definitions: z.array(oldDataSourceSchema).optional()
}),
data_settings: z.object({
indicator_holder_groups: oldIndicatorGroup,
indicator_holders: z.array(oldIndicatorHolder)
}),
user: z.object({
id: z.string()
}),
});
41 changes: 11 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2933,14 +2933,14 @@
dependencies:
"@hapi/hoek" "^9.0.0"

"@hisptz/dhis2-analytics@^2.0.26":
version "2.0.26"
resolved "https://registry.yarnpkg.com/@hisptz/dhis2-analytics/-/dhis2-analytics-2.0.26.tgz#dd9e19bce64e21b12c9cc6cf091b4bd7bcd7eff9"
integrity sha512-38kPtxNbKKBEXBw3IYiqVT1DZ/1xr6IotK6Pz5g+Np8I4gWS1BH33wZj/p+r0WoZ9KhAn+9QkCD+HtTpILGCbA==
"@hisptz/dhis2-analytics@^2.0.30":
version "2.0.30"
resolved "https://registry.yarnpkg.com/@hisptz/dhis2-analytics/-/dhis2-analytics-2.0.30.tgz#c72c7bcf0482555b6fe6ef30ac09b0e04907dec0"
integrity sha512-oauHazfBDZI3N5g9GtquQY1rAbbBd8YbGjg18lo9mBDywUkwbCxDxTdzZoWEd9MJSO5vtAAQjlWj3Tojr7r6+A==
dependencies:
"@dnd-kit/core" "^6.1.0"
"@dnd-kit/utilities" "^3.2.2"
"@hisptz/dhis2-ui" "2.0.20"
"@hisptz/dhis2-ui" "2.0.23"
"@hisptz/dhis2-utils" "2.0.7"
"@react-leaflet/core" "^2.1.0"
"@tanstack/react-table" "^8.19.3"
Expand All @@ -2963,7 +2963,7 @@
zod "^3.23.8"

"@hisptz/dhis2-analytics@file:../dhis2-utils-v2/packages/analytics":
version "2.0.27"
version "2.0.30"
dependencies:
"@dnd-kit/core" "^6.1.0"
"@dnd-kit/utilities" "^3.2.2"
Expand All @@ -2989,29 +2989,10 @@
screenfull "^6.0.2"
zod "^3.23.8"

"@hisptz/[email protected]":
version "2.0.20"
resolved "https://registry.yarnpkg.com/@hisptz/dhis2-ui/-/dhis2-ui-2.0.20.tgz#8de46a996da429d1231f457df8da1f253bcd2911"
integrity sha512-oIleodTExiSKjs6LyByoIgYDwtPGpLrNAi6oGNnfS7vhkF+TPMxPznHWaH4nnwegs4/u+4oyAaJPp3qW/jBqwA==
dependencies:
"@hisptz/dhis2-utils" "2.0.7"
classnames "^2.5.1"
dexie "^3.2.3"
jodit-react "^1.3.39"
lodash "^4.17.21"
luxon "^3.4.4"
react-circular-progressbar "^2.1.0"
react-collapsible "^2.10.0"
react-color "^2.19.3"
react-hook-form "^7.53.0"
recoil "^0.7.7"
styled-components "^6.1.8"
usehooks-ts "^2.9.2"

"@hisptz/dhis2-ui@^2.0.21":
version "2.0.21"
resolved "https://registry.yarnpkg.com/@hisptz/dhis2-ui/-/dhis2-ui-2.0.21.tgz#2ec08aab084b4e04ec4a87e430a6635af2c7bafa"
integrity sha512-Ux72DMxCkdIzVEW1fD/KELI+hu5G/JUYkArbMBT4FMc0fkui4A6d7ENTAZikvmewzqIftBiflZjj9b5l74G4ww==
"@hisptz/[email protected]", "@hisptz/dhis2-ui@^2.0.23":
version "2.0.23"
resolved "https://registry.yarnpkg.com/@hisptz/dhis2-ui/-/dhis2-ui-2.0.23.tgz#699bbfa03ed9235c220caacb9682645e54d215a2"
integrity sha512-TJgPnEh0uuJzErS59bBmU9ylj5ydOVIL16RtcBMKcWk6uX3B6QCESdLTVKCfuJj6L/0ukRyDFNlVFKrzm2qfOg==
dependencies:
"@hisptz/dhis2-utils" "2.0.7"
classnames "^2.5.1"
Expand All @@ -3028,7 +3009,7 @@
usehooks-ts "^2.9.2"

"@hisptz/dhis2-ui@file:../dhis2-utils-v2/packages/ui":
version "2.0.21"
version "2.0.23"
dependencies:
"@hisptz/dhis2-utils" "workspace:*"
classnames "^2.5.1"
Expand Down

0 comments on commit 5f12a84

Please sign in to comment.