Ver código fonte

update

tags/Baseline_30082024_FRONTEND_UAT
cyril.tsui 1 ano atrás
pai
commit
1c3cfafe5b
3 arquivos alterados com 37 adições e 15 exclusões
  1. +27
    -9
      src/app/utils/fetchUtil.ts
  2. +8
    -5
      src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx
  3. +2
    -1
      src/components/SearchBox/SearchBox.tsx

+ 27
- 9
src/app/utils/fetchUtil.ts Ver arquivo

@@ -70,23 +70,41 @@ export async function serverFetchBlob<T>(...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<T>(...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;


+ 8
- 5
src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx Ver arquivo

@@ -22,7 +22,7 @@ const GenerateEX02ProjectCashFlowReport: React.FC<Props> = ({ projects }) => {

const searchCriteria: Criterion<SearchParamNames>[] = 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<Props> = ({ projects }) => {
<SearchBox
criteria={searchCriteria}
onSearch={async (query) => {
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!!)
}
}
}}
/>


+ 2
- 1
src/components/SearchBox/SearchBox.tsx Ver arquivo

@@ -36,6 +36,7 @@ interface TextCriterion<T extends string> extends BaseCriterion<T> {
interface SelectCriterion<T extends string> extends BaseCriterion<T> {
type: "select";
options: string[];
needAll?: boolean;
}

interface DateRangeCriterion<T extends string> extends BaseCriterion<T> {
@@ -134,7 +135,7 @@ function SearchBox<T extends string>({
onChange={makeSelectChangeHandler(c.paramName)}
value={inputs[c.paramName]}
>
<MenuItem value={"All"}>{t("All")}</MenuItem>
{!(c.needAll === false) && <MenuItem value={"All"}>{t("All")}</MenuItem>}
{c.options.map((option, index) => (
<MenuItem key={`${option}-${index}`} value={option}>
{t(option)}


Carregando…
Cancelar
Salvar