Skip to content

Commit e2b020a

Browse files
committed
SelectApp has a SingleValue now with icon
1 parent b38f664 commit e2b020a

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useApps } from "../hooks/use-apps";
66
import { AppResponse } from "@pipedream/sdk";
77

88
type SelectAppProps = {
9-
value?: Partial<AppResponse> & { name_slug: string; };
9+
value?: Partial<AppResponse> & { name_slug: string; name: string; id: string };
1010
onChange?: (app?: AppResponse) => void;
1111
};
1212

@@ -25,7 +25,9 @@ export function SelectApp({
2525
} = useApps({
2626
q,
2727
});
28-
const { Option } = components;
28+
console.log("apps: ", apps);
29+
const { Option, SingleValue } = components;
30+
const selectedValue = apps?.find((o) => o.name_slug === value?.name_slug) || null;
2931
return (
3032
<Select
3133
instanceId={instanceId}
@@ -52,14 +54,38 @@ export function SelectApp({
5254
</div>
5355
</Option>
5456
),
57+
SingleValue: (singleValueProps) => (
58+
<SingleValue {...singleValueProps}>
59+
<div style={{ display: "flex", gap: 10, alignItems: "center" }}>
60+
<img
61+
src={`https://pipedream.com/s.v0/${singleValueProps.data.id}/logo/48`}
62+
style={{ height: 24, width: 24 }}
63+
alt={singleValueProps.data.name}
64+
/>
65+
<span style={{ whiteSpace: "nowrap" }}>
66+
{singleValueProps.data.name}
67+
</span>
68+
</div>
69+
</SingleValue>
70+
),
5571
IndicatorSeparator: () => null,
5672
}}
5773
options={apps || []}
74+
//options={[...(value ? [value] : []), ...apps]}
5875
getOptionLabel={(o) => o.name || o.name_slug} // TODO fetch initial value app so we show name
5976
getOptionValue={(o) => o.name_slug}
60-
value={value}
61-
onChange={(o) => onChange?.((o as AppResponse) || undefined)}
62-
onInputChange={(v) => setQ(v)}
77+
value={selectedValue}
78+
// value={apps?.find((app) => app.name_slug === value?.name_slug) || null}
79+
onChange={(o) => {
80+
console.log("onChange", o);
81+
onChange?.((o as AppResponse) || undefined)
82+
}}
83+
onInputChange={(v) => {
84+
console.log("onInputChange", v);
85+
if (v) {
86+
setQ(v)
87+
}
88+
}}
6389
isLoading={isLoading}
6490
/>
6591
);
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { useId } from "react";
1+
import { useId, useEffect } from "react";
22
import Select from "react-select";
33
import { useComponents } from "../hooks/use-components";
4-
import {
5-
AppResponse, V1Component,
6-
} from "@pipedream/sdk";
4+
import { AppResponse, V1Component } from "@pipedream/sdk";
75

86
type SelectComponentProps = {
9-
app?: Partial<AppResponse> & { name_slug: string; };
7+
app?: Partial<AppResponse> & { name_slug: string };
108
componentType?: "action" | "trigger";
11-
value?: Partial<V1Component> & { key: string; };
9+
value?: Partial<V1Component> & { key: string };
1210
onChange?: (component?: V1Component) => void;
1311
};
1412

@@ -19,21 +17,18 @@ export function SelectComponent({
1917
onChange,
2018
}: SelectComponentProps) {
2119
const instanceId = useId();
22-
const {
23-
isLoading,
24-
// TODO error
25-
components,
26-
} = useComponents({
20+
const { isLoading, components } = useComponents({
2721
app: app?.name_slug,
2822
componentType,
2923
});
24+
3025
return (
3126
<Select
3227
instanceId={instanceId}
3328
className="react-select-container text-sm"
3429
classNamePrefix="react-select"
3530
options={components}
36-
getOptionLabel={(o) => o.name || o.key} // TODO fetch default component so we show name (or just prime correctly in demo)
31+
getOptionLabel={(o) => o.name || o.key}
3732
getOptionValue={(o) => o.key}
3833
value={value}
3934
onChange={(o) => onChange?.((o as V1Component) || undefined)}
@@ -44,3 +39,4 @@ export function SelectComponent({
4439
/>
4540
);
4641
}
42+

packages/connect-react/src/hooks/use-apps.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ export const useApps = (input?: GetAppsOpts) => {
1313
input,
1414
],
1515
queryFn: () => client.apps(input),
16+
// keepPreviousData: true,
17+
// staleTime: 1000 * 60 * 5, // Cache results for 5 minutes
18+
// cacheTime: 1000 * 60 * 10, // Keep cache for 10 minutes
1619
});
1720

1821
return {
1922
...query,
20-
apps: query.data?.data,
23+
apps: query.data?.data || [],
2124
};
2225
};

0 commit comments

Comments
 (0)