Skip to content

Commit

Permalink
Merge pull request #95 from hisptz/bugfix/download-fix
Browse files Browse the repository at this point in the history
fix: download
  • Loading branch information
nnkogift authored Oct 11, 2024
2 parents e1d8be7 + e9d3cd6 commit 9b322de
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@tanstack/react-query": "^4.32.1",
"@tanstack/react-table": "^8.9.3",
"async": "^3.2.4",
"async-es": "^3.2.4",
"async-es": "^3.2.6",
"classnames": "^2.3.2",
"file-saver": "^2.0.5",
"intro.js": "^7.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ModalTitle,
} from "@dhis2/ui";
import { SharingObject } from "../../types/data";
import { FormProvider, useController, useForm } from "react-hook-form";
import { FormProvider, useForm } from "react-hook-form";
import { AccessAdd } from "./components/AccessAdd";
import { AccessList } from "./components/AccessList";
import i18n from "@dhis2/d2-i18n";
Expand Down Expand Up @@ -80,9 +80,6 @@ function getSharingFromSharingObject(data: SharingObject): Partial<Sharing> {
}

export function SharingDialog({ hide, onClose }: SharingDialogProps) {
const { field } = useController({
name: "general.sharing",
});
const { config } = useConfiguration();
const { show } = useAlert(
({ message }) => message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ import React, { useRef, useState } from "react";
import { useDownload } from "./hooks/download";
import { PDFArea } from "./components/PDFArea";
import { useReactToPrint } from "react-to-print";
import { isEmpty } from "lodash";
import { useAlert } from "@dhis2/app-runtime";

export function Download() {
const targetRef = useRef<HTMLDivElement | null>(null);

const { show } = useAlert(
({ message }) => message,
({ type }) => ({
...type,
duration: 3000,
}),
);

const [downloadedData, setDownloadedData] = useState<
Array<Record<string, any>> | undefined
>();
Expand All @@ -30,6 +40,13 @@ export function Download() {
setDownloadStateRef(false);
if (type === "pdf") {
const data = await getDownloadData();
if (isEmpty(data)) {
show({
message: i18n.t("There is no data to download"),
type: { info: true },
});
return;
}
setDownloadedData(data ?? []);
handlePrint();
setTimeout(() => setDownloadedData(undefined), 1000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { SimpleDataTable } from "@hisptz/dhis2-ui";
import { head } from "lodash";
import { head, isEmpty } from "lodash";
import { uid } from "@hisptz/dhis2-utils";
import i18n from "@dhis2/d2-i18n";
import { useDimensions } from "../../../../../../../shared/hooks";
Expand All @@ -22,6 +22,10 @@ export const PDFArea = React.forwardRef<
return null;
}

if (isEmpty(data)) {
return null;
}

const columns = Object.keys(
head<Record<string, any>>(data) as unknown as string,
).map((name) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18n from "@dhis2/d2-i18n";
import { asyncify, mapSeries } from "async";
import { asyncify, mapSeries } from "async-es";
import {
useAlert,
useConfig,
Expand Down Expand Up @@ -198,9 +198,9 @@ const actionQuery = {
resource: "tracker/trackedEntities",
params: ({ program, filter }: any) => {
return {
ouMode: "ALL",
ouMode: "ACCESSIBLE",
program,
filter,
filter: [filter],
paging: false,
fields: [
"trackedEntity",
Expand Down Expand Up @@ -408,7 +408,7 @@ export function useDownload() {
filter: [
`${config?.meta.linkageConfig.trackedEntityAttribute}:eq:${(parent as Event)?.event ?? (parent as TrackedEntity)?.trackedEntity}`,
`${getPeriodQuery(config as Config, period)}`,
],
].join(","),
program: config?.action.id,
},
})) as {
Expand Down
9 changes: 8 additions & 1 deletion src/shared/components/Form/hooks/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,14 @@ export function useFormActions({
if (parent && tei && config) {
const relationship = generateRelationship({
parent: {
id: parent.instance?.enrollment as string,
id:
parent.instance?.enrollment ??
(head(
parent.instance
.enrollments as Array<{
enrollment: string;
}>,
)?.enrollment as string),
},
instance: head(tei.enrollments)
?.enrollment as string,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export function generateMetadataFromConfig(
) {
const { program: categoryProgram, programStages: categoriesProgramStage } =
generateCategoriesMetadata(config.categories, {
linkageConfig: config.meta.linkageConfig,
linkageConfig: config.meta?.linkageConfig,
...meta,
orgUnits: config.general.orgUnit.orgUnits ?? [],
code: config.code,
Expand Down
16 changes: 10 additions & 6 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
declare module "*.css"
declare module "*.js"
declare module '*.png'
declare module '*.svg'
declare module '@dhis2/cypress-commands'
declare module '@dhis2/cypress-plugins'
declare module "*.css";
declare module "*.js";
declare module "*.png";
declare module "*.svg";
declare module "@dhis2/cypress-commands";
declare module "@dhis2/cypress-plugins";

declare module "async-es" {
export * from "async";
}
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4888,10 +4888,10 @@ astral-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==

async-es@^3.2.4:
version "3.2.5"
resolved "https://registry.yarnpkg.com/async-es/-/async-es-3.2.5.tgz#d5855ba36ed87c528e3fad6c3567831ad628ba99"
integrity sha512-oXGVkIf1wSg34CtmK7js8brsxUZWwMGjNa63YJFY+fDHb6RQQd7N0d7N2yP53VaqvXh5DTPuOl0hH+vDFKPHuQ==
async-es@^3.2.6:
version "3.2.6"
resolved "https://registry.yarnpkg.com/async-es/-/async-es-3.2.6.tgz#72073232e38049262bd93445ec2c45c80a9c7e71"
integrity sha512-9C2+oOPd7/EzIeneF4k24o75oY7OcHU/Isl7xIot12EBRwXonyuqKsmxwLuAbFWL6B/FucTQip09xTbiu1CA8A==

async@^2.6.3:
version "2.6.4"
Expand Down Expand Up @@ -6171,9 +6171,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001578, caniuse-lite@^1.0.30001580:
version "1.0.30001581"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001581.tgz#0dfd4db9e94edbdca67d57348ebc070dece279f4"
integrity sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ==
version "1.0.30001663"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001663.tgz"
integrity sha512-o9C3X27GLKbLeTYZ6HBOLU1tsAcBZsLis28wrVzddShCS16RujjHp9GDHKZqrB3meE0YjhawvMFsGb/igqiPzA==

capital-case@^1.0.4:
version "1.0.4"
Expand Down

0 comments on commit 9b322de

Please sign in to comment.