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

Add support to delete location #6996

Merged
merged 35 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
32d7560
Add support to delete location
Pranshu1902 Jan 8, 2024
349d723
fix button widths
Pranshu1902 Jan 9, 2024
4989f92
add modal for delete confirmation
Pranshu1902 Jan 9, 2024
ca63a22
add cypress for delete location functionality
Pranshu1902 Jan 9, 2024
e3ae83a
add confirmation dialog before deleting
Pranshu1902 Jan 11, 2024
85e088a
update cypress tests
Pranshu1902 Jan 11, 2024
7046c61
refactor
Pranshu1902 Jan 12, 2024
0e67b7a
fix cypress tests
Pranshu1902 Jan 13, 2024
959ba1a
Merge branch 'develop' into issue#6976
Pranshu1902 Jan 13, 2024
25f972a
show modal with links to linked assets and beds
Pranshu1902 Jan 19, 2024
8c6f79f
use pom in tests and cover all cases
Pranshu1902 Jan 19, 2024
b408dd8
Merge branch 'develop' into issue#6976
Pranshu1902 Jan 19, 2024
14038a9
Merge branch 'develop' into issue#6976
nihal467 Jan 19, 2024
e112fb9
Merge branch 'develop' into issue#6976
nihal467 Jan 22, 2024
447b6ab
update cypress tests to close notifications
Pranshu1902 Jan 25, 2024
1263a00
Merge branch 'develop' into issue#6976
Pranshu1902 Jan 25, 2024
2e443c1
Merge branch 'develop' into issue#6976
nihal467 Feb 5, 2024
dff5a5f
use id for cypress tests
Pranshu1902 Feb 8, 2024
026dd25
Merge branch 'develop' into issue#6976
Pranshu1902 Feb 8, 2024
a6c91e3
re-order asset creation commands
Pranshu1902 Feb 11, 2024
0e1f119
Merge branch 'develop' into issue#6976
rithviknishad Feb 12, 2024
006e72c
Merge branch 'develop' into issue#6976
nihal467 Feb 12, 2024
0849c5f
add wait for creating asset in tests
Pranshu1902 Feb 12, 2024
c96f510
refactor
Pranshu1902 Feb 12, 2024
c305dd8
verify location creation success
Pranshu1902 Feb 12, 2024
5fbbaa2
update location name in cypress
Pranshu1902 Feb 12, 2024
5cbf654
change facility name
Pranshu1902 Feb 12, 2024
54a37c6
update to dummy shifting facility
Pranshu1902 Feb 12, 2024
8d942ab
Merge branch 'develop' into issue#6976
nihal467 Feb 13, 2024
f558391
load specific facility for test
Pranshu1902 Feb 15, 2024
67b8987
Merge branch 'develop' into issue#6976
Pranshu1902 Feb 15, 2024
0389cac
fix typo
Pranshu1902 Feb 15, 2024
cf5b39b
fix tests for new assets page
Pranshu1902 Feb 15, 2024
1b362cb
Merge branch 'develop' into issue#6976
Pranshu1902 Feb 17, 2024
7d5b1fb
Merge branch 'develop' into issue#6976
nihal467 Feb 21, 2024
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
19 changes: 19 additions & 0 deletions cypress/e2e/facility_spec/locations.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ describe("Location Management Section", () => {
assetPagination.navigateToPreviousPage();
});

it("Delete location", () => {
cy.awaitUrl("/facility");
cy.get("a").contains("Dummy Facility 2").click().wait(1000);
cy.get("button").contains("Manage Facility").click().wait(100);
cy.get("div[id=location-management]").click().wait(1000);

// create new location
cy.get("button[id=add-new-location]").click().wait(1000);
cy.get("input[id=name]").type("Test Location");
cy.get("div[id=location-type]").click();
cy.get("li[id=location-type-option-OTHER]").click();
cy.get("button[id=submit]").click().wait(1000);

// delete location
cy.get("button[id=delete-location-button]").click().wait(1000);
cy.get("button[id=submit]").click();
cy.contains("Location Test Location deleted successfully").should("exist");
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
95 changes: 81 additions & 14 deletions src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lazy } from "react";
import { lazy, useState } from "react";
import ButtonV2 from "../Common/components/ButtonV2";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import CareIcon from "../../CAREUI/icons/CareIcon";
Expand All @@ -7,20 +7,51 @@ import routes from "../../Redux/api";
import PaginatedList from "../../CAREUI/misc/PaginatedList";
import { LocationModel } from "./models";
import RecordMeta from "../../CAREUI/display/RecordMeta";
import request from "../../Utils/request/request";
import * as Notification from "../../Utils/Notifications.js";
import ConfirmDialog from "../Common/ConfirmDialog";

const Loading = lazy(() => import("../Common/Loading"));

interface Props {
facilityId: string;
}

interface LocationProps extends LocationModel {
setShowDeletePopup: any;
}
Pranshu1902 marked this conversation as resolved.
Show resolved Hide resolved

export default function LocationManagement({ facilityId }: Props) {
const [showDeletePopup, setShowDeletePopup] = useState({
open: false,
name: "",
id: "",
});

const deleteAssetLocation = async () => {
const res: any = await request(routes.deleteFacilityAssetLocation, {
pathParams: {
facility_external_id: facilityId,
external_id: showDeletePopup.id,
},
});
if (res?.res?.status === 204) {
Notification.Success({
msg: `Location ${showDeletePopup.name} deleted successully`,
});
PaginatedList.Refresh;
} else {
Notification.Error({ msg: "Something went wrong!" });
}
setShowDeletePopup({ ...showDeletePopup, open: false });
};

Pranshu1902 marked this conversation as resolved.
Show resolved Hide resolved
return (
<PaginatedList
route={routes.listFacilityAssetLocation}
pathParams={{ facility_external_id: facilityId }}
>
{() => (
{({ refetch }) => (
<Page
title="Location Management"
backUrl={`/facility/${facilityId}`}
Expand Down Expand Up @@ -55,13 +86,30 @@ export default function LocationManagement({ facilityId }: Props) {
<Loading />
</PaginatedList.WhenLoading>
<PaginatedList.Items<LocationModel> className="my-8 grid gap-3 @4xl:grid-cols-2 @6xl:grid-cols-3 @[100rem]:grid-cols-4 lg:mx-8">
{(item) => <Location {...item} />}
{(item) => (
<Location setShowDeletePopup={setShowDeletePopup} {...item} />
)}
</PaginatedList.Items>
</div>

<div className="flex w-full items-center justify-center">
<PaginatedList.Paginator hideIfSinglePage />
</div>

<ConfirmDialog
title="Delete Location"
description="Are you sure you want to delete this location?"
action="Confirm"
variant="danger"
show={showDeletePopup.open}
onClose={() =>
setShowDeletePopup({ ...showDeletePopup, open: false })
}
onConfirm={async () => {
await deleteAssetLocation();
refetch();
}}
/>
</Page>
)}
</PaginatedList>
Expand All @@ -76,7 +124,8 @@ const Location = ({
created_date,
modified_date,
id,
}: LocationModel) => (
setShowDeletePopup,
}: LocationProps) => (
<div className="flex h-full w-full flex-col rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400">
<div className="flex-1">
<div className="flex w-full items-center justify-between gap-2">
Expand All @@ -96,16 +145,6 @@ const Location = ({
</p>
</div>
</div>
<ButtonV2
id="edit-location-button"
variant="secondary"
border
href={`location/${id}/update`}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-pen text-lg" />
Edit
</ButtonV2>
</div>
<p
className="mt-3 break-all text-sm font-medium text-gray-700"
Expand Down Expand Up @@ -134,6 +173,34 @@ const Location = ({
<CareIcon className="care-l-bed text-lg" />
Manage Beds
</ButtonV2>
<div className="mt-2 flex w-full flex-col gap-2 md:flex-row">
<div className="w-full md:w-1/2">
<ButtonV2
id="edit-location-button"
variant="secondary"
border
className="w-full"
href={`location/${id}/update`}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-pen text-lg" />
Edit
</ButtonV2>
</div>
<div className="w-full md:w-1/2">
<ButtonV2
id="delete-location-button"
variant="secondary"
border
className="w-full"
onClick={() => setShowDeletePopup({ open: true, name: name, id: id })}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-trash text-lg" />
Delete
</ButtonV2>
</div>
</div>

<div className="mt-3 flex items-center justify-between gap-4 text-sm font-medium text-gray-700">
<RecordMeta time={created_date} prefix="Created:" />
Expand Down
7 changes: 7 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ const routes = {
path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/",
method: "PATCH",
},
deleteFacilityAssetLocation: {
path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/",
method: "DELETE",
TRes: Type<null | {
detail?: string;
}>(),
Pranshu1902 marked this conversation as resolved.
Show resolved Hide resolved
},

// Asset bed
listAssetBeds: {
Expand Down
Loading