Skip to content

Commit 13cb10f

Browse files
committed
fix: remove console
1 parent 1ba39e6 commit 13cb10f

1 file changed

Lines changed: 105 additions & 48 deletions

File tree

src/visualBuilder/components/fieldLabelWrapper.tsx

Lines changed: 105 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ 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 { FieldTypeIconsMap, getFieldIcon } from "../generators/generateCustomCursor";
11+
import {
12+
FieldTypeIconsMap,
13+
getFieldIcon,
14+
} from "../generators/generateCustomCursor";
1215
import { uniqBy } from "lodash-es";
1316
import { visualBuilderStyles } from "../visualBuilder.style";
1417
import { CslpError } from "./CslpError";
@@ -25,7 +28,7 @@ interface ReferenceParentMap {
2528
contentTypeUid: string;
2629
contentTypeTitle: string;
2730
referenceFieldName: string;
28-
}[]
31+
}[];
2932
}
3033

3134
async function getFieldDisplayNames(fieldMetadata: CslpData[]) {
@@ -43,18 +46,28 @@ async function getContentTypeName(contentTypeUid: string) {
4346
content_type_uid: contentTypeUid,
4447
});
4548
return result?.contentTypeName;
46-
} catch(e) {
47-
console.warn("[getFieldLabelWrapper] Error getting content type name", e);
49+
} catch (e) {
50+
console.warn(
51+
"[getFieldLabelWrapper] Error getting content type name",
52+
e
53+
);
4854
return "";
4955
}
5056
}
5157

5258
async function getReferenceParentMap() {
5359
try {
54-
const result = await visualBuilderPostMessage?.send<ReferenceParentMap>(VisualBuilderPostMessageEvents.REFERENCE_MAP, {}) ?? {};
60+
const result =
61+
(await visualBuilderPostMessage?.send<ReferenceParentMap>(
62+
VisualBuilderPostMessageEvents.REFERENCE_MAP,
63+
{}
64+
)) ?? {};
5565
return result;
56-
} catch(e) {
57-
console.warn("[getFieldLabelWrapper] Error getting reference parent map", e);
66+
} catch (e) {
67+
console.warn(
68+
"[getFieldLabelWrapper] Error getting reference parent map",
69+
e
70+
);
5871
return {};
5972
}
6073
}
@@ -118,35 +131,53 @@ function FieldLabelWrapperComponent(
118131
],
119132
"cslpValue"
120133
);
121-
const [displayNames, fieldSchema, contentTypeName, referenceParentMap] = await Promise.all([
134+
const [
135+
displayNames,
136+
fieldSchema,
137+
contentTypeName,
138+
referenceParentMap,
139+
] = await Promise.all([
122140
getFieldDisplayNames(allPaths),
123141
FieldSchemaMap.getFieldSchema(
124142
props.fieldMetadata.content_type_uid,
125143
props.fieldMetadata.fieldPath
126144
),
127-
getContentTypeName(
128-
props.fieldMetadata.content_type_uid
129-
),
130-
getReferenceParentMap()
145+
getContentTypeName(props.fieldMetadata.content_type_uid),
146+
getReferenceParentMap(),
131147
]);
132148
const entryUid = props.fieldMetadata.entry_uid;
133149

134150
const referenceData = referenceParentMap[entryUid];
135151
const isReference = !!referenceData;
136152

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

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;
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;
150181
}
151182
}
152183
}
@@ -185,15 +216,14 @@ function FieldLabelWrapperComponent(
185216
props.fieldMetadata.content_type_uid,
186217
}
187218
);
188-
console.log("result", result);
189219

190220
// If the modal was closed or linking failed, do nothing
191221
if (!result || result.type === "error") {
192222
return;
193223
}
194224

195225
// If linking was successful and requires revalidation, revalidate
196-
if (result.type === "success" ) {
226+
if (result.type === "success") {
197227
await handleRevalidateFieldData();
198228
}
199229
} catch (message) {
@@ -222,25 +252,38 @@ function FieldLabelWrapperComponent(
222252
"visual-builder__tooltip--persistent"
223253
]
224254
)}
225-
data-tooltip={!reason?.toLowerCase().includes("click here to link a variant")
255+
data-tooltip={
256+
!reason
257+
?.toLowerCase()
258+
.includes("click here to link a variant")
226259
? reason
227-
: undefined}
260+
: undefined
261+
}
228262
>
229263
{reason
230264
.toLowerCase()
231265
.includes("click here to link a variant") && (
232266
<div
233-
className={visualBuilderStyles()["visual-builder__custom-tooltip"]}
267+
className={
268+
visualBuilderStyles()[
269+
"visual-builder__custom-tooltip"
270+
]
271+
}
234272
onClick={handleLinkVariant}
235273
>
236274
{(() => {
237-
const [before, after] = reason.split(
238-
"here"
239-
);
275+
const [before, after] =
276+
reason.split("here");
240277
return (
241278
<>
242279
{before}
243-
<span style={{ textDecoration: "underline" }}>here</span>
280+
<span
281+
style={{
282+
textDecoration: "underline",
283+
}}
284+
>
285+
here
286+
</span>
244287
{after}
245288
</>
246289
);
@@ -272,8 +315,11 @@ function FieldLabelWrapperComponent(
272315

273316
try {
274317
fetchData();
275-
} catch(e) {
276-
console.warn("[getFieldLabelWrapper] Error fetching field label data", e);
318+
} catch (e) {
319+
console.warn(
320+
"[getFieldLabelWrapper] Error fetching field label data",
321+
e
322+
);
277323
}
278324
}, [props]);
279325

@@ -305,7 +351,13 @@ function FieldLabelWrapperComponent(
305351
)}
306352
>
307353
{currentField.isVariant ? <VariantIndicator /> : null}
308-
<ToolbarTooltip data={{contentTypeName: currentField.parentContentTypeName, referenceFieldName: currentField.referenceFieldName}} disabled={!currentField.isReference || isDropdownOpen}>
354+
<ToolbarTooltip
355+
data={{
356+
contentTypeName: currentField.parentContentTypeName,
357+
referenceFieldName: currentField.referenceFieldName,
358+
}}
359+
disabled={!currentField.isReference || isDropdownOpen}
360+
>
309361
<div
310362
className={classNames(
311363
"visual-builder__focused-toolbar__field-label-wrapper",
@@ -323,8 +375,9 @@ function FieldLabelWrapperComponent(
323375
},
324376
{
325377
"field-label-dropdown-open": isDropdownOpen,
326-
[visualBuilderStyles()["field-label-dropdown-open"]]:
327-
isDropdownOpen,
378+
[visualBuilderStyles()[
379+
"field-label-dropdown-open"
380+
]]: isDropdownOpen,
328381
},
329382
{
330383
"visual-builder__focused-toolbar--variant":
@@ -350,20 +403,23 @@ function FieldLabelWrapperComponent(
350403
visualBuilderStyles()[
351404
"visual-builder__button--primary"
352405
],
353-
visualBuilderStyles()["visual-builder__button-loader"],
406+
visualBuilderStyles()[
407+
"visual-builder__button-loader"
408+
],
354409
error &&
355410
visualBuilderStyles()[
356411
"visual-builder__button-error"
357412
]
358413
)}
359414
disabled={dataLoading}
360415
>
361-
{
362-
currentField.isReference && !dataLoading && !error ?
416+
{currentField.isReference && !dataLoading && !error ? (
363417
<div
364418
className={classNames(
365419
"visual-builder__reference-icon-container",
366-
visualBuilderStyles()["visual-builder__reference-icon-container"]
420+
visualBuilderStyles()[
421+
"visual-builder__reference-icon-container"
422+
]
367423
)}
368424
>
369425
<div
@@ -379,10 +435,11 @@ function FieldLabelWrapperComponent(
379435
data-testid="visual-builder__field-icon-caret"
380436
/>
381437
<CaretRightIcon />
382-
</div> : null
383-
}
384-
{
385-
currentField.contentTypeName && !dataLoading && !error ?
438+
</div>
439+
) : null}
440+
{currentField.contentTypeName &&
441+
!dataLoading &&
442+
!error ? (
386443
<>
387444
<ContentTypeIcon />
388445
<div
@@ -396,8 +453,8 @@ function FieldLabelWrapperComponent(
396453
>
397454
{currentField.contentTypeName + " : "}
398455
</div>
399-
</> : null
400-
}
456+
</>
457+
) : null}
401458
{currentField.prefixIcon ? (
402459
<div
403460
className={classNames(

0 commit comments

Comments
 (0)