Skip to content

Commit 297de05

Browse files
authored
Added edit in object table actions (#5781)
1 parent 2ce6e23 commit 297de05

File tree

3 files changed

+84
-12
lines changed

3 files changed

+84
-12
lines changed

frontend/app/src/entities/nodes/object/ui/object-table/cells/actions-cell.tsx

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import {
2-
DeleteObjectModal,
3-
DeleteObjectModalProps,
4-
} from "@/entities/nodes/object/ui/delete-object-modal";
1+
import ObjectItemEditComponent from "@/entities/nodes/object-item-edit/object-item-edit-paginated";
2+
import { DeleteObjectModal } from "@/entities/nodes/object/ui/delete-object-modal";
53
import { getObjectDetailsUrl2 } from "@/entities/nodes/utils";
64
import { Permission } from "@/entities/permission/types";
5+
import { useSchema } from "@/entities/schema/hooks/useSchema";
6+
import { queryClient } from "@/shared/api/rest/client";
77
import { Button } from "@/shared/components/buttons/button-primitive";
8+
import SlideOver, { SlideOverTitle } from "@/shared/components/display/slide-over";
9+
import ErrorScreen from "@/shared/components/errors/error-screen";
810
import { TableCell } from "@/shared/components/table/table-cell";
911
import {
1012
DropdownMenu,
@@ -17,14 +19,22 @@ import { Icon } from "@iconify-icon/react";
1719
import { useState } from "react";
1820
import { Link } from "react-router";
1921

20-
export interface ActionsCellProps extends Omit<DeleteObjectModalProps, "open" | "setOpen"> {
22+
export interface ActionsCellProps {
2123
permission: Permission;
24+
objectId: string;
25+
objectKind: string;
26+
objectLabel: string;
2227
}
2328

2429
export function ActionsCell({ objectKind, objectId, objectLabel, permission }: ActionsCellProps) {
2530
const [showDeleteModal, setShowDeleteModal] = useState(false);
31+
const [showEditForm, setShowEditForm] = useState(false);
32+
const { schema } = useSchema(objectKind);
33+
const isEditAllowed = permission.update.isAllowed;
2634
const isDeleteAllowed = permission.delete.isAllowed;
2735

36+
if (!schema) return <ErrorScreen message={`Schema not found for ${objectKind}`} />;
37+
2838
return (
2939
<>
3040
<TableCell className="sticky right-0 border-l size-10 items-center justify-center bg-white -ml-px">
@@ -49,6 +59,18 @@ export function ActionsCell({ objectKind, objectId, objectLabel, permission }: A
4959
</Link>
5060
</DropdownMenuItem>
5161

62+
<Tooltip enabled={!isEditAllowed} content={permission.update.message} side="left">
63+
<div>
64+
<DropdownMenuItem
65+
disabled={!isEditAllowed}
66+
onClick={() => isEditAllowed && setShowEditForm(true)}
67+
>
68+
<Icon icon="mdi:edit-outline" className="text-base" />
69+
Edit
70+
</DropdownMenuItem>
71+
</div>
72+
</Tooltip>
73+
5274
<Tooltip enabled={!isDeleteAllowed} content={permission.delete.message} side="left">
5375
<div>
5476
<DropdownMenuItem
@@ -64,6 +86,31 @@ export function ActionsCell({ objectKind, objectId, objectLabel, permission }: A
6486
</DropdownMenu>
6587
</TableCell>
6688

89+
{showEditForm && (
90+
<SlideOver
91+
title={
92+
<SlideOverTitle
93+
schema={schema}
94+
currentObjectLabel={objectLabel}
95+
title={`Edit ${objectLabel}`}
96+
/>
97+
}
98+
open={true}
99+
setOpen={() => setShowEditForm(false)}
100+
>
101+
<ObjectItemEditComponent
102+
closeDrawer={() => setShowEditForm(false)}
103+
onUpdateComplete={async () => {
104+
await queryClient.invalidateQueries({
105+
predicate: (query) => query.queryKey.includes("objects"),
106+
});
107+
}}
108+
objectid={objectId}
109+
objectname={objectKind}
110+
/>
111+
</SlideOver>
112+
)}
113+
67114
{showDeleteModal && (
68115
<DeleteObjectModal
69116
objectKind={objectKind}

frontend/app/src/entities/nodes/object/ui/object-table/get-object-table-columns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const getObjectTableColumns = (
3333
{
3434
id: "id",
3535
accessorFn: ({ hfid, display_label, id }): string => {
36-
if (schema.human_friendly_id && hfid) return hfid;
36+
if (schema.human_friendly_id && hfid) return hfid.join(", ");
3737
if (schema.display_labels && display_label) return display_label;
3838
return id;
3939
},

frontend/app/tests/e2e/objects/object-list.spec.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,40 @@ test.describe("/objects/:objectKind", () => {
6464
expect(page.url()).toContain("/objects/InfraPlatform/");
6565
});
6666

67-
test("should be able to create a new object", async ({ page }) => {
67+
test("should be able to manage objects", async ({ page }) => {
6868
await page.goto("/objects/BuiltinTag");
69-
7069
await expect(page.getByRole("heading", { name: "Tag" })).toBeVisible();
7170
await expect(page.getByTestId("create-object-button")).toBeEnabled();
72-
await page.getByTestId("actions-cell-blue").click();
73-
await expect(page.getByRole("menuitem", { name: "Delete" })).toBeEnabled();
74-
await page.getByTestId("create-object-button").click();
75-
await expect(page.getByRole("heading", { name: "Create Tag", exact: true })).toBeVisible();
71+
72+
await test.step("create a new item from the list", async () => {
73+
await page.getByTestId("create-object-button").click();
74+
await page.getByLabel("Name *").fill("crud");
75+
await page.getByLabel("Description").fill("initial description");
76+
await page.getByRole("button", { name: "Save" }).click();
77+
78+
await expect(page.getByRole("link", { name: "crud" })).toBeVisible();
79+
await expect(page.getByText("initial description")).toBeVisible();
80+
});
81+
82+
await test.step("edit the item", async () => {
83+
await page.getByTestId("actions-cell-crud").click();
84+
await page.getByRole("menuitem", { name: "Edit" }).click();
85+
await page.getByLabel("Description").fill("description updated");
86+
await page.getByRole("button", { name: "Save" }).click();
87+
88+
await expect(page.getByText("Tag updated")).toBeVisible();
89+
await expect(page.getByRole("link", { name: "crud" })).toBeVisible();
90+
await expect(page.getByText("description updated")).toBeVisible();
91+
});
92+
93+
await test.step("delete the item", async () => {
94+
await page.getByTestId("actions-cell-crud").click();
95+
await page.getByRole("menuitem", { name: "Delete" }).click();
96+
await expect(page.getByTestId("modal-delete")).toBeVisible();
97+
await expect(page.getByText("Are you sure you want to remove crud")).toBeVisible();
98+
await page.getByTestId("modal-delete-confirm").click();
99+
await expect(page.getByText("Object crud deleted")).toBeVisible();
100+
});
76101
});
77102
});
78103
});

0 commit comments

Comments
 (0)