Skip to content

Commit 80ec405

Browse files
committed
meh fixes to no-explicit-any
1 parent 70bfbe0 commit 80ec405

File tree

8 files changed

+108
-96
lines changed

8 files changed

+108
-96
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
} from "@pipedream/sdk";
99
import { InternalComponentForm } from "./InternalComponentForm";
1010

11-
export type ComponentFormProps<T extends ConfigurableProps = any> = {
11+
export type ComponentFormProps<T extends ConfigurableProps> = {
1212
userId: string;
1313
component: V1Component<T>;
1414
configuredProps?: ConfiguredProps<T>; // XXX value?
@@ -19,7 +19,7 @@ export type ComponentFormProps<T extends ConfigurableProps = any> = {
1919
hideOptionalProps?: boolean;
2020
};
2121

22-
export function ComponentForm(props: ComponentFormProps) {
22+
export function ComponentForm<T extends ConfigurableProps>(props: ComponentFormProps<T>) {
2323
return (
2424
<FormContextProvider props={props}>
2525
<InternalComponentForm />

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { useCustomize } from "../hooks/customization-context";
33
import type { CSSProperties } from "react";
44

55
export function ControlAny() {
6-
const props = useFormFieldContext();
6+
const formFieldContext = useFormFieldContext();
77
const {
88
id, onChange, value,
9-
} = props;
9+
} = formFieldContext;
1010
const {
1111
getProps, theme,
1212
} = useCustomize();
@@ -29,7 +29,7 @@ export function ControlAny() {
2929
id={id}
3030
value={jsonValue}
3131
onChange={(e) => onChange(e.target.value)}
32-
{...getProps("controlAny", baseStyles, props)}
32+
{...getProps("controlAny", baseStyles, formFieldContext)}
3333
/>
3434
);
3535
}

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

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import { useCustomize } from "../hooks/customization-context";
66
import type { BaseReactSelectProps } from "../hooks/customization-context";
77
import { useMemo } from "react";
88
import type { CSSProperties } from "react";
9-
109
import type { OptionProps } from "react-select";
11-
import {
10+
import type {
1211
AppResponse, ConfigurablePropApp,
1312
} from "@pipedream/sdk";
1413

15-
const BaseOption = (props: OptionProps<any>) => {
14+
const BaseOption = (props: OptionProps<AppResponse>) => {
1615
// const imgSrc =
1716
// props.data.img_src ?? `https://pipedream.com/s.v0/${props.data.id}/logo/48`
1817
return (
@@ -56,7 +55,7 @@ export function ControlApp({ app }: ControlAppProps) {
5655
Option: BaseOption,
5756
},
5857
styles: {
59-
control: (base: {}) => ({
58+
control: (base) => ({
6059
...base,
6160
gridArea: "control",
6261
boxShadow: theme.boxShadow.input,
@@ -122,51 +121,51 @@ export function ControlApp({ app }: ControlAppProps) {
122121
app,
123122
...formFieldCtx,
124123
})}>
125-
{isLoadingAccounts ? (
124+
{isLoadingAccounts ?
126125
`Loading ${app.name} accounts...`
127-
) : accounts.length ? (
128-
<Select
129-
instanceId={id}
130-
value={selectValue}
131-
options={[
132-
...accounts,
133-
{
134-
id: "_new",
135-
name: `Connect new ${app.name} account...`,
136-
},
137-
]}
138-
{...selectProps}
139-
required={true}
140-
placeholder={`Select ${app.name} account...`}
141-
isLoading={isLoadingAccounts}
142-
isClearable={true}
143-
isSearchable={true}
144-
getOptionLabel={(a) => a.name}
145-
getOptionValue={(a) => a.id}
146-
onChange={(a) => {
147-
if (a) {
148-
if (a.id === "_new") {
126+
: accounts.length ?
127+
<Select
128+
instanceId={id}
129+
value={selectValue}
130+
options={[
131+
...accounts,
132+
{
133+
id: "_new",
134+
name: `Connect new ${app.name} account...`,
135+
},
136+
]}
137+
{...selectProps}
138+
required={true}
139+
placeholder={`Select ${app.name} account...`}
140+
isLoading={isLoadingAccounts}
141+
isClearable={true}
142+
isSearchable={true}
143+
getOptionLabel={(a) => a.name}
144+
getOptionValue={(a) => a.id}
145+
onChange={(a) => {
146+
if (a) {
147+
if (a.id === "_new") {
149148
// start connect account and then select it, etc.
150149
// TODO unset / put in loading state
151-
startConnectAccount();
150+
startConnectAccount();
151+
} else {
152+
onChange({
153+
authProvisionId: a.id,
154+
});
155+
}
152156
} else {
153-
onChange({
154-
authProvisionId: a.id,
155-
});
157+
onChange(undefined);
156158
}
157-
} else {
158-
onChange(undefined);
159-
}
160-
}}
161-
/>
162-
) : (
163-
<button type="button" {...getProps("connectButton", baseStylesConnectButton, {
164-
app,
165-
...formFieldCtx,
166-
})} onClick={() => startConnectAccount()}>
159+
}}
160+
/>
161+
:
162+
<button type="button" {...getProps("connectButton", baseStylesConnectButton, {
163+
app,
164+
...formFieldCtx,
165+
})} onClick={() => startConnectAccount()}>
167166
Connect {app.name}
168-
</button>
169-
)}
167+
</button>
168+
}
170169
</div>
171170
);
172171
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { FormContext } from "../hooks/form-context";
22
import type { FormFieldContext } from "../hooks/form-field-context";
3-
import { ConfigurableProp } from "@pipedream/sdk";
4-
3+
import {
4+
ConfigurableProp, ConfigurableProps,
5+
} from "@pipedream/sdk";
56
import { useCustomize } from "../hooks/customization-context";
67
import type { CSSProperties } from "react";
78

8-
export type ErrorsProps<T extends ConfigurableProp> = {
9+
export type ErrorsProps<T extends ConfigurableProps, U extends ConfigurableProp> = {
910
errors: string[];
10-
field: FormFieldContext<T>;
11-
form: FormContext;
11+
field: FormFieldContext<U>;
12+
form: FormContext<T>;
1213
};
1314

14-
export function Errors<T extends ConfigurableProp>(props: ErrorsProps<T>) {
15+
export function Errors<T extends ConfigurableProps, U extends ConfigurableProp>(props: ErrorsProps<T, U>) {
1516
const { errors } = props;
1617

1718
const {
@@ -31,7 +32,7 @@ export function Errors<T extends ConfigurableProp>(props: ErrorsProps<T>) {
3132
// maybe that should just be handled by FormFieldContext instead of container?
3233
return (
3334
<ul {...getProps("errors", baseStyles, props)}>
34-
{errors.map((msg) => <li {...getProps("error", baseStyles, props)}>{msg}</li>)}
35+
{errors.map((msg) => <li key={msg} {...getProps("error", baseStyles, props)}>{msg}</li>)}
3536
</ul>
3637
);
3738
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export function InternalComponentForm() {
1818
isValid,
1919
optionalPropIsEnabled,
2020
optionalPropSetEnabled,
21-
props,
21+
props: formContextProps,
2222
setSubmitting,
2323
} = formContext;
2424

2525
const {
2626
hideOptionalProps, onSubmit,
27-
} = props;
27+
} = formContextProps;
2828

2929
const {
3030
getComponents, getProps, theme,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function RemoteOptionsContainer({ queryEnabled }: RemoteOptionsContainerP
2929
setQuery,
3030
] = useState("");
3131

32-
const configuredPropsUpTo: Record<string, any> = {};
32+
const configuredPropsUpTo: Record<string, unknown> = {};
3333
for (let i = 0; i < idx; i++) {
3434
const prop = configurableProps[i];
3535
configuredPropsUpTo[prop.name] = configuredProps[prop.name];
@@ -45,9 +45,10 @@ export function RemoteOptionsContainer({ queryEnabled }: RemoteOptionsContainerP
4545
componentConfigureInput.query = query || ""; // TODO ref.value ? Is this still supported?
4646
}
4747
// exclude dynamicPropsId from the key since only affect it should have is to add / remove props but prop by name should not change!
48-
const {
49-
dynamicPropsId, ...queryKeyInput
50-
} = componentConfigureInput;
48+
const queryKeyInput = {
49+
...componentConfigureInput,
50+
}
51+
delete queryKeyInput.dynamicPropsId
5152

5253
const [
5354
error,

packages/connect-react/src/hooks/customization-context.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import {
88
components as ReactSelectComponents, mergeStyles as mergeReactSelectStyles,
99
} from "react-select";
1010
import type {
11-
ClassNamesConfig as ReactSelectClassNamesConfig, SelectComponentsConfig as ReactSelectComponentsConfig, Props as ReactSelectCustomizationProps, StylesConfig as ReactSelectStylesConfig, Theme as ReactSelectTheme,
11+
ClassNamesConfig as ReactSelectClassNamesConfig,
12+
GroupBase,
13+
Props as ReactSelectCustomizationProps,
14+
SelectComponentsConfig as ReactSelectComponentsConfig,
15+
StylesConfig as ReactSelectStylesConfig,
16+
Theme as ReactSelectTheme,
1217
} from "react-select";
1318
import type { ConfigurableProp } from "@pipedream/sdk";
1419
import {
@@ -41,15 +46,16 @@ export type ReactSelectComponents = {
4146
controlSelect: typeof ControlSelect;
4247
};
4348

44-
export type CustomComponents = {
49+
export type CustomComponents<Option, IsMulti extends boolean, Group extends GroupBase<Option>> = {
4550
[K in keyof typeof defaultComponents]: typeof defaultComponents[K]
4651
} & {
47-
[K in keyof ReactSelectComponents]: ReactSelectComponentsConfig<any, any, any>
52+
[K in keyof ReactSelectComponents]: ReactSelectComponentsConfig<Option, IsMulti, Group>
4853
};
4954

5055
export type ComponentLibrary = typeof defaultComponents;
51-
export type CustomComponentsConfig = Partial<CustomComponents>;
56+
export type CustomComponentsConfig<T, U extends boolean, V extends GroupBase<T>> = Partial<CustomComponents<T, U, V>>;
5257

58+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5359
export type CustomizationOpts<P extends ComponentProps<JSXElementConstructor<any>>> = P & {
5460
theme: Theme;
5561
};
@@ -86,16 +92,16 @@ export type CustomStylesConfig = {
8692
[K in keyof ReactSelectComponents]?: ReactSelectStylesConfig
8793
};
8894

89-
export type CustomizationConfig = {
95+
export type CustomizationConfig<Option, IsMulti extends boolean, Group extends GroupBase<Option>> = {
9096
classNames?: CustomClassNamesConfig;
9197
classNamePrefix?: string;
92-
components?: CustomComponentsConfig;
98+
components?: CustomComponentsConfig<Option, IsMulti, Group>;
9399
styles?: CustomStylesConfig;
94100
theme?: CustomThemeConfig;
95101
unstyled?: boolean;
96102
};
97103

98-
export const CustomizationContext = createContext<CustomizationConfig>({
104+
export const CustomizationContext = createContext<CustomizationConfig<any, any, any>>({ // eslint-disable-line @typescript-eslint/no-explicit-any
99105
classNames: {},
100106
classNamePrefix: "",
101107
components: {},
@@ -108,11 +114,12 @@ export type CustomizationProps = {
108114
className: string;
109115
style: CSSProperties;
110116
};
111-
export type BaseReactSelectProps = {
112-
components?: ReactSelectComponentsConfig<any, any, any>;
117+
export type BaseReactSelectProps<Option, IsMulti extends boolean, Group extends GroupBase<Option>> = {
118+
components?: ReactSelectComponentsConfig<Option, IsMulti, Group>;
113119
styles?: ReactSelectStylesConfig;
114120
};
115121

122+
// XXX refactor generics in this file to fix relationship between Key and other generics, etc.
116123
export type Customization = {
117124
getClassNames: <Key extends keyof CustomizableProps>(name: Key, props: CustomizableProps[Key]) => string;
118125
getComponents: () => ComponentLibrary;
@@ -122,9 +129,11 @@ export type Customization = {
122129
select: {
123130
getClassNamePrefix: <Key extends keyof ReactSelectComponents>(name: Key) => string;
124131
getClassNames: <Key extends keyof ReactSelectComponents>(name: Key) => ReactSelectClassNamesConfig;
132+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125133
getComponents: <Key extends keyof ReactSelectComponents>(name: Key, baseComponents?: ReactSelectComponentsConfig<any, any, any>) => ReactSelectComponentsConfig<any, any, any>;
126134
getStyles: <Key extends keyof ReactSelectComponents>(name: Key, baseStyles?: ReactSelectStylesConfig) => ReactSelectStylesConfig;
127-
getProps: <Key extends keyof ReactSelectComponents>(name: Key, baseProps?: BaseReactSelectProps) => ReactSelectCustomizationProps;
135+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
136+
getProps: <Key extends keyof ReactSelectComponents>(name: Key, baseProps?: BaseReactSelectProps<any, any, any>) => ReactSelectCustomizationProps;
128137
theme: ReactSelectTheme;
129138
};
130139
};
@@ -152,6 +161,7 @@ function createSelectCustomization(): Customization["select"] {
152161
return classNames;
153162
}
154163

164+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
155165
function getComponents<Key extends keyof ReactSelectComponents>(name: Key, baseComponents?: ReactSelectComponentsConfig<any, any, any>): ReactSelectComponentsConfig<any, any, any> {
156166
return {
157167
...ReactSelectComponents,
@@ -164,7 +174,8 @@ function createSelectCustomization(): Customization["select"] {
164174
return mergeReactSelectStyles(context.styles?.[name] ?? {}, baseStyles ?? {});
165175
}
166176

167-
function getProps<Key extends keyof ReactSelectComponents>(name: Key, baseProps?: BaseReactSelectProps): ReactSelectCustomizationProps {
177+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
178+
function getProps<Key extends keyof ReactSelectComponents>(name: Key, baseProps?: BaseReactSelectProps<any, any, any>): ReactSelectCustomizationProps {
168179
return {
169180
classNamePrefix: getClassNamePrefix(),
170181
classNames: getClassNames(name),

0 commit comments

Comments
 (0)