Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced dispatch with useQuery and request in Asset module #6374

Merged
merged 27 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6f5a27b
changed to request in HL7monitor.tsx
kshitijv256 Sep 26, 2023
ebc21e1
replaced dispatch in assetTypes
kshitijv256 Sep 27, 2023
a355fc6
changed dispatch in filteer, import files
kshitijv256 Sep 27, 2023
4f06879
changed all dispatch requests with useQuery and request in asset module
kshitijv256 Sep 29, 2023
aae1541
Merge branch 'coronasafe:develop' into assets_update
kshitijv256 Sep 29, 2023
79fa2ff
added TBody to various endpoints
kshitijv256 Sep 29, 2023
d90b17a
fixed assetfilter page
kshitijv256 Sep 29, 2023
dd887bc
fixed asset import modal page
kshitijv256 Sep 29, 2023
08d6244
made requested changes
kshitijv256 Sep 29, 2023
8d3222a
made requested changes
kshitijv256 Sep 30, 2023
ab9824e
reverted to assetBedModel
kshitijv256 Oct 1, 2023
f31aeaa
fixed delete asset function
kshitijv256 Oct 1, 2023
bcd97ff
fixed after delete redirection
kshitijv256 Oct 1, 2023
056a0d3
removed extra setstates
kshitijv256 Oct 1, 2023
4226603
Merge branch 'develop' into asset_changes
nihal467 Oct 3, 2023
610780d
updated failing cypress tests for asset module
kshitijv256 Oct 3, 2023
d4f5079
Merge branch 'develop' into asset_changes
kshitijv256 Oct 3, 2023
700ccd0
removed useEffects
kshitijv256 Oct 3, 2023
87d6d46
Merge branch 'develop' into asset_changes
kshitijv256 Oct 8, 2023
502680f
Merge branch 'develop' into asset_changes
kshitijv256 Oct 9, 2023
b1f3b72
removed changes from cypress files
kshitijv256 Oct 9, 2023
390f567
Merge branch 'develop' into asset_changes
kshitijv256 Oct 9, 2023
7c1bdfe
fixed merge issues
kshitijv256 Oct 9, 2023
77ba690
fixed transactions issue
kshitijv256 Oct 11, 2023
983a242
Merge branch 'develop' into asset_changes
kshitijv256 Oct 11, 2023
9344abe
Merge branch 'develop' into asset_changes
kshitijv256 Oct 17, 2023
fc2e15e
remove console logs
rithviknishad Oct 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/e2e/assets_spec/asset_homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("Asset Tab", () => {
assetPage.selectImportOption();
assetPage.selectImportFacility("Dummy Facility 1");
assetPage.importAssetFile();
assetPage.selectImportLocation("Camera Loc");
assetPage.selectImportLocation("Camera Locations");
assetPage.clickImportAsset();
});

Expand Down
79 changes: 27 additions & 52 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { useState, useEffect, useCallback } from "react";
import { useAbortableEffect, statusType } from "../../Common/utils";
import { navigate, useQueryParams } from "raviger";
import { FacilitySelect } from "../Common/FacilitySelect";
import { FacilityModel } from "../Facility/models";
import { useDispatch } from "react-redux";
import {
getFacilityAssetLocation,
getPermittedFacility,
} from "../../Redux/actions";
import * as Notification from "../../Utils/Notifications.js";
import { LocationSelect } from "../Common/LocationSelect";
import { AssetClass, AssetLocationObject } from "./AssetTypes";
import { FieldLabel } from "../Form/FormFields/FormField";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover";
import routes from "../../Redux/api";
import useQuery from "../../Utils/request/useQuery";
import DateRangeFormField from "../Form/FormFields/DateRangeFormField";
import dayjs from "dayjs";
import { FieldChangeEvent } from "../Form/FormFields/Utils";
Expand All @@ -35,7 +30,6 @@ const getDate = (value: any) =>

function AssetFilter(props: any) {
const { filter, onChange, closeFilter } = props;
const dispatch: any = useDispatch();
const [facility, setFacility] = useState<FacilityModel>({ name: "" });
const [location, setLocation] =
useState<AssetLocationObject>(initialLocation);
Expand All @@ -46,16 +40,39 @@ function AssetFilter(props: any) {
const [asset_class, setAssetClass] = useState<string>(
filter.asset_class || ""
);
const [facilityId, setFacilityId] = useState<number | "">(filter.facility);
const [facilityId, setFacilityId] = useState<string | "">(filter.facility);
const [locationId, setLocationId] = useState<string | "">(filter.location);
const [warrantyExpiry, setWarrantyExpiry] = useState({
before: filter.warranty_amc_end_of_validity_before || null,
after: filter.warranty_amc_end_of_validity_after || null,
});
const [qParams, _] = useQueryParams();

useQuery(routes.getPermittedFacility, {
pathParams: { id: facilityId },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setFacility(data);
}
},
prefetch: !!facilityId,
});

useQuery(routes.getFacilityAssetLocation, {
pathParams: {
facilityId: String(facilityId),
locationId: String(locationId),
},
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setLocation(data);
}
},
prefetch: !!(facilityId && locationId),
});

useEffect(() => {
setFacilityId(facility?.id ? facility?.id : "");
setFacilityId(facility?.id ? `${facility?.id}` : "");
setLocationId(
facility?.id === qParams.facility ? qParams.location ?? "" : ""
);
Comment on lines 74 to 78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this useEffect and set these values in onResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing it is causing problems in with location in filter

Expand All @@ -75,48 +92,6 @@ function AssetFilter(props: any) {
else navigate("/assets");
}, [qParams]);

const fetchFacility = useCallback(
async (status: statusType) => {
if (facilityId) {
const facilityData: any = await dispatch(
getPermittedFacility(facilityId)
);
if (!status.aborted) {
setFacility(facilityData?.data);
}
}
},
[filter.facility]
);

const fetchLocation = useCallback(
async (status: statusType) => {
if (locationId && facilityId) {
const [locationData]: any = await Promise.all([
dispatch(
getFacilityAssetLocation(String(facilityId), String(locationId))
),
]);
if (!status.aborted && locationData !== undefined) {
if (!locationData.data)
Notification.Error({
msg: "Something went wrong..!",
});
else {
setLocation(locationData.data);
}
}
} else {
setLocation(initialLocation);
}
},
[filter.location]
);

useAbortableEffect((status: statusType) => {
filter.facility && fetchFacility(status);
filter.location && fetchLocation(status);
}, []);
const applyFilter = () => {
const data = {
facility: facilityId,
Expand Down
22 changes: 9 additions & 13 deletions src/Components/Assets/AssetImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { FacilityModel } from "../Facility/models";
import { AssetData } from "./AssetTypes";
import * as Notification from "../../Utils/Notifications.js";
import { Cancel, Submit } from "../Common/components/ButtonV2";
import { listFacilityAssetLocation } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { Link } from "raviger";
import readXlsxFile from "read-excel-file";
import {
Expand All @@ -16,6 +14,8 @@ import {
import { parseCsvFile } from "../../Utils/utils";
import useConfig from "../../Common/hooks/useConfig";
import DialogModal from "../Common/Dialog";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import { SelectFormField } from "../Form/FormFields/SelectFormField";

interface Props {
Expand All @@ -34,7 +34,6 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
location: "",
});
const [locations, setLocations] = useState<any>([]);
const dispatchAction: any = useDispatch();
const { sample_format_asset_import } = useConfig();
const [locationsLoading, setLocationsLoading] = useState(false);

Expand All @@ -43,18 +42,14 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
setSelectedFile(undefined);
onClose && onClose();
};

useEffect(() => {
setLocationsLoading(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed? The loader for when the locations are still being fetched does not work anymore.. setLocationsLoading

dispatchAction(
listFacilityAssetLocation({}, { facility_external_id: facility.id })
).then(({ data }: any) => {
setLocationsLoading(false);
if (data.count > 0) {
useQuery(routes.listFacilityAssetLocation, {
pathParams: { facility_external_id: `${facility.id}` },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setLocations(data.results);
}
});
}, []);
},
});

useEffect(() => {
const readFile = async () => {
Expand Down Expand Up @@ -362,6 +357,7 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
<Submit
onClick={handleUpload}
disabled={isImporting || !selectedFile}
data-testid="asset-import-btn"
>
{isImporting ? (
<i className="fa-solid fa-spinner animate-spin" />
Expand Down
Loading
Loading