From feb2fddfbbf4577e6cb1c4ed504598a9b1b3639f Mon Sep 17 00:00:00 2001
From: Tony Xiao <tonyx.ca@gmail.com>
Date: Wed, 20 Dec 2023 21:15:06 -0100
Subject: [PATCH] feat: Filter connect page by connector config display name

---
 apps/web/app/connect/page.tsx                   | 10 ++++++----
 packages/engine-backend/router/endUserRouter.ts |  9 ++++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/apps/web/app/connect/page.tsx b/apps/web/app/connect/page.tsx
index 0ba8ca81..4c53d39b 100644
--- a/apps/web/app/connect/page.tsx
+++ b/apps/web/app/connect/page.tsx
@@ -1,6 +1,5 @@
 import {clerkClient} from '@clerk/nextjs'
 import Image from 'next/image'
-
 import {defConnectors} from '@usevenice/app-config/connectors/connectors.def'
 import {kAccessToken} from '@usevenice/app-config/constants'
 import {env} from '@usevenice/app-config/env'
@@ -14,11 +13,9 @@ import {
 } from '@usevenice/cdk'
 import {zConnectPageParams} from '@usevenice/engine-backend/router/endUserRouter'
 import {makeUlid, z} from '@usevenice/util'
-
 import {ClientRoot} from '@/components/ClientRoot'
 import {SuperHydrate} from '@/components/SuperHydrate'
 import {createServerComponentHelpers} from '@/lib-server/server-component-helpers'
-
 import ConnectPage from './ConnectPage'
 import {SetCookieAndRedirect} from './SetCookieAndRedirect'
 
@@ -65,9 +62,14 @@ export default async function ConnectPageContainer({
   // Implement shorthand for specifying only connectorConfigId by connectorName
   let connectorConfigId = params.connectorConfigId
   if (!connectorConfigId && params.connectorName) {
-    const ints = await ssg.listConnectorConfigInfos.fetch({
+    let ints = await ssg.listConnectorConfigInfos.fetch({
       connectorName: params.connectorName,
     })
+    if (params.connectorConfigDisplayName) {
+      ints = ints.filter(
+        (int) => int.displayName === params.connectorConfigDisplayName,
+      )
+    }
     if (ints.length === 1 && ints[0]?.id) {
       connectorConfigId = ints[0]?.id
     } else if (ints.length < 1) {
diff --git a/packages/engine-backend/router/endUserRouter.ts b/packages/engine-backend/router/endUserRouter.ts
index cd1a14b7..65a24d80 100644
--- a/packages/engine-backend/router/endUserRouter.ts
+++ b/packages/engine-backend/router/endUserRouter.ts
@@ -44,7 +44,14 @@ export const zConnectPageParams = z.object({
       'Where to send user to after connect / if they press back button',
     ),
   // TODO: How to make sure we actually have a typed api here and can use zProviderName
-  connectorName: z.string().nullish().describe('Which provider to use'),
+  connectorName: z
+    .string()
+    .nullish()
+    .describe('Filter connector config by connector name'),
+  connectorConfigDisplayName: z
+    .string()
+    .nullish()
+    .describe('Filter connector config by displayName '),
   /** Launch the conector with config right away */
   connectorConfigId: zId('ccfg').optional(),
   /** Whether to show existing resources */