diff --git a/src/app/utils/fetchUtil.ts b/src/app/utils/fetchUtil.ts index 9fa878e..4c96d1e 100644 --- a/src/app/utils/fetchUtil.ts +++ b/src/app/utils/fetchUtil.ts @@ -70,23 +70,41 @@ export async function serverFetchBlob(...args: FetchParams) { let finalUInt8Array = new Uint8Array() let done = false - // Read some more, and call this function again while (!done) { - // Result objects contain two properties: - // done - true if the stream has already given you all its data. - // value - some data. Always undefined when done is true. const read = await reader?.read() + // version 1 if (read?.done) { done = true } else { - // value for fetch streams is a Uint8Array - finalUInt8Array = new Uint8Array(read?.value.length!!) - finalUInt8Array.set(read?.value!!) + const tempUInt8Array = new Uint8Array(finalUInt8Array.length + read?.value.length!!) + tempUInt8Array.set(finalUInt8Array) + tempUInt8Array.set(read?.value!!, finalUInt8Array.length) + finalUInt8Array = new Uint8Array(tempUInt8Array.length!!) + finalUInt8Array.set(tempUInt8Array) + + // console.log("1", finalUInt8Array) } } - // const bodyRead = await reader?.read() + // version 2 & return bodyRead + // const bodyRead = reader?.read().then(function processText({ done, value }): any { + // // Result objects contain two properties: + // // done - true if the stream has already given you all its data. + // // value - some data. Always undefined when done is true. + // if (done) { + // console.log("Stream complete"); + // return { filename: response.headers.get("filename"), blobValue: finalUInt8Array } as T;; + // } + + // // value for fetch streams is a Uint8Array + // finalUInt8Array = new Uint8Array(value.length) + // finalUInt8Array.set(value) + + // console.log(finalUInt8Array) + // // Read some more, and call this function again + // return reader.read().then(processText); + // }) // const bodyValue = bodyRead?.value // const blob = await response.blob() @@ -94,7 +112,7 @@ export async function serverFetchBlob(...args: FetchParams) { // const blobType = await blob.type; // console.log(bodyReader) - // console.log(finalUInt8Array) + // console.log("2", finalUInt8Array) // console.log(bodyValue) return { filename: response.headers.get("filename"), blobValue: finalUInt8Array } as T; diff --git a/src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx b/src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx index 43b5e5d..7aec1c2 100644 --- a/src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx +++ b/src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx @@ -22,7 +22,7 @@ const GenerateEX02ProjectCashFlowReport: React.FC = ({ projects }) => { const searchCriteria: Criterion[] = useMemo( () => [ - { label: t("Project"), paramName: "project", type: "select", options: projectCombo }, + { label: t("Project"), paramName: "project", type: "select", options: projectCombo, needAll: false}, ], [t], ); @@ -32,10 +32,13 @@ const GenerateEX02ProjectCashFlowReport: React.FC = ({ projects }) => { { - const projectIndex = projectCombo.findIndex(project => project === query.project) - const response = await fetchEX02ProjectCashFlowReport({ projectId: projects[projectIndex].id }) - if (response) { - downloadFile(new Uint8Array(response.blobValue), response.filename!!) + + if (query.project.length > 0 && query.project.toLocaleLowerCase() !== "all") { + const projectIndex = projectCombo.findIndex(project => project === query.project) + const response = await fetchEX02ProjectCashFlowReport({ projectId: projects[projectIndex].id }) + if (response) { + downloadFile(new Uint8Array(response.blobValue), response.filename!!) + } } }} /> diff --git a/src/components/SearchBox/SearchBox.tsx b/src/components/SearchBox/SearchBox.tsx index 26914fe..5ea1690 100644 --- a/src/components/SearchBox/SearchBox.tsx +++ b/src/components/SearchBox/SearchBox.tsx @@ -36,6 +36,7 @@ interface TextCriterion extends BaseCriterion { interface SelectCriterion extends BaseCriterion { type: "select"; options: string[]; + needAll?: boolean; } interface DateRangeCriterion extends BaseCriterion { @@ -134,7 +135,7 @@ function SearchBox({ onChange={makeSelectChangeHandler(c.paramName)} value={inputs[c.paramName]} > - {t("All")} + {!(c.needAll === false) && {t("All")}} {c.options.map((option, index) => ( {t(option)}