diff --git a/packages/backend/src/graphql/queries/get-connected-apps.ts b/packages/backend/src/graphql/queries/get-connected-apps.ts index 2373944f..31780691 100644 --- a/packages/backend/src/graphql/queries/get-connected-apps.ts +++ b/packages/backend/src/graphql/queries/get-connected-apps.ts @@ -20,18 +20,37 @@ const getConnectedApps = async ( .count('connections.id as count') .groupBy('connections.key'); - const connectionKeys = connections.map((connection) => connection.key); + const flows = await context.currentUser + .$relatedQuery('flows') + .withGraphJoined('steps') + .orderBy('created_at', 'desc'); + + const duplicatedUsedApps = flows + .map((flow) => flow.steps.map((step) => step.appKey)) + .flat() + .filter(Boolean); + + const usedApps = [...new Set(duplicatedUsedApps)]; apps = apps - .filter((app: IApp) => connectionKeys.includes(app.key)) + .filter((app: IApp) => { + return usedApps.includes(app.key); + }) .map((app: IApp) => { const connection = connections.find( (connection) => (connection as IConnection).key === app.key ); - if (connection) { - app.connectionCount = connection.count; - } + app.connectionCount = connection?.count || 0; + app.flowCount = 0; + + flows.forEach((flow) => { + const usedFlow = flow.steps.find((step) => step.appKey === app.key); + + if (usedFlow) { + app.flowCount += 1; + } + }); return app; }); diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index ed3717d4..e841a2de 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -90,6 +90,7 @@ type App { name: String key: String connectionCount: Int + flowCount: Int iconUrl: String docUrl: String primaryColor: String diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 91130065..2ec94cfa 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -152,6 +152,7 @@ export interface IApp { authenticationSteps: IAuthenticationStep[]; reconnectionSteps: IAuthenticationStep[]; connectionCount: number; + flowCount: number; triggers: any[]; actions: any[]; connections: IConnection[]; diff --git a/packages/web/src/components/AppRow/index.tsx b/packages/web/src/components/AppRow/index.tsx index f04f9c35..e575f187 100644 --- a/packages/web/src/components/AppRow/index.tsx +++ b/packages/web/src/components/AppRow/index.tsx @@ -27,7 +27,7 @@ const countTranslation = (value: React.ReactNode) => ( function AppRow(props: AppRowProps): React.ReactElement { const formatMessage = useFormatMessage(); - const { name, primaryColor, iconUrl, connectionCount } = props.application; + const { name, primaryColor, iconUrl, connectionCount, flowCount } = props.application; return ( @@ -52,7 +52,7 @@ function AppRow(props: AppRowProps): React.ReactElement { - {formatMessage('app.flowCount', { count: countTranslation(0) })} + {formatMessage('app.flowCount', { count: countTranslation(flowCount) })} diff --git a/packages/web/src/graphql/queries/get-connected-apps.ts b/packages/web/src/graphql/queries/get-connected-apps.ts index 1c91f6e9..b4529e8e 100644 --- a/packages/web/src/graphql/queries/get-connected-apps.ts +++ b/packages/web/src/graphql/queries/get-connected-apps.ts @@ -9,6 +9,7 @@ export const GET_CONNECTED_APPS = gql` docUrl primaryColor connectionCount + flowCount supportsConnections } }