Skip to content

Commit

Permalink
fix: sharing.ts
Browse files Browse the repository at this point in the history
Fixed issues with sharing
  • Loading branch information
nnkogift committed Oct 1, 2024
1 parent 17a4006 commit 62f3305
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 21,532 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.

7 changes: 5 additions & 2 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-10-01T11:27:30.817Z\n"
"PO-Revision-Date: 2024-10-01T11:27:30.817Z\n"
"POT-Creation-Date: 2024-10-01T15:40:19.258Z\n"
"PO-Revision-Date: 2024-10-01T15:40:19.258Z\n"

msgid "Scorecard deleted successfully"
msgstr "Scorecard deleted successfully"
Expand Down Expand Up @@ -489,6 +489,9 @@ msgstr "Migrated"
msgid "Failed"
msgstr "Failed"

msgid "Only the scorecard's owner can migrate their scorecards"
msgstr "Only the scorecard's owner can migrate their scorecards"

msgid "Back"
msgstr "Back"

Expand Down
1 change: 1 addition & 0 deletions packages/app/src/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"Success": "Success",
"Migrated": "Migrated",
"Failed": "Failed",
"Only the scorecard's owner can migrate their scorecards": "Only the scorecard's owner can migrate their scorecards",
"Back": "Back",
"Scorecards to migrate": "Scorecards to migrate",
"Select the scorecards configuration that you would like to migrate": "Select the scorecards configuration that you would like to migrate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import { ScorecardConfig } from "@hisptz/dhis2-analytics";
import { useController } from "react-hook-form";

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


console.log({
sharing: field.value
});

return (
<div style={{ gap: 16 }} className="column h-100">
<div className="pt-16 pb-16">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tab, TabBar, Tooltip } from "@dhis2/ui";
import { colors, IconErrorFilled16, Tab, TabBar, Tooltip } from "@dhis2/ui";
import { useLocation, useNavigate } from "react-router-dom";
import { getCurrentStepId, getStep, steps } from "../constants/steps";
import { useCallback, useMemo } from "react";
Expand All @@ -8,7 +8,7 @@ import i18n from "@dhis2/d2-i18n";


function StepTab({ id }: { id: string }) {
const { trigger } = useFormContext();
const { trigger, formState } = useFormContext();
const { show } = useAlert(({ message }) => message, ({ type }) => ({ ...type, duration: 3000 }));
const navigate = useNavigate();
const location = useLocation();
Expand All @@ -26,8 +26,10 @@ function StepTab({ id }: { id: string }) {
}
}, [location]);

const hasErrors = Object.keys(formState.errors).some((key) => step.fieldIds.includes(key));

return (
<Tab onClick={onStepClick} selected={active}>
<Tab icon={hasErrors ? (<IconErrorFilled16 color={colors.red500} />) : undefined} onClick={onStepClick} selected={active}>
<Tooltip
content={step.tooltip}
key={`${step.id}-step`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function SaveButton() {
});
navigate(`/view/${config.id}`);
} catch (err) {

//Error is already shown in the save function.
}
};
Expand Down
11 changes: 6 additions & 5 deletions packages/app/src/modules/ScorecardManagement/constants/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const steps: FormStep[] = [
"customHeader",
"additionalLabels",
"legendDefinitions"
]as const
] as const
},
{
label: i18n.t("Data Configuration"),
Expand All @@ -47,7 +47,7 @@ export const steps: FormStep[] = [
id: "dataConfiguration",
fieldIds: [
"dataSelection"
]as const
] as const
},
{
label: i18n.t("Highlighted Indicators"),
Expand All @@ -59,7 +59,7 @@ export const steps: FormStep[] = [
id: "highlightedIndicators",
fieldIds: [
"highlightedIndicators"
]as const
] as const
},
{
label: i18n.t("Access"),
Expand All @@ -70,8 +70,9 @@ export const steps: FormStep[] = [
),
id: "access",
fieldIds: [
"orgUnitSelection"
]as const
"orgUnitSelection",
"sharing"
] as const
},
{
label: i18n.t("Options"),
Expand Down
12 changes: 8 additions & 4 deletions packages/app/src/modules/ScorecardManagement/hooks/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { uid } from "@hisptz/dhis2-utils";
import i18n from "@dhis2/d2-i18n";
import { ScorecardConfig } from "@hisptz/dhis2-analytics";
import { useRecoilValue } from "recoil";
import { getSharingSettingsFromOldConfiguration } from "../../../utils/sharing";
import { getSharingSettingsFromOldConfiguration, ScorecardConfigWithOldSharing } from "../../../utils/sharing";

const query: any = {
scorecard: {
Expand Down Expand Up @@ -103,7 +103,8 @@ export default function useScorecardFormMetadata() {
});
const schema = useFormSchema();
const form = useForm<ScorecardConfig>({
shouldFocusError: true,
shouldFocusError: false,
progressive: true,
defaultValues: async () => {
if (id) {
const scorecardDefaultValues = await getScorecard() as { scorecard: ScorecardConfig };
Expand All @@ -115,7 +116,10 @@ export default function useScorecardFormMetadata() {
defaultValue.sharing = getSharingSettingsFromOldConfiguration(defaultValue as any);
}

console.log(defaultValue);

console.log({
defaultValue
});

return defaultValue;
}
Expand All @@ -128,6 +132,6 @@ export default function useScorecardFormMetadata() {

return {
form,
access: data ? getUserAuthority(user, data?.scorecard.sharing ?? getSharingSettingsFromOldConfiguration(data?.scorecard)) : undefined
access: data ? getUserAuthority(user, data?.scorecard.sharing ?? getSharingSettingsFromOldConfiguration(data?.scorecard as ScorecardConfigWithOldSharing)) : undefined
};
}
1 change: 1 addition & 0 deletions packages/app/src/modules/ScorecardManagement/hooks/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function useSaveScorecard() {
}
} catch (e: any) {
show({ message: `${i18n.t("Error saving scorecard")}: ${e.message}`, type: { critical: true } });
throw e;
}
}, [id]);
const saveSilently = useCallback(async (config: ScorecardConfig) => {
Expand Down
9 changes: 7 additions & 2 deletions packages/app/src/modules/ScorecardManagement/hooks/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import i18n from "@dhis2/d2-i18n";
import { checkTitleAvailability } from "../components/General/utils/utils";
import { useParams } from "react-router-dom";
import { useDataEngine } from "@dhis2/app-runtime";
import { dataGroupSchema, dataHolderSchema, organisationUnitSelectionSchema } from "@hisptz/dhis2-analytics";
import { dataGroupSchema, dataHolderSchema, organisationUnitSelectionSchema, scorecardSharing, scorecardViewOptionsSchema } from "@hisptz/dhis2-analytics";


function anyOrgUnitSelected({
Expand Down Expand Up @@ -48,6 +48,11 @@ export function useFormSchema() {
additionalLabels: z.array(z.string()).optional(),
subtitle: z.string().optional(),
customHeader: z.string().optional(),
description: z.string().optional()
description: z.string().optional(),
options: scorecardViewOptionsSchema.extend({
arrows: z.boolean().optional(),
showDataInRows: z.boolean().optional()
}),
sharing: scorecardSharing
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ export function MigrateButton({ scorecards, selected, onProgressUpdate, onClearS
setLoading(false);
}, [selected, scorecards, onProgressUpdate, goToNextStep, migrate]);

const countString = count === 0 ? "" : `${count}`;

return (
<Button loading={loading} onClick={onMigrateClick} primary disabled={count === 0}>
{loading ? i18n.t("Migrating scorecard(s)... ({{progress}}/{{count}})", {
count,
progress: value
}) : i18n.t("Migrate {{count}} scorecard(s)", {
count: count === 0 ? "" : `${count}`
count: countString as any
})}
</Button>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/utils/sharing.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ScorecardConfig, ScorecardSharing } from "@hisptz/dhis2-analytics";
import { fromPairs } from "lodash";

export type ScorecardConfigWithOldSharing = ScorecardConfig & { user: { id: string }, publicAccess: { access: string; }; userAccesses: Array<{ id: string; access: string; }>; userGroupAccesses: Array<{ id: string; access: string; }> };

export function getSharingSettingsFromOldConfiguration({ user, publicAccess, userGroupAccesses, userAccesses }: ScorecardConfig & { user: { id: string }, publicAccess: { access: string; }; userAccesses: Array<{ id: string; access: string; }>; userGroupAccesses: Array<{ id: string; access: string; }> }): ScorecardSharing {
export function getSharingSettingsFromOldConfiguration({ user, publicAccess, userGroupAccesses, userAccesses }: ScorecardConfigWithOldSharing): ScorecardSharing {

return {
owner: user?.id ?? "",
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"dependencies": {
"@dhis2/multi-calendar-dates": "^1.2.4",
"@dhis2/ui": "^9.10.2",
"@hisptz/dhis2-analytics": "file:../../../dhis2-utils-v2/packages/analytics",
"@hisptz/dhis2-ui": "file:../../../dhis2-utils-v2/packages/ui",
"@hisptz/dhis2-utils": "file:../../../dhis2-utils-v2/packages/utils",
"@hisptz/dhis2-analytics": "^2.0.32",
"@hisptz/dhis2-ui": "^2.0.25",
"@hisptz/dhis2-utils": "^2.0.8",
"@material-ui/icons": "^4.11.2",
"jquery": "^3.6.4",
"lodash": "^4.17.21",
Expand Down
6 changes: 4 additions & 2 deletions packages/shared/src/utils/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function getScorecardPublicAccess(oldScorecardUserGroups: OldUserGroup[]) {
};
}

function getScorecardUserGroupAccesses(oldScorecardUserGroups: OldUserGroup[]): Record<string, { id: string; access: string }> {
function getScorecardUserGroupAccesses(oldScorecardUserGroups: OldUserGroup[]): Record<string, { id: string; access: string; name: string; displayName: string; }> {
const userGroupsOnly = oldScorecardUserGroups?.filter(
(userGroup) => userGroup.id !== "all"
);
Expand All @@ -228,7 +228,9 @@ function getScorecardUserGroupAccesses(oldScorecardUserGroups: OldUserGroup[]):
userGroup.id,
{
id: userGroup?.id,
access: getScorecardAccess(userGroup)
access: getScorecardAccess(userGroup),
name: userGroup.name,
displayName: userGroup.name
}
];
}));
Expand Down
Loading

0 comments on commit 62f3305

Please sign in to comment.