From 778f37954d9ff56d02115531cd5cc9ec43e84f75 Mon Sep 17 00:00:00 2001 From: manmeetnagii Date: Tue, 17 Dec 2024 13:08:19 +0530 Subject: [PATCH 1/3] enhanced-asset-header --- src/components/Assets/AssetsList.tsx | 221 ++++++++++++++++----------- 1 file changed, 129 insertions(+), 92 deletions(-) diff --git a/src/components/Assets/AssetsList.tsx b/src/components/Assets/AssetsList.tsx index c0e47610766..075a13ea26d 100644 --- a/src/components/Assets/AssetsList.tsx +++ b/src/components/Assets/AssetsList.tsx @@ -15,9 +15,9 @@ import ButtonV2 from "@/components/Common/ButtonV2"; import ExportMenu from "@/components/Common/Export"; import Loading from "@/components/Common/Loading"; import Page from "@/components/Common/Page"; +import SearchByMultipleFields from "@/components/Common/SearchByMultipleFields"; import FacilitiesSelectDialogue from "@/components/ExternalResult/FacilitiesSelectDialogue"; import { FacilityModel } from "@/components/Facility/models"; -import SearchInput from "@/components/Form/SearchInput"; import useFilters from "@/hooks/useFilters"; import { useIsAuthorized } from "@/hooks/useIsAuthorized"; @@ -37,10 +37,11 @@ const AssetsList = () => { Pagination, FilterBadges, advancedFilter, + clearSearch, resultsPerPage, } = useFilters({ limit: 18, - cacheBlacklist: ["search"], + cacheBlacklist: ["name", "serial_number", "qr_code_id"], }); const [assets, setAssets] = useState([{} as AssetData]); const [isLoading, setIsLoading] = useState(false); @@ -56,6 +57,9 @@ const AssetsList = () => { const params = { limit: resultsPerPage, page: qParams.page, + name: qParams.name || "", + serial_number: qParams.serial_number || "", + qr_code_id: qParams.qr_code_id || "", offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, search_text: qParams.search || "", facility: qParams.facility || "", @@ -311,103 +315,42 @@ const AssetsList = () => { ); } + const searchOptions = [ + { + key: "name", + label: "Name", + type: "text" as const, + placeholder: "Search by Name", + value: qParams.name || "", + shortcutKey: "n", + }, + { + key: "serial_number", + label: "Serial No.", + type: "text" as const, + placeholder: "Search by Serial No.", + value: qParams.serial_number || "", + shortcutKey: "u", + }, + { + key: "asset_qr_id", + label: "QR Code ID", + type: "text" as const, + placeholder: "Search by QR Code ID", + value: qParams.qr_code_id || "", + shortcutKey: "p", + }, + ]; + return ( - {authorizedForImportExport && ( -
- - ), - onClick: () => setImportAssetModalOpen(true), - }, - }, - { - label: "Export Assets (JSON)", - action: async () => { - const { data } = await request(routes.listAssets, { - query: { ...qParams, json: true, limit: totalCount }, - }); - return data ?? null; - }, - type: "json", - filePrefix: `assets_${facility?.name ?? "all"}`, - options: { - icon: , - disabled: totalCount === 0 || !authorizedForImportExport, - id: "export-json-option", - }, - }, - { - label: "Export Assets (CSV)", - action: async () => { - const { data } = await request(routes.listAssets, { - query: { ...qParams, csv: true, limit: totalCount }, - }); - return data ?? null; - }, - type: "csv", - filePrefix: `assets_${facility?.name ?? "all"}`, - options: { - icon: , - disabled: totalCount === 0 || !authorizedForImportExport, - id: "export-csv-option", - }, - }, - ]} - /> -
- )} - - } - > -
- -
- updateQuery({ [e.name]: e.value })} - placeholder="Search by name/serial no./QR code ID" - /> -
-
-
-
- advancedFilter.setShow(true)} - /> -
- setIsScannerActive(true)} - > - Scan Asset - QR - -
+
{ {t("create_asset")}
+
+
+ setIsScannerActive(true)} + > + Scan + Asset QR + +
+ advancedFilter.setShow(true)} + /> +
+
+ {authorizedForImportExport && ( +
+ + ), + onClick: () => setImportAssetModalOpen(true), + }, + }, + { + label: "Export Assets (JSON)", + action: async () => { + const { data } = await request(routes.listAssets, { + query: { ...qParams, json: true, limit: totalCount }, + }); + return data ?? null; + }, + type: "json", + filePrefix: `assets_${facility?.name ?? "all"}`, + options: { + icon: , + disabled: + totalCount === 0 || !authorizedForImportExport, + id: "export-json-option", + }, + }, + { + label: "Export Assets (CSV)", + action: async () => { + const { data } = await request(routes.listAssets, { + query: { ...qParams, csv: true, limit: totalCount }, + }); + return data ?? null; + }, + type: "csv", + filePrefix: `assets_${facility?.name ?? "all"}`, + options: { + icon: , + disabled: + totalCount === 0 || !authorizedForImportExport, + id: "export-csv-option", + }, + }, + ]} + /> +
+ )} +
+
+ } + > +
+
+ +
+
+ updateQuery({ search: value })} + clearSearch={clearSearch} + className="w-full" + />
From f601b89d72f3136ee4f081d5e821a22b97f45e47 Mon Sep 17 00:00:00 2001 From: manmeetnagii Date: Tue, 17 Dec 2024 15:11:31 +0530 Subject: [PATCH 2/3] enhanced-asset-header --- src/components/Assets/AssetsList.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Assets/AssetsList.tsx b/src/components/Assets/AssetsList.tsx index 075a13ea26d..91a56c262cb 100644 --- a/src/components/Assets/AssetsList.tsx +++ b/src/components/Assets/AssetsList.tsx @@ -56,10 +56,10 @@ const AssetsList = () => { const [selectedFacility, setSelectedFacility] = useState(); const params = { limit: resultsPerPage, - page: qParams.page, - name: qParams.name || "", - serial_number: qParams.serial_number || "", - qr_code_id: qParams.qr_code_id || "", + page: qParams.page || 1, + name: qParams.name || undefined, + serial_number: qParams.serial_number || undefined, + qr_code_id: qParams.qr_code_id || undefined, offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, search_text: qParams.search || "", facility: qParams.facility || "", @@ -478,6 +478,7 @@ const AssetsList = () => { ), badge("Name/Serial No./QR ID", "search"), value("Asset Class", "asset_class", asset_class ?? ""), + value("Name", "name", qParams.name ?? ""), value("Status", "status", status?.replace(/_/g, " ") ?? ""), value( "Location", From 6e5735773c80cbe478217e8df80c05322fabaac1 Mon Sep 17 00:00:00 2001 From: manmeetnagii Date: Tue, 17 Dec 2024 15:40:47 +0530 Subject: [PATCH 3/3] migrates to shadcn button --- src/components/Assets/AssetsList.tsx | 111 ++++++++++++++------------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/src/components/Assets/AssetsList.tsx b/src/components/Assets/AssetsList.tsx index 91a56c262cb..a9a069f8a85 100644 --- a/src/components/Assets/AssetsList.tsx +++ b/src/components/Assets/AssetsList.tsx @@ -8,10 +8,11 @@ import CountBlock from "@/CAREUI/display/Count"; import CareIcon from "@/CAREUI/icons/CareIcon"; import { AdvancedFilterButton } from "@/CAREUI/interactive/FiltersSlideover"; +import { Button } from "@/components/ui/button"; + import AssetFilter from "@/components/Assets/AssetFilter"; import AssetImportModal from "@/components/Assets/AssetImportModal"; import { AssetData, assetClassProps } from "@/components/Assets/AssetTypes"; -import ButtonV2 from "@/components/Common/ButtonV2"; import ExportMenu from "@/components/Common/Export"; import Loading from "@/components/Common/Loading"; import Page from "@/components/Common/Page"; @@ -19,6 +20,7 @@ import SearchByMultipleFields from "@/components/Common/SearchByMultipleFields"; import FacilitiesSelectDialogue from "@/components/ExternalResult/FacilitiesSelectDialogue"; import { FacilityModel } from "@/components/Facility/models"; +import useAuthUser from "@/hooks/useAuthUser"; import useFilters from "@/hooks/useFilters"; import { useIsAuthorized } from "@/hooks/useIsAuthorized"; @@ -37,8 +39,8 @@ const AssetsList = () => { Pagination, FilterBadges, advancedFilter, - clearSearch, resultsPerPage, + clearSearch, } = useFilters({ limit: 18, cacheBlacklist: ["name", "serial_number", "qr_code_id"], @@ -56,10 +58,10 @@ const AssetsList = () => { const [selectedFacility, setSelectedFacility] = useState(); const params = { limit: resultsPerPage, - page: qParams.page || 1, - name: qParams.name || undefined, - serial_number: qParams.serial_number || undefined, - qr_code_id: qParams.qr_code_id || undefined, + page: qParams.page, + name: qParams.name || "", + serial_number: qParams.serial_number || "", + qr_code_id: qParams.qr_code_id || "", offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, search_text: qParams.search || "", facility: qParams.facility || "", @@ -118,6 +120,9 @@ const AssetsList = () => { }, ); + const authUser = useAuthUser(); + const isDisabled = !NonReadOnlyUsers(authUser.user_type); + function isValidURL(url: string) { try { new URL(url); @@ -346,16 +351,19 @@ const AssetsList = () => { +
- { if (qParams.facility) { navigate(`/facility/${qParams.facility}/assets/new`); @@ -366,25 +374,28 @@ const AssetsList = () => { > {t("create_asset")} - +
-
-
- setIsScannerActive(true)} - > - Scan - Asset QR - -
- advancedFilter.setShow(true)} - /> -
-
- {authorizedForImportExport && ( -
+
+ advancedFilter.setShow(true)} + /> + + + +
+ {authorizedForImportExport && ( { icon: ( ), onClick: () => setImportAssetModalOpen(true), @@ -438,31 +449,28 @@ const AssetsList = () => { }, ]} /> -
- )} + )} +
} > -
-
- -
-
- updateQuery({ search: value })} - clearSearch={clearSearch} - className="w-full" - /> -
+
+ + + updateQuery({ search: value })} + clearSearch={clearSearch} + className="w-full" + />
{isLoading ? ( @@ -478,7 +486,6 @@ const AssetsList = () => { ), badge("Name/Serial No./QR ID", "search"), value("Asset Class", "asset_class", asset_class ?? ""), - value("Name", "name", qParams.name ?? ""), value("Status", "status", status?.replace(/_/g, " ") ?? ""), value( "Location",