Skip to content

Commit 0dea0ed

Browse files
Linting
1 parent 7fa33d9 commit 0dea0ed

File tree

4 files changed

+66
-53
lines changed

4 files changed

+66
-53
lines changed

packages/connect-react/src/components/ControlSelect.tsx

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { useFormFieldContext } from "../hooks/form-field-context";
1111
import { useCustomize } from "../hooks/customization-context";
1212
import type { BaseReactSelectProps } from "../hooks/customization-context";
1313
import { LoadMoreButton } from "./LoadMoreButton";
14-
import { isString, isOptionWithValue, OptionWithValue } from "../utils/type-guards";
14+
import {
15+
isString, isOptionWithValue, OptionWithValue,
16+
} from "../utils/type-guards";
1517

1618
// XXX T and ConfigurableProp should be related
1719
type ControlSelectProps<T> = {
@@ -43,37 +45,37 @@ export function ControlSelect<T>({
4345

4446
useEffect(() => {
4547
// Ensure all options have proper primitive values for label/value
46-
const sanitizedOptions = options.map(option => {
47-
if (typeof option === 'string') return option;
48-
48+
const sanitizedOptions = options.map((option) => {
49+
if (typeof option === "string") return option;
50+
4951
// If option has __lv wrapper, extract the inner option
50-
if (option && typeof option === 'object' && '__lv' in option) {
52+
if (option && typeof option === "object" && "__lv" in option) {
5153
const innerOption = option.__lv;
5254
return {
53-
label: String(innerOption?.label || innerOption?.value || ''),
54-
value: innerOption?.value
55+
label: String(innerOption?.label || innerOption?.value || ""),
56+
value: innerOption?.value,
5557
};
5658
}
57-
59+
5860
// Handle nested label and value objects
59-
let actualLabel = '';
61+
let actualLabel = "";
6062
let actualValue = option.value;
61-
63+
6264
// Extract nested label
63-
if (option.label && typeof option.label === 'object' && 'label' in option.label) {
64-
actualLabel = String(option.label.label || '');
65+
if (option.label && typeof option.label === "object" && "label" in option.label) {
66+
actualLabel = String(option.label.label || "");
6567
} else {
66-
actualLabel = String(option.label || option.value || '');
68+
actualLabel = String(option.label || option.value || "");
6769
}
68-
70+
6971
// Extract nested value
70-
if (option.value && typeof option.value === 'object' && 'value' in option.value) {
72+
if (option.value && typeof option.value === "object" && "value" in option.value) {
7173
actualValue = option.value.value;
7274
}
73-
75+
7476
return {
7577
label: actualLabel,
76-
value: actualValue
78+
value: actualValue,
7779
};
7880
});
7981
setSelectOptions(sanitizedOptions)
@@ -160,7 +162,7 @@ export function ControlSelect<T>({
160162
}
161163

162164
const props = select.getProps("controlSelect", baseSelectProps)
163-
165+
164166
if (showLoadMoreButton) {
165167
props.components = {
166168
// eslint-disable-next-line react/prop-types
@@ -180,19 +182,25 @@ export function ControlSelect<T>({
180182
}
181183
const newOption = createOption(inputValue)
182184
let newRawValue = newOption
183-
185+
184186
// NEVER add wrapped objects to selectOptions - only clean {label, value} objects
185-
const cleanSelectOptions = selectOptions.map(opt => {
186-
if (typeof opt === 'string') return opt;
187-
if (opt && typeof opt === 'object' && '__lv' in opt) {
188-
return {label: String(opt.__lv?.label || ''), value: opt.__lv?.value};
187+
const cleanSelectOptions = selectOptions.map((opt) => {
188+
if (typeof opt === "string") return opt;
189+
if (opt && typeof opt === "object" && "__lv" in opt) {
190+
return {
191+
label: String(opt.__lv?.label || ""),
192+
value: opt.__lv?.value,
193+
};
189194
}
190195
return opt;
191196
});
192-
193-
const newSelectOptions = [newOption, ...cleanSelectOptions];
197+
198+
const newSelectOptions = [
199+
newOption,
200+
...cleanSelectOptions,
201+
];
194202
setSelectOptions(newSelectOptions);
195-
203+
196204
if (prop.type.endsWith("[]")) {
197205
if (Array.isArray(rawValue)) {
198206
newRawValue = [
@@ -242,33 +250,32 @@ export function ControlSelect<T>({
242250
: Select;
243251

244252
// Final safety check - ensure NO __lv wrapped objects reach react-select
245-
const cleanedOptions = selectOptions.map(opt => {
246-
if (typeof opt === 'string') return opt;
247-
if (opt && typeof opt === 'object' && '__lv' in opt && opt.__lv) {
248-
let actualLabel = '';
253+
const cleanedOptions = selectOptions.map((opt) => {
254+
if (typeof opt === "string") return opt;
255+
if (opt && typeof opt === "object" && "__lv" in opt && opt.__lv) {
256+
let actualLabel = "";
249257
let actualValue = opt.__lv.value;
250-
258+
251259
// Handle nested label in __lv
252-
if (opt.__lv.label && typeof opt.__lv.label === 'object' && 'label' in opt.__lv.label) {
253-
actualLabel = String(opt.__lv.label.label || '');
260+
if (opt.__lv.label && typeof opt.__lv.label === "object" && "label" in opt.__lv.label) {
261+
actualLabel = String(opt.__lv.label.label || "");
254262
} else {
255-
actualLabel = String(opt.__lv.label || opt.__lv.value || '');
263+
actualLabel = String(opt.__lv.label || opt.__lv.value || "");
256264
}
257-
265+
258266
// Handle nested value in __lv
259-
if (opt.__lv.value && typeof opt.__lv.value === 'object' && 'value' in opt.__lv.value) {
267+
if (opt.__lv.value && typeof opt.__lv.value === "object" && "value" in opt.__lv.value) {
260268
actualValue = opt.__lv.value.value;
261269
}
262-
270+
263271
return {
264272
label: actualLabel,
265-
value: actualValue
273+
value: actualValue,
266274
};
267275
}
268276
return opt;
269277
});
270278

271-
272279
return (
273280
<MaybeCreatableSelect
274281
inputId={id}
@@ -279,10 +286,14 @@ export function ControlSelect<T>({
279286
isClearable={true}
280287
required={!prop.optional}
281288
getOptionLabel={(option) => {
282-
return typeof option === 'string' ? option : String(option?.label || option?.value || '');
289+
return typeof option === "string"
290+
? option
291+
: String(option?.label || option?.value || "");
283292
}}
284293
getOptionValue={(option) => {
285-
return typeof option === 'string' ? option : String(option?.value || '');
294+
return typeof option === "string"
295+
? option
296+
: String(option?.value || "");
286297
}}
287298
onChange={handleChange}
288299
{...props}

packages/connect-react/src/components/RemoteOptionsContainer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { useFormContext } from "../hooks/form-context";
55
import { useFormFieldContext } from "../hooks/form-field-context";
66
import { useFrontendClient } from "../hooks/frontend-client-context";
77
import { ControlSelect } from "./ControlSelect";
8-
import { isString, isOptionWithValue } from "../utils/type-guards";
8+
import {
9+
isString, isOptionWithValue,
10+
} from "../utils/type-guards";
911

1012
export type RemoteOptionsContainerProps = {
1113
queryEnabled?: boolean;
@@ -146,7 +148,7 @@ export function RemoteOptionsContainer({ queryEnabled }: RemoteOptionsContainerP
146148
value = o.value;
147149
} else {
148150
// Skip items that don't match expected format
149-
console.warn('Skipping invalid option:', o);
151+
console.warn("Skipping invalid option:", o);
150152
continue;
151153
}
152154
if (allValues.has(value)) {

packages/connect-react/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ export * from "./hooks/use-component";
3333
export * from "./hooks/use-components";
3434

3535
// Debug info for development
36-
import packageJson from '../package.json';
36+
import packageJson from "../package.json";
3737

3838
export const DEBUG_INFO = {
3939
version: `${packageJson.version}-dev`,
4040
buildTime: new Date().toISOString(),
41-
source: "local-development"
41+
source: "local-development",
4242
};
4343

4444
// Auto-log debug info in development
45-
if (typeof window !== 'undefined') {
46-
console.log('🔧 @pipedream/connect-react DEBUG:', DEBUG_INFO);
45+
if (typeof window !== "undefined") {
46+
console.log("🔧 @pipedream/connect-react DEBUG:", DEBUG_INFO);
4747
}

packages/connect-react/src/utils/type-guards.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ export interface OptionWithValue {
55
}
66

77
export function isString(value: unknown): value is string {
8-
return typeof value === 'string';
8+
return typeof value === "string";
99
}
1010

1111
export function isOptionWithValue(value: unknown): value is OptionWithValue {
1212
return (
1313
value !== null &&
14-
typeof value === 'object' &&
14+
typeof value === "object" &&
1515
!Array.isArray(value) &&
16-
'value' in value
16+
"value" in value
1717
);
1818
}
1919

2020
export function isStringArray(value: unknown): value is string[] {
21-
return Array.isArray(value) && value.every(item => typeof item === 'string');
21+
return Array.isArray(value) && value.every((item) => typeof item === "string");
2222
}
2323

2424
export function isOptionArray(value: unknown): value is OptionWithValue[] {
25-
return Array.isArray(value) && value.every(item => isOptionWithValue(item));
25+
return Array.isArray(value) && value.every((item) => isOptionWithValue(item));
2626
}
2727

2828
export function normalizeOption(option: unknown): OptionWithValue | string {
@@ -40,4 +40,4 @@ export function normalizeOptions(options: unknown): Array<OptionWithValue | stri
4040
return [];
4141
}
4242
return options.map(normalizeOption);
43-
}
43+
}

0 commit comments

Comments
 (0)