Skip to content

Commit 42099cd

Browse files
refactor: address review UI comments
1 parent 49204b6 commit 42099cd

File tree

5 files changed

+47
-96
lines changed

5 files changed

+47
-96
lines changed

src/components/TDViewer/components/Action.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const Action: React.FC<any> = (props) => {
3131
const [isExpanded, setIsExpanded] = useState(false);
3232

3333
const addFormDialog = React.useRef<any>();
34+
3435
const handleOpenAddFormDialog = () => {
3536
addFormDialog.current?.openModal();
3637
};
@@ -79,9 +80,10 @@ const Action: React.FC<any> = (props) => {
7980
setIsExpanded(true);
8081

8182
setTimeout(() => {
82-
document
83-
.getElementById(`action-${newName}`)
84-
?.scrollIntoView({ behavior: "smooth", block: "center" });
83+
document.getElementById(`action-${newName}`)?.scrollIntoView({
84+
behavior: "smooth",
85+
block: "center",
86+
});
8587
}, 100);
8688
} catch (e) {
8789
console.error(e);
@@ -105,7 +107,7 @@ const Action: React.FC<any> = (props) => {
105107
{isExpanded && (
106108
<>
107109
<button
108-
className="flex h-10 w-10 items-center justify-center self-stretch bg-gray-400 text-base"
110+
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-lg bg-gray-400 text-base"
109111
title="Copy action"
110112
onClick={(e) => {
111113
e.preventDefault();
@@ -115,9 +117,8 @@ const Action: React.FC<any> = (props) => {
115117
>
116118
<Copy size={16} color="white" />
117119
</button>
118-
119120
<button
120-
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-md rounded-tr-md bg-gray-400 text-base"
121+
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-lg rounded-tr-lg bg-gray-400 text-base"
121122
title="Delete action"
122123
onClick={(e) => {
123124
e.preventDefault();
@@ -161,7 +162,7 @@ const Action: React.FC<any> = (props) => {
161162

162163
{forms.map((form, i) => (
163164
<Form
164-
key={`${i}-${form.href}`}
165+
key={`${i}-${form?.href ?? "nohref"}`}
165166
form={form}
166167
propName={props.actionName}
167168
interactionType="action"
@@ -171,5 +172,4 @@ const Action: React.FC<any> = (props) => {
171172
</details>
172173
);
173174
};
174-
175-
export default Action;
175+
export default Action;

src/components/TDViewer/components/Event.tsx

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,20 @@ const Event: React.FC<any> = (props) => {
3131
const [isExpanded, setIsExpanded] = useState(false);
3232

3333
const addFormDialog = useRef<{ openModal: () => void }>(null);
34+
3435
const handleOpenAddFormDialog = () => {
3536
addFormDialog.current?.openModal();
3637
};
3738

38-
if (
39-
Object.keys(props.event).length === 0 &&
40-
props.event.constructor !== Object
41-
) {
42-
return (
43-
<div className="text-3xl text-white">
44-
Event could not be rendered because mandatory fields are missing.
45-
</div>
46-
);
47-
}
48-
4939
const event = props.event;
50-
const forms = separateForms(props.event.forms);
40+
const forms = separateForms(event.forms);
5141

5242
const attributeListObject = buildAttributeListObject(
5343
{ name: props.eventName },
54-
props.event,
44+
event,
5545
alreadyRenderedKeys
5646
);
5747

58-
const attributes = Object.keys(attributeListObject).map((x) => (
59-
<li key={x}>
60-
{x} : {JSON.stringify(attributeListObject[x])}
61-
</li>
62-
));
63-
6448
const handleDeleteEventClicked = () => {
6549
context.removeOneOfAKindReducer("events", props.eventName);
6650
};
@@ -75,7 +59,6 @@ const Event: React.FC<any> = (props) => {
7559
});
7660

7761
context.updateOfflineTD(JSON.stringify(updatedTD, null, 2));
78-
7962
setIsExpanded(true);
8063

8164
setTimeout(() => {
@@ -104,9 +87,8 @@ const Event: React.FC<any> = (props) => {
10487

10588
{isExpanded && (
10689
<>
107-
{/* COPY BUTTON */}
10890
<button
109-
className="flex h-10 w-10 items-center justify-center self-stretch bg-gray-400 text-base"
91+
className="flex h-10 w-10 items-center justify-center self-stretch bg-gray-400"
11092
title="Copy event"
11193
onClick={(e) => {
11294
e.preventDefault();
@@ -117,9 +99,8 @@ const Event: React.FC<any> = (props) => {
11799
<Copy size={16} color="white" />
118100
</button>
119101

120-
{/* DELETE BUTTON */}
121102
<button
122-
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-md rounded-tr-md bg-gray-400 text-base"
103+
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-lg rounded-tr-lg bg-gray-400"
123104
title="Delete event"
124105
onClick={(e) => {
125106
e.preventDefault();
@@ -140,19 +121,20 @@ const Event: React.FC<any> = (props) => {
140121
</div>
141122
)}
142123

143-
<ul className="list-disc pl-6 text-base text-gray-300">{attributes}</ul>
124+
<ul className="list-disc pl-6 text-base text-gray-300">
125+
{Object.entries(attributeListObject).map(([k, v]) => (
126+
<li key={k}>
127+
{k}: {JSON.stringify(v)}
128+
</li>
129+
))}
130+
</ul>
144131

145-
<div className="flex items-center justify-start pb-2 pt-2">
146-
<InfoIconWrapper
147-
className="flex-grow"
148-
tooltip={getFormsTooltipContent()}
149-
id="events"
150-
>
151-
<h4 className="pr-1 text-lg font-bold text-white">Forms</h4>
152-
</InfoIconWrapper>
153-
</div>
132+
<InfoIconWrapper tooltip={getFormsTooltipContent()} id="events">
133+
<h4 className="text-lg font-bold text-white">Forms</h4>
134+
</InfoIconWrapper>
154135

155136
<AddFormElement onClick={handleOpenAddFormDialog} />
137+
156138
<AddFormDialog
157139
type="event"
158140
interaction={event}

src/components/TDViewer/components/Property.tsx

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,21 @@ import { copyAffordance } from "../../../utils/copyAffordance";
2626

2727
const alreadyRenderedKeys = ["title", "forms", "description"];
2828

29-
interface IProperty {
30-
prop: {
31-
title: string;
32-
forms: Array<{
33-
href: string;
34-
contentType?: string;
35-
op?: string | string[];
36-
[key: string]: any;
37-
}>;
38-
description?: string;
39-
[key: string]: any;
40-
};
41-
propName: string;
42-
}
43-
44-
const Property: React.FC<IProperty> = (props) => {
29+
const Property: React.FC<any> = (props) => {
4530
const context = useContext(ediTDorContext);
4631
const [isExpanded, setIsExpanded] = useState(false);
4732

4833
const addFormDialog = useRef<{ openModal: () => void }>(null);
49-
const handleOpenAddFormDialog = () => {
50-
addFormDialog.current?.openModal();
51-
};
52-
53-
if (
54-
Object.keys(props.prop).length === 0 &&
55-
props.prop.constructor !== Object
56-
) {
57-
return (
58-
<div className="text-3xl text-white">
59-
Property could not be rendered because mandatory fields are missing.
60-
</div>
61-
);
62-
}
6334

6435
const property = props.prop;
65-
const forms = separateForms(structuredClone(props.prop.forms));
36+
const forms = separateForms(structuredClone(property.forms));
6637

6738
const attributeListObject = buildAttributeListObject(
6839
{ name: props.propName },
69-
props.prop,
40+
property,
7041
alreadyRenderedKeys
7142
);
7243

73-
const attributes = Object.keys(attributeListObject).map((x) => (
74-
<li key={x}>
75-
{x} : {JSON.stringify(attributeListObject[x])}
76-
</li>
77-
));
78-
7944
const handleDeletePropertyClicked = () => {
8045
context.removeOneOfAKindReducer("properties", props.propName);
8146
};
@@ -90,7 +55,6 @@ const Property: React.FC<IProperty> = (props) => {
9055
});
9156

9257
context.updateOfflineTD(JSON.stringify(updatedTD, null, 2));
93-
9458
setIsExpanded(true);
9559

9660
setTimeout(() => {
@@ -119,9 +83,8 @@ const Property: React.FC<IProperty> = (props) => {
11983

12084
{isExpanded && (
12185
<>
122-
{/* COPY BUTTON */}
12386
<button
124-
className="flex h-10 w-10 items-center justify-center self-stretch bg-gray-400 text-base"
87+
className="flex h-10 w-10 items-center justify-center self-stretch bg-gray-400"
12588
title="Copy property"
12689
onClick={(e) => {
12790
e.preventDefault();
@@ -132,9 +95,8 @@ const Property: React.FC<IProperty> = (props) => {
13295
<Copy size={16} color="white" />
13396
</button>
13497

135-
{/* DELETE BUTTON */}
13698
<button
137-
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-md rounded-tr-md bg-gray-400 text-base"
99+
className="flex h-10 w-10 items-center justify-center self-stretch rounded-bl-lg rounded-tr-lg bg-gray-400"
138100
title="Delete property"
139101
onClick={(e) => {
140102
e.preventDefault();
@@ -155,15 +117,20 @@ const Property: React.FC<IProperty> = (props) => {
155117
</div>
156118
)}
157119

158-
<ul className="list-disc pl-6 text-base text-gray-300">{attributes}</ul>
120+
<ul className="list-disc pl-6 text-base text-gray-300">
121+
{Object.entries(attributeListObject).map(([k, v]) => (
122+
<li key={k}>
123+
{k}: {JSON.stringify(v)}
124+
</li>
125+
))}
126+
</ul>
127+
128+
<InfoIconWrapper tooltip={getFormsTooltipContent()} id="properties">
129+
<h4 className="text-lg font-bold text-white">Forms</h4>
130+
</InfoIconWrapper>
159131

160-
<div className="flex items-center justify-start pb-2 pt-2">
161-
<InfoIconWrapper tooltip={getFormsTooltipContent()} id="properties">
162-
<h4 className="pr-1 text-lg font-bold text-white">Forms</h4>
163-
</InfoIconWrapper>
164-
</div>
132+
<AddFormElement onClick={() => addFormDialog.current?.openModal()} />
165133

166-
<AddFormElement onClick={handleOpenAddFormDialog} />
167134
<AddFormDialog
168135
type="property"
169136
interaction={property}

src/types/global.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ declare global {
5555
quality?: number;
5656
}
5757
}
58+
59+
export type InteractionKey = "actions" | "properties" | "events";
60+
5861
export {};

src/utils/copyAffordance.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
********************************************************************************/
1313

1414
import test from "node:test";
15-
16-
type Section = "actions" | "properties" | "events";
15+
import type { InteractionKey } from "../types/global";
1716

1817
interface CopyAffordanceParams {
1918
parsedTD: any;
20-
section: Section;
19+
section: InteractionKey;
2120
originalName: string;
2221
affordance: any;
2322
}

0 commit comments

Comments
 (0)