Skip to content

Commit 59a3088

Browse files
authored
display node label based on the row kind instead of current view kind (#5805)
1 parent 7ec570e commit 59a3088

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function TableRelationshipCell({
3939
export function RelationshipNodeDisplay({ node }: NodeRelationshipOne) {
4040
const { schema } = useSchema(node.__typename);
4141

42-
if (!schema) return "Unknown schema";
42+
if (!schema) return `Schema for ${node.__typename} not found`;
4343

4444
return (
4545
<LinkButton
@@ -49,7 +49,7 @@ export function RelationshipNodeDisplay({ node }: NodeRelationshipOne) {
4949
className="rounded-full truncate hover:underline hover:border-custom-blue-700 pr-2.5"
5050
>
5151
<Icon icon={schema.icon ?? "mdi:cube-outline"} className="mr-1 text-custom-blue-800" />
52-
{getNodeLabel({ node, schema })}
52+
{getNodeLabel(node)}
5353
</LinkButton>
5454
);
5555
}

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
@@ -32,7 +32,7 @@ export const getObjectTableColumns = (
3232
return [
3333
{
3434
id: "id",
35-
accessorFn: (node) => getNodeLabel({ node, schema }),
35+
accessorFn: (node) => getNodeLabel(node),
3636
header: () => (
3737
<div className={classNames(cellsStyle, cellHeaderStyle, "left-0 z-10 hover:bg-white")}>
3838
{schema.icon && <Icon icon={schema.icon} className="text-stone-400" />}

frontend/app/src/entities/nodes/object/utils/get-node-label.test.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { NodeCore } from "@/entities/nodes/types";
2-
import { describe, expect, it } from "vitest";
2+
import { getSchema } from "@/entities/schema/domain/get-schema";
3+
import { describe, expect, it, vi } from "vitest";
34
import { generateNodeSchema } from "../../../../../tests/fake/schema";
45
import { getNodeLabel } from "./get-node-label";
56

7+
vi.mock("@/entities/schema/domain/get-schema", () => ({
8+
getSchema: vi.fn(() => ({
9+
schema: generateNodeSchema(),
10+
isGeneric: false,
11+
isNode: true,
12+
isProfile: false,
13+
})),
14+
}));
15+
616
describe("getNodeLabel", () => {
7-
const baseSchema = generateNodeSchema();
817
const baseNode: NodeCore = {
918
id: "test-id",
1019
hfid: null,
@@ -14,78 +23,74 @@ describe("getNodeLabel", () => {
1423

1524
it("should join multiple hfids with comma when node has hfid array", () => {
1625
// GIVEN
17-
const node = { ...baseNode, hfid: ["hfid-1", "hfid-2"] };
18-
const schema = baseSchema;
26+
const node: NodeCore = { ...baseNode, hfid: ["hfid-1", "hfid-2"] };
1927

2028
// WHEN
21-
const result = getNodeLabel({ node, schema });
29+
const result = getNodeLabel(node);
2230

2331
// THEN
2432
expect(result).toBe("hfid-1, hfid-2");
2533
});
2634

2735
it("should use display_label when hfid is not present", () => {
2836
// GIVEN
29-
const node = { ...baseNode, display_label: "Display Label" };
30-
const schema = baseSchema;
37+
const node: NodeCore = { ...baseNode, display_label: "Display Label" };
3138

3239
// WHEN
33-
const result = getNodeLabel({ node, schema });
40+
const result = getNodeLabel(node);
3441

3542
// THEN
3643
expect(result).toBe("Display Label");
3744
});
3845

3946
it("should fallback to node.id when neither hfid nor display_label are present", () => {
4047
// WHEN
41-
const result = getNodeLabel({ node: baseNode, schema: baseSchema });
48+
const result = getNodeLabel(baseNode);
4249

4350
// THEN
4451
expect(result).toBe("test-id");
4552
});
4653

4754
it("should prefer hfid over display_label when both are available", () => {
4855
// GIVEN
49-
const node = {
56+
const node: NodeCore = {
5057
...baseNode,
5158
hfid: ["hfid-1"],
5259
display_label: "Display Label",
5360
};
54-
const schema = baseSchema;
5561

5662
// WHEN
57-
const result = getNodeLabel({ node, schema });
63+
const result = getNodeLabel(node);
5864

5965
// THEN
6066
expect(result).toBe("hfid-1");
6167
});
6268

63-
it("should fallback to node.id when schema allows special labels but node values are null", () => {
64-
// GIVEN
65-
const schema = baseSchema;
66-
69+
it("should fallback to node.id when special labels are null", () => {
6770
// WHEN
68-
const result = getNodeLabel({ node: baseNode, schema });
71+
const result = getNodeLabel(baseNode);
6972

7073
// THEN
7174
expect(result).toBe("test-id");
7275
});
7376

74-
it("should use node.id when schema disables special labels even if node has them", () => {
77+
it("should use node.id when schema is not found even if node has special labels", () => {
7578
// GIVEN
76-
const node = {
79+
vi.mocked(getSchema).mockReturnValueOnce({
80+
schema: null,
81+
isGeneric: false,
82+
isNode: false,
83+
isProfile: false,
84+
});
85+
const node: NodeCore = {
7786
...baseNode,
7887
hfid: ["hfid-1"],
7988
display_label: "Display Label",
80-
};
81-
const schema = {
82-
...baseSchema,
83-
human_friendly_id: null,
84-
display_labels: null,
89+
__typename: "UnknownType",
8590
};
8691

8792
// WHEN
88-
const result = getNodeLabel({ node, schema: schema });
93+
const result = getNodeLabel(node);
8994

9095
// THEN
9196
expect(result).toBe("test-id");

frontend/app/src/entities/nodes/object/utils/get-node-label.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { NodeCore } from "@/entities/nodes/types";
2-
import { IModelSchema } from "@/entities/schema/stores/schema.atom";
2+
import { getSchema } from "@/entities/schema/domain/get-schema";
3+
4+
export function getNodeLabel(node: NodeCore): string {
5+
const { schema } = getSchema(node.__typename);
6+
7+
if (!schema) return node.id;
38

4-
export function getNodeLabel({ node, schema }: { node: NodeCore; schema: IModelSchema }): string {
59
if (schema.human_friendly_id && node.hfid) {
610
return node.hfid.join(", ");
711
}

0 commit comments

Comments
 (0)