Skip to content

Commit a2942f5

Browse files
authored
Display new attributes parameters in the schema viewer - IFC-1527 (#6510)
* add styled title * add parameters in the schema viewer * update test * fix attribute display and update test
1 parent ad564ae commit a2942f5

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

frontend/app/src/entities/schema/ui/attribute-display.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { components } from "@/shared/api/rest/types.generated";
22
import Accordion from "@/shared/components/display/accordion";
33
import { ComputedAttributeDisplay } from "./computed-attribute-display";
4-
import { AccordionStyled, NullDisplay, PropertyRow } from "./styled";
4+
import { AccordionStyled, NullDisplay, PropertyRow, PropertyTitle } from "./styled";
55

66
export const AttributeDisplay = ({
77
attribute,
@@ -29,6 +29,7 @@ export const AttributeDisplay = ({
2929
<PropertyRow title="Label" value={attribute.label} />
3030
<PropertyRow title="Description" value={attribute.description} />
3131
<PropertyRow title="Inherited" value={attribute.inherited} />
32+
<PropertyRow title="Default value" value={attribute.default_value as any} />
3233
</div>
3334

3435
<div>
@@ -38,16 +39,12 @@ export const AttributeDisplay = ({
3839
<PropertyRow title="Enum" value={attribute.enum as string[]} />
3940
</div>
4041

41-
<div>
42-
<PropertyRow title="Default value" value={attribute.default_value as any} />
43-
<PropertyRow title="Max length" value={attribute.max_length} />
44-
<PropertyRow title="Min length" value={attribute.min_length} />
45-
<PropertyRow title="Regex" value={attribute.regex} />
46-
</div>
4742
<div>
4843
<PropertyRow title="Branch" value={attribute.branch} />
4944
<PropertyRow title="Order weight" value={attribute.order_weight} />
5045
</div>
46+
47+
<AttributeParameters attribute={attribute} />
5148
</AccordionStyled>
5249
);
5350
};
@@ -86,3 +83,23 @@ const ChoicesRow = ({
8683
</div>
8784
);
8885
};
86+
87+
const AttributeParameters = ({
88+
attribute,
89+
}: { attribute: components["schemas"]["AttributeSchema-Output"] }) => {
90+
if (attribute.kind === "Text") {
91+
return (
92+
<div>
93+
<PropertyTitle title="Parameters" />
94+
95+
<div className="pl-4">
96+
<PropertyRow title="Regex" value={attribute.parameters?.regex} />
97+
<PropertyRow title="Min length" value={attribute.parameters?.min_length} />
98+
<PropertyRow title="Max length" value={attribute.parameters?.max_length} />
99+
</div>
100+
</div>
101+
);
102+
}
103+
104+
return null;
105+
};

frontend/app/src/entities/schema/ui/schema-viewer.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ describe("Schema Visualizer Component", () => {
3636
kind: "Jinja2",
3737
jinja2_template: "test",
3838
},
39+
parameters: {
40+
regex: "test-regex",
41+
min_length: 1,
42+
max_length: 10,
43+
},
3944
},
4045
],
4146
});
@@ -49,6 +54,9 @@ describe("Schema Visualizer Component", () => {
4954
// THEN
5055
await expect.element(component.getByText("random-id")).toBeVisible();
5156
await expect.element(component.getByText("CoreTransformJinja2")).toBeVisible();
57+
await expect.element(component.getByText("test-regex")).toBeVisible();
58+
await expect.element(component.getByText("Min length1")).toBeVisible();
59+
await expect.element(component.getByText("Max length10")).toBeVisible();
5260
});
5361

5462
test("renders jinja template correctly", async () => {
@@ -63,6 +71,7 @@ describe("Schema Visualizer Component", () => {
6371
kind: "Text",
6472
optional: false,
6573
read_only: false,
74+
parameters: {},
6675
computed_attribute: {
6776
kind: "Jinja2",
6877
jinja2_template: "{{ name__value | upper }}",
@@ -95,6 +104,7 @@ describe("Schema Visualizer Component", () => {
95104
kind: "Text",
96105
optional: false,
97106
read_only: false,
107+
parameters: {},
98108
computed_attribute: {
99109
kind: "TransformPython",
100110
transform: "test-transform",

frontend/app/src/entities/schema/ui/styled.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ export const PropertyRow = ({
107107
);
108108
};
109109

110+
export const PropertyTitle = ({
111+
title,
112+
}: {
113+
title: string;
114+
}) => {
115+
return (
116+
<dl className="flex justify-between items-start gap-4 text-sm font-semibold p-2 py-3">
117+
<dt>{title}</dt>
118+
</dl>
119+
);
120+
};
121+
110122
export const TabStyled = ({ className, ...props }: TabProps) => (
111123
<Tab
112124
className={({ isSelected }) =>

0 commit comments

Comments
 (0)