Skip to content

Commit 300b479

Browse files
committed
fix: formatting removed
1 parent 13cb10f commit 300b479

1 file changed

Lines changed: 46 additions & 104 deletions

File tree

src/visualBuilder/components/fieldLabelWrapper.tsx

Lines changed: 46 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import { isFieldDisabled } from "../utils/isFieldDisabled";
88
import visualBuilderPostMessage from "../utils/visualBuilderPostMessage";
99
import { CaretIcon, CaretRightIcon, InfoIcon } from "./icons";
1010
import { LoadingIcon } from "./icons/loading";
11-
import {
12-
FieldTypeIconsMap,
13-
getFieldIcon,
14-
} from "../generators/generateCustomCursor";
11+
import { FieldTypeIconsMap, getFieldIcon } from "../generators/generateCustomCursor";
1512
import { uniqBy } from "lodash-es";
1613
import { visualBuilderStyles } from "../visualBuilder.style";
1714
import { CslpError } from "./CslpError";
@@ -28,7 +25,7 @@ interface ReferenceParentMap {
2825
contentTypeUid: string;
2926
contentTypeTitle: string;
3027
referenceFieldName: string;
31-
}[];
28+
}[]
3229
}
3330

3431
async function getFieldDisplayNames(fieldMetadata: CslpData[]) {
@@ -46,28 +43,18 @@ async function getContentTypeName(contentTypeUid: string) {
4643
content_type_uid: contentTypeUid,
4744
});
4845
return result?.contentTypeName;
49-
} catch (e) {
50-
console.warn(
51-
"[getFieldLabelWrapper] Error getting content type name",
52-
e
53-
);
46+
} catch(e) {
47+
console.warn("[getFieldLabelWrapper] Error getting content type name", e);
5448
return "";
5549
}
5650
}
5751

5852
async function getReferenceParentMap() {
5953
try {
60-
const result =
61-
(await visualBuilderPostMessage?.send<ReferenceParentMap>(
62-
VisualBuilderPostMessageEvents.REFERENCE_MAP,
63-
{}
64-
)) ?? {};
54+
const result = await visualBuilderPostMessage?.send<ReferenceParentMap>(VisualBuilderPostMessageEvents.REFERENCE_MAP, {}) ?? {};
6555
return result;
66-
} catch (e) {
67-
console.warn(
68-
"[getFieldLabelWrapper] Error getting reference parent map",
69-
e
70-
);
56+
} catch(e) {
57+
console.warn("[getFieldLabelWrapper] Error getting reference parent map", e);
7158
return {};
7259
}
7360
}
@@ -131,53 +118,35 @@ function FieldLabelWrapperComponent(
131118
],
132119
"cslpValue"
133120
);
134-
const [
135-
displayNames,
136-
fieldSchema,
137-
contentTypeName,
138-
referenceParentMap,
139-
] = await Promise.all([
121+
const [displayNames, fieldSchema, contentTypeName, referenceParentMap] = await Promise.all([
140122
getFieldDisplayNames(allPaths),
141123
FieldSchemaMap.getFieldSchema(
142124
props.fieldMetadata.content_type_uid,
143125
props.fieldMetadata.fieldPath
144126
),
145-
getContentTypeName(props.fieldMetadata.content_type_uid),
146-
getReferenceParentMap(),
127+
getContentTypeName(
128+
props.fieldMetadata.content_type_uid
129+
),
130+
getReferenceParentMap()
147131
]);
148132
const entryUid = props.fieldMetadata.entry_uid;
149133

150134
const referenceData = referenceParentMap[entryUid];
151135
const isReference = !!referenceData;
152136

153-
let referenceFieldName = referenceData
154-
? referenceData[0].referenceFieldName
155-
: "";
156-
let parentContentTypeName = referenceData
157-
? referenceData[0].contentTypeTitle
158-
: "";
137+
let referenceFieldName = referenceData ? referenceData[0].referenceFieldName : "";
138+
let parentContentTypeName = referenceData ? referenceData[0].contentTypeTitle : "";
159139

160-
if (isReference) {
161-
const domAncestor = eventDetails.editableElement.closest(
162-
`[data-cslp]:not([data-cslp^="${props.fieldMetadata.content_type_uid}"])`
163-
);
164-
if (domAncestor) {
165-
const domAncestorCslp =
166-
domAncestor.getAttribute("data-cslp");
167-
const domAncestorDetails = extractDetailsFromCslp(
168-
domAncestorCslp!
169-
);
170-
const domAncestorContentTypeUid =
171-
domAncestorDetails.content_type_uid;
172-
const domAncestorContentParent = referenceData?.find(
173-
(data) =>
174-
data.contentTypeUid === domAncestorContentTypeUid
175-
);
176-
if (domAncestorContentParent) {
177-
referenceFieldName =
178-
domAncestorContentParent.referenceFieldName;
179-
parentContentTypeName =
180-
domAncestorContentParent.contentTypeTitle;
140+
if(isReference) {
141+
const domAncestor = eventDetails.editableElement.closest(`[data-cslp]:not([data-cslp^="${props.fieldMetadata.content_type_uid}"])`);
142+
if(domAncestor) {
143+
const domAncestorCslp = domAncestor.getAttribute("data-cslp");
144+
const domAncestorDetails = extractDetailsFromCslp(domAncestorCslp!);
145+
const domAncestorContentTypeUid = domAncestorDetails.content_type_uid;
146+
const domAncestorContentParent = referenceData?.find(data => data.contentTypeUid === domAncestorContentTypeUid);
147+
if(domAncestorContentParent) {
148+
referenceFieldName = domAncestorContentParent.referenceFieldName;
149+
parentContentTypeName = domAncestorContentParent.contentTypeTitle;
181150
}
182151
}
183152
}
@@ -252,38 +221,25 @@ function FieldLabelWrapperComponent(
252221
"visual-builder__tooltip--persistent"
253222
]
254223
)}
255-
data-tooltip={
256-
!reason
257-
?.toLowerCase()
258-
.includes("click here to link a variant")
224+
data-tooltip={!reason?.toLowerCase().includes("click here to link a variant")
259225
? reason
260-
: undefined
261-
}
226+
: undefined}
262227
>
263228
{reason
264229
.toLowerCase()
265230
.includes("click here to link a variant") && (
266231
<div
267-
className={
268-
visualBuilderStyles()[
269-
"visual-builder__custom-tooltip"
270-
]
271-
}
232+
className={visualBuilderStyles()["visual-builder__custom-tooltip"]}
272233
onClick={handleLinkVariant}
273234
>
274235
{(() => {
275-
const [before, after] =
276-
reason.split("here");
236+
const [before, after] = reason.split(
237+
"here"
238+
);
277239
return (
278240
<>
279241
{before}
280-
<span
281-
style={{
282-
textDecoration: "underline",
283-
}}
284-
>
285-
here
286-
</span>
242+
<span style={{ textDecoration: "underline" }}>here</span>
287243
{after}
288244
</>
289245
);
@@ -315,11 +271,8 @@ function FieldLabelWrapperComponent(
315271

316272
try {
317273
fetchData();
318-
} catch (e) {
319-
console.warn(
320-
"[getFieldLabelWrapper] Error fetching field label data",
321-
e
322-
);
274+
} catch(e) {
275+
console.warn("[getFieldLabelWrapper] Error fetching field label data", e);
323276
}
324277
}, [props]);
325278

@@ -351,13 +304,7 @@ function FieldLabelWrapperComponent(
351304
)}
352305
>
353306
{currentField.isVariant ? <VariantIndicator /> : null}
354-
<ToolbarTooltip
355-
data={{
356-
contentTypeName: currentField.parentContentTypeName,
357-
referenceFieldName: currentField.referenceFieldName,
358-
}}
359-
disabled={!currentField.isReference || isDropdownOpen}
360-
>
307+
<ToolbarTooltip data={{contentTypeName: currentField.parentContentTypeName, referenceFieldName: currentField.referenceFieldName}} disabled={!currentField.isReference || isDropdownOpen}>
361308
<div
362309
className={classNames(
363310
"visual-builder__focused-toolbar__field-label-wrapper",
@@ -375,9 +322,8 @@ function FieldLabelWrapperComponent(
375322
},
376323
{
377324
"field-label-dropdown-open": isDropdownOpen,
378-
[visualBuilderStyles()[
379-
"field-label-dropdown-open"
380-
]]: isDropdownOpen,
325+
[visualBuilderStyles()["field-label-dropdown-open"]]:
326+
isDropdownOpen,
381327
},
382328
{
383329
"visual-builder__focused-toolbar--variant":
@@ -403,23 +349,20 @@ function FieldLabelWrapperComponent(
403349
visualBuilderStyles()[
404350
"visual-builder__button--primary"
405351
],
406-
visualBuilderStyles()[
407-
"visual-builder__button-loader"
408-
],
352+
visualBuilderStyles()["visual-builder__button-loader"],
409353
error &&
410354
visualBuilderStyles()[
411355
"visual-builder__button-error"
412356
]
413357
)}
414358
disabled={dataLoading}
415359
>
416-
{currentField.isReference && !dataLoading && !error ? (
360+
{
361+
currentField.isReference && !dataLoading && !error ?
417362
<div
418363
className={classNames(
419364
"visual-builder__reference-icon-container",
420-
visualBuilderStyles()[
421-
"visual-builder__reference-icon-container"
422-
]
365+
visualBuilderStyles()["visual-builder__reference-icon-container"]
423366
)}
424367
>
425368
<div
@@ -435,11 +378,10 @@ function FieldLabelWrapperComponent(
435378
data-testid="visual-builder__field-icon-caret"
436379
/>
437380
<CaretRightIcon />
438-
</div>
439-
) : null}
440-
{currentField.contentTypeName &&
441-
!dataLoading &&
442-
!error ? (
381+
</div> : null
382+
}
383+
{
384+
currentField.contentTypeName && !dataLoading && !error ?
443385
<>
444386
<ContentTypeIcon />
445387
<div
@@ -453,8 +395,8 @@ function FieldLabelWrapperComponent(
453395
>
454396
{currentField.contentTypeName + " : "}
455397
</div>
456-
</>
457-
) : null}
398+
</> : null
399+
}
458400
{currentField.prefixIcon ? (
459401
<div
460402
className={classNames(

0 commit comments

Comments
 (0)