diff --git a/connectors/connector-google/server.ts b/connectors/connector-google/server.ts index 439de510..773704a4 100644 --- a/connectors/connector-google/server.ts +++ b/connectors/connector-google/server.ts @@ -72,37 +72,40 @@ export const googleServer = { } return {} }, - // eslint-disable-next-line @typescript-eslint/require-await - async listIntegrations() { + async listIntegrations(params: unknown) { + const integrationsToFilter = (params as any)?.ccfg?.integrations ?? {} + + const integrations = [ + { + id: 'drive', + name: 'Google Drive', + // TODO: Differ oauth scope use in Connect based on which integration + raw_data: {} as any, + verticals: ['file-storage'], + updated_at: new Date().toISOString(), + logo_url: '/_assets/logo-google-drive.svg', + }, + { + id: 'gmail', + name: 'Gmail', + raw_data: {} as any, + verticals: ['email'], + updated_at: new Date().toISOString(), + logo_url: '/_assets/logo-google-gmail.svg', + }, + { + id: 'calendar', + name: 'Google Calendar', + raw_data: {} as any, + verticals: ['calendar'], + updated_at: new Date().toISOString(), + logo_url: '/_assets/logo-google-calendar.svg', + }, + ].filter((int) => integrationsToFilter[int.id]?.enabled === true) as any + return { has_next_page: false, - items: [ - { - id: 'drive', - name: 'Google Drive', - // TODO: Differ oauth scope use in Connect based on which integration - raw_data: {} as any, - verticals: ['file-storage'], - updated_at: new Date().toISOString(), - logo_url: '/_assets/logo-google-drive.svg', - }, - { - id: 'gmail', - name: 'Gmail', - raw_data: {} as any, - verticals: ['email'], - updated_at: new Date().toISOString(), - logo_url: '/_assets/logo-google-gmail.svg', - }, - { - id: 'calendar', - name: 'Google Calendar', - raw_data: {} as any, - verticals: ['calendar'], - updated_at: new Date().toISOString(), - logo_url: '/_assets/logo-google-calendar.svg', - }, - ], + items: integrations, next_cursor: null, } }, diff --git a/packages/engine-backend/router/connectorRouter.ts b/packages/engine-backend/router/connectorRouter.ts index 8d1a8ed2..9fafefcb 100644 --- a/packages/engine-backend/router/connectorRouter.ts +++ b/packages/engine-backend/router/connectorRouter.ts @@ -130,6 +130,7 @@ const _connectorRouter = trpc.router({ zPaginationParams.extend({ name: z.string(), search_text: z.string().nullish(), + ccfg: z.object({}).passthrough().optional(), }), ) // TODO: Add deterministic type for the output here @@ -138,7 +139,7 @@ const _connectorRouter = trpc.router({ items: z.array(zIntegration), }), ) - .query(({ctx, input: {name, ...params}}) => { + .query(async ({ctx, input: {name, ccfg, ...params}}) => { const connector = ctx.connectorMap[name] if (!connector) { throw new TRPCError({ @@ -147,7 +148,7 @@ const _connectorRouter = trpc.router({ }) } if (connector.listIntegrations) { - return connector.listIntegrations(params).then((res) => ({ + return connector.listIntegrations({ccfg, ...params}).then((res) => ({ ...res, items: res.items.map((item) => ({ ...item, @@ -215,6 +216,7 @@ export const connectorRouter = trpc.mergeRouters( .listConnectorIntegrations({ name: extractId(ccfg.id)[1], search_text: input.search_text, + ccfg, }) .then((res) => ({ ...res, diff --git a/packages/engine-frontend/components/IntegrationSearch.tsx b/packages/engine-frontend/components/IntegrationSearch.tsx index 640ef83f..113e59de 100644 --- a/packages/engine-frontend/components/IntegrationSearch.tsx +++ b/packages/engine-frontend/components/IntegrationSearch.tsx @@ -34,21 +34,10 @@ export function IntegrationSearch({ connector_config_ids: connectorConfigs.map((ccfg) => ccfg.id), search_text: searchText, }) - const ints = listIntegrationsRes.data?.items - .map((int) => ({ - ...int, - ccfg: connectorConfigs.find( - (ccfg) => ccfg.id === int.connector_config_id, - )!, - })) - .filter((int) => { - if (int.connector_name === 'google') { - // these are nested integrations within a connector i.e. int_google_gmail - // so we only want to show those enabled in the integrations list of the connector config - return int.ccfg.integrations.some((i) => int.id.includes(i)) - } - return true - }) + const ints = listIntegrationsRes.data?.items.map((int) => ({ + ...int, + ccfg: connectorConfigs.find((ccfg) => ccfg.id === int.connector_config_id)!, + })) const categories = Array.from( new Set(connectorConfigs.flatMap((ccfg) => ccfg.verticals)),