This repository was archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The most significant changes involve the addition of new functionalit…
…y to export order data. This is achieved through the creation of new methods and components across multiple files. The `Export.cs` file has been heavily modified to include a new `ExportOrder()` method that exports order data into a byte array. This method also includes checks to ensure that exports are not performed too frequently. A new `AdminOrderExportButton` component has been added to the `TopNavBar.tsx` file, allowing users to export order data. New methods have also been added to the `Get.ts` and `Export.ts` files to support this new functionality. List of changes: 1. `Export.cs` file has been significantly modified to include new imports, changes to the `AdminHub` class, and a new `ExportOrder()` method. This method exports order data into a byte array and includes checks to ensure that exports are not performed more frequently than every 3 minutes (Export.cs). 2. `TopNavBar.tsx` file has been updated to include a new `AdminOrderExportButton` component, which allows users to export order data (TopNavBar.tsx). 3. `Entity.ts` file has been updated to change the return type of the `Order` and `Comment` methods in the `AdminOrderEntity` class (Entity.ts). 4. `Get.ts` file has been updated to include a new `Export` method in the `AdminOrderGet` class, which is used to export order data (Get.ts). 5. A new `Export.tsx` file has been created, which defines the `AdminOrderExportButton` component. This component uses the `AdminHub.Order.Get.Export(log)` method to export order data when clicked (Export.tsx). 6. A new `Export.ts` file has been created, which defines the `AdminOrderExport` class. This class includes a `Export(plog: Logger)` method, which is used to export order data (Export.ts).
- Loading branch information
Showing
6 changed files
with
208 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Button, Toast, ToastTitle } from "@fluentui/react-components"; | ||
import { ArrowDownloadRegular } from "@fluentui/react-icons"; | ||
import { useRequest } from "ahooks"; | ||
import { useRouter } from "~/Components/Router"; | ||
import { Logger } from "~/Helpers/Logger"; | ||
import { useErrorToast } from "~/Helpers/useToast"; | ||
import { AdminHub } from "~/ShopNet/Admin"; | ||
|
||
const log = new Logger("Admin", "Order", "ExportButton"); | ||
|
||
/** | ||
* @author Aloento | ||
* @since 1.3.5 | ||
* @version 0.1.0 | ||
*/ | ||
export function AdminOrderExportButton() { | ||
const { Paths } = useRouter(); | ||
const path1 = Paths.at(0); | ||
const path2 = Paths.at(1); | ||
|
||
const { dispatch, dispatchToast } = useErrorToast(log); | ||
|
||
const { run, loading } = useRequest(() => AdminHub.Order.Get.Export(log), { | ||
manual: true, | ||
onError(e, params) { | ||
dispatch({ | ||
Message: "Failed Export Order", | ||
Request: params, | ||
Error: e | ||
}); | ||
}, | ||
onSuccess(url) { | ||
dispatchToast( | ||
<Toast> | ||
<ToastTitle>Order Exported</ToastTitle> | ||
</Toast>, | ||
{ intent: "success" } | ||
); | ||
|
||
const a = document.createElement("a"); | ||
a.href = url; | ||
a.download = `Order_${new Date().toISOString()}.xlsx`; | ||
a.click(); | ||
} | ||
}); | ||
|
||
return ( | ||
path1 === "Admin" && path2 === "Order" && | ||
<Button | ||
appearance="subtle" | ||
icon={<ArrowDownloadRegular />} | ||
onClick={run} | ||
disabled={loading}> | ||
Export Order | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Logger } from "~/Helpers/Logger"; | ||
import { AdminNet } from "../AdminNet"; | ||
|
||
/** | ||
* @author Aloento | ||
* @since 1.3.5 | ||
* @version 0.1.0 | ||
*/ | ||
export abstract class AdminOrderExport extends AdminNet { | ||
/** | ||
* @author Aloento | ||
* @since 1.3.5 | ||
* @version 0.1.0 | ||
*/ | ||
public static async Export(plog: Logger): Promise<string> { | ||
this.EnsureLogin(); | ||
await this.EnsureConnected(); | ||
|
||
const slice: Uint8Array[] = []; | ||
|
||
return new Promise((resolve, reject) => { | ||
this.Hub.stream<Uint8Array>("ExportOrder").subscribe({ | ||
error(err) { | ||
plog.error(err); | ||
reject(err); | ||
}, | ||
next(value) { | ||
slice.push(value); | ||
plog.debug("Received Slice", slice.length); | ||
}, | ||
complete() { | ||
plog.debug("Received All Slices", slice.length); | ||
resolve(URL.createObjectURL(new Blob(slice))); | ||
}, | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters