Skip to content

Commit

Permalink
refactor: renames
Browse files Browse the repository at this point in the history
Renamed files for consistency
  • Loading branch information
nnkogift committed Sep 23, 2024
1 parent 41afee9 commit bf597fd
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 118 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

10 changes: 5 additions & 5 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +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-12T05:03:56.135Z\n"
"PO-Revision-Date: 2024-09-12T05:03:56.135Z\n"
"POT-Creation-Date: 2024-09-16T09:21:02.849Z\n"
"PO-Revision-Date: 2024-09-16T09:21:02.849Z\n"

msgid "Could not determine scorecard's access"
msgstr "Could not determine scorecard's access"
Expand Down Expand Up @@ -71,9 +71,6 @@ msgstr "grid"
msgid "Add New Scorecard"
msgstr "Add New Scorecard"

msgid "Please select at least one organisation unit"
msgstr "Please select at least one organisation unit"

msgid "Organisation Unit"
msgstr "Organisation Unit"

Expand Down Expand Up @@ -411,6 +408,9 @@ msgstr "A data group must have at least one data item"
msgid "A scorecard needs at least one data group"
msgstr "A scorecard needs at least one data group"

msgid "You must select at least one organisation unit"
msgstr "You must select at least one organisation unit"

msgid "Preparing migration..."
msgstr "Preparing migration..."

Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@dhis2/multi-calendar-dates": "^1.2.4",
"@dhis2/ui": "^9.11.0",
"@hisptz/dhis2-analytics": "^2.0.24",
"@hisptz/dhis2-ui": "^2.0.19",
"@hisptz/dhis2-ui": "^2.0.20",
"@hisptz/dhis2-utils": "^2.0.5",
"@hookform/resolvers": "^3.9.0",
"@iapps/function-analytics": "^1.0.0-beta.23",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"list": "list",
"grid": "grid",
"Add New Scorecard": "Add New Scorecard",
"Please select at least one organisation unit": "Please select at least one organisation unit",
"Organisation Unit": "Organisation Unit",
"Select Access": "Select Access",
"Add": "Add",
Expand Down Expand Up @@ -126,6 +125,7 @@
"A scorecard with the title '{{value}}' already exists. Please select another title": "A scorecard with the title '{{value}}' already exists. Please select another title",
"A data group must have at least one data item": "A data group must have at least one data item",
"A scorecard needs at least one data group": "A scorecard needs at least one data group",
"You must select at least one organisation unit": "You must select at least one organisation unit",
"Preparing migration...": "Preparing migration...",
"Migrating scorecards": "Migrating scorecards",
"of": "of",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import i18n from "@dhis2/d2-i18n";
import { colors, IconError24 } from "@dhis2/ui";
import { OrgUnitSelector } from "@hisptz/dhis2-ui";
import { ContainerLoader } from "@scorecard/shared";
import React, { Suspense } from "react";
import { useController } from "react-hook-form";
import { ScorecardConfig } from "@hisptz/dhis2-analytics";


export default function OrgUnit() {
const { field, fieldState } = useController<ScorecardConfig, `orgUnitSelection`>({
name: "orgUnitSelection"
});

return (
<div className="column h-100">
<div className="pt-16 pb-16">
<h3>{i18n.t("Organisation Unit")}</h3>
</div>
{fieldState.error && (
<div
style={{
display: "flex",
gap: 8,
alignItems: "center",
padding: "8px 0",
color: colors.red500
}}
>
<IconError24 />
{fieldState.error?.message}
</div>
)}
<div
style={{ minHeight: 400 }}
className="access-org-unit-filter h-100"
>
<Suspense fallback={<ContainerLoader height={400} />}>
<OrgUnitSelector
showGroups
showLevels
showUserOptions
onUpdate={field.onChange}
value={field.value ?? { orgUnits: [] }}
/>
</Suspense>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Menu, MenuDivider } from "@dhis2/ui";
import React, { Fragment } from "react";
import useAccessManage from "../../../../hooks/useAccessManage";
import SingleSharingComponent from "./Components/SingleSharingComponent";
import SingleSharingComponent from "./components/SingleSharingComponent";

export default function SharingList() {
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import i18n from "@dhis2/d2-i18n";
import React from "react";
import SharingList from "./Components/SharingList";
import AddSharingAccess from "./Components/SharingList/Components/AddSharingAccess";
import SharingList from "./components/SharingList";
import AddSharingAccess from "./components/SharingList/components/AddSharingAccess";


export default function Sharing() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ACCESS_HELP_STEPS, Help } from "@scorecard/shared";
import React from "react";
import OrgUnit from "./Components/OrgUnitFilter";
import Sharing from "./Components/Sharing";
import OrgUnit from "./components/OrgUnitFilter";
import Sharing from "./components/Sharing";

export default function AccessScorecardForm() {
return (
<div
style={{ minHeight: "70vh", height: "100%" }}
style={{ width: "100%", height: "100%" }}
className="container p-16"
>
<Help helpSteps={ACCESS_HELP_STEPS} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function DataSourceConfigurationForm({ path }: { path: string })
/>
<RHFTextInputField
required
type="number"
valueType={DHIS2ValueTypes.NUMBER.name}
label={i18n.t("Weight")}
name={`${path}.weight`}
Expand All @@ -36,6 +37,7 @@ export default function DataSourceConfigurationForm({ path }: { path: string })
<div className="column pr-16 effective-gap-settings">
<RHFTextInputField
valueType={DHIS2ValueTypes.NUMBER.name}
type="number"
label={i18n.t("Effective Gap")}
name={`${path}.effectiveGap`}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import i18n from "@dhis2/d2-i18n";
import { Button, ButtonStrip, IconEdit16, Table, TableBody, TableCell, TableCellHead, TableHead, TableRow, TableRowHead } from "@dhis2/ui";
import { Button, ButtonStrip, colors, IconEdit16, IconError16, Table, TableBody, TableCell, TableCellHead, TableHead, TableRow, TableRowHead, Tooltip } from "@dhis2/ui";
import { Help, HIGHLIGHTED_TABLE_HELP_STEPS } from "@scorecard/shared";
import { IconDelete16 } from "@dhis2/ui-icons";
import { get, isEmpty } from "lodash";
import React, { Fragment } from "react";
import { useController } from "react-hook-form";
import { capitalize, get, isEmpty } from "lodash";
import { FieldError, useController } from "react-hook-form";
import { ScorecardConfig } from "@hisptz/dhis2-analytics";
import { useBoolean } from "usehooks-ts";
import HighlightedDataSourceConfigurationForm from "../HighlightedDataSourceConfigurationForm";
Expand All @@ -30,15 +29,21 @@ function HighlightedTableRow({ index, onRemove }: { index: number; onRemove: (in
name: `highlightedIndicators.${index}`
});

const errorObject = fieldState.error as unknown as Record<string, FieldError> ?? {};

const errorMessage = Object.keys(errorObject).map((key: string) => `${capitalize(key)}: ${errorObject[key]?.message as string}`);

return (
<TableRow
>
{columns?.map(({ path }) => (
{columns?.map(({ path }, index) => (
<TableCell
key={`${index}-${path}`}
>
{get(field.value, path)}
<div style={{ gap: 8 }} className="row align-items-center">
{index === 0 && fieldState.error ? <Tooltip content={errorMessage.join(", ")}><IconError16 color={colors.red500} /></Tooltip> : null}
{get(field.value, path)}
</div>
</TableCell>
))}
<TableCell>
Expand Down
26 changes: 25 additions & 1 deletion packages/app/src/modules/ScorecardManagement/hooks/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ import i18n from "@dhis2/d2-i18n";
import { titleDoesNotExist } from "../components/General/utils/utils";
import { useParams } from "react-router-dom";
import { useDataEngine } from "@dhis2/app-runtime";
import { dataGroupSchema, dataHolderSchema } from "@hisptz/dhis2-analytics";
import { dataGroupSchema, dataHolderSchema, organisationUnitSelectionSchema } from "@hisptz/dhis2-analytics";


function anyOrgUnitSelected({
groups,
levels,
orgUnits,
userOrgUnit,
userSubUnit,
userSubX2Unit
}: any) {
return (
userSubX2Unit ||
userSubUnit ||
userOrgUnit ||
groups.length > 0 ||
levels.length > 0 ||
orgUnits.length > 0
);
}


export function useFormSchema() {
Expand All @@ -23,6 +42,11 @@ export function useFormSchema() {
dataHolders: z.array(dataHolderSchema).min(1, i18n.t("A data group must have at least one data item"))
})).min(1, i18n.t("A scorecard needs at least one data group"))
}),
orgUnitSelection: organisationUnitSelectionSchema.refine((value) => {
return anyOrgUnitSelected(value);
}, {
message: i18n.t("You must select at least one organisation unit")
}),
additionalLabels: z.array(z.string()).optional(),
subtitle: z.string().optional(),
customHeader: z.string().optional(),
Expand Down
Loading

0 comments on commit bf597fd

Please sign in to comment.