From e2b020aaf5a6c60b5b3450f71ec21c22e800e3d4 Mon Sep 17 00:00:00 2001 From: Jason Endo Date: Wed, 19 Feb 2025 08:50:53 -0800 Subject: [PATCH 1/6] SelectApp has a SingleValue now with icon --- .../src/components/SelectApp.tsx | 36 ++++++++++++++++--- .../src/components/SelectComponent.tsx | 20 +++++------ packages/connect-react/src/hooks/use-apps.tsx | 5 ++- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/packages/connect-react/src/components/SelectApp.tsx b/packages/connect-react/src/components/SelectApp.tsx index 61fe7bd27098f..6ca2ecfaed030 100644 --- a/packages/connect-react/src/components/SelectApp.tsx +++ b/packages/connect-react/src/components/SelectApp.tsx @@ -6,7 +6,7 @@ import { useApps } from "../hooks/use-apps"; import { AppResponse } from "@pipedream/sdk"; type SelectAppProps = { - value?: Partial & { name_slug: string; }; + value?: Partial & { name_slug: string; name: string; id: string }; onChange?: (app?: AppResponse) => void; }; @@ -25,7 +25,9 @@ export function SelectApp({ } = useApps({ q, }); - const { Option } = components; + console.log("apps: ", apps); + const { Option, SingleValue } = components; + const selectedValue = apps?.find((o) => o.name_slug === value?.name_slug) || null; return ( o.name || o.key} // TODO fetch default component so we show name (or just prime correctly in demo) + getOptionLabel={(o) => o.name || o.key} getOptionValue={(o) => o.key} value={value} onChange={(o) => onChange?.((o as V1Component) || undefined)} @@ -44,3 +39,4 @@ export function SelectComponent({ /> ); } + diff --git a/packages/connect-react/src/hooks/use-apps.tsx b/packages/connect-react/src/hooks/use-apps.tsx index d14780a242ac7..8ec6c8fbdf0a0 100644 --- a/packages/connect-react/src/hooks/use-apps.tsx +++ b/packages/connect-react/src/hooks/use-apps.tsx @@ -13,10 +13,13 @@ export const useApps = (input?: GetAppsOpts) => { input, ], queryFn: () => client.apps(input), +// keepPreviousData: true, +// staleTime: 1000 * 60 * 5, // Cache results for 5 minutes +// cacheTime: 1000 * 60 * 10, // Keep cache for 10 minutes }); return { ...query, - apps: query.data?.data, + apps: query.data?.data || [], }; }; From 4eb47484daee1d958e07e5ed33c050ab2b714e6a Mon Sep 17 00:00:00 2001 From: Jason Endo Date: Wed, 19 Feb 2025 09:13:29 -0800 Subject: [PATCH 2/6] better label when component is selected --- packages/connect-react/src/components/SelectComponent.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/connect-react/src/components/SelectComponent.tsx b/packages/connect-react/src/components/SelectComponent.tsx index 1e29eac76784b..4dd122d213cc6 100644 --- a/packages/connect-react/src/components/SelectComponent.tsx +++ b/packages/connect-react/src/components/SelectComponent.tsx @@ -1,4 +1,4 @@ -import { useId, useEffect } from "react"; +import { useId } from "react"; import Select from "react-select"; import { useComponents } from "../hooks/use-components"; import { AppResponse, V1Component } from "@pipedream/sdk"; @@ -22,6 +22,8 @@ export function SelectComponent({ componentType, }); + const selectedValue = components?.find((c) => c.key === value?.key) || null; + return ( ( -
+
{singleValueProps.data.name} - + {singleValueProps.data.name}
@@ -75,7 +87,7 @@ export function SelectApp({ value={selectedValue} onChange={(o) => onChange?.((o as AppResponse) || undefined)} onInputChange={(v) => { - if(v) setQ(v) + if (v) setQ(v) }} isLoading={isLoading} /> diff --git a/packages/connect-react/src/components/SelectComponent.tsx b/packages/connect-react/src/components/SelectComponent.tsx index c870d1727fefb..b20a6073da49c 100644 --- a/packages/connect-react/src/components/SelectComponent.tsx +++ b/packages/connect-react/src/components/SelectComponent.tsx @@ -1,7 +1,9 @@ import { useId } from "react"; import Select from "react-select"; import { useComponents } from "../hooks/use-components"; -import { AppResponse, V1Component } from "@pipedream/sdk"; +import { + AppResponse, V1Component, +} from "@pipedream/sdk"; type SelectComponentProps = { app?: Partial & { name_slug: string; }; @@ -17,7 +19,9 @@ export function SelectComponent({ onChange, }: SelectComponentProps) { const instanceId = useId(); - const { isLoading, components } = useComponents({ + const { + isLoading, components, + } = useComponents({ app: app?.name_slug, componentType, });