AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(connections): searching OAuth2 permissions filters the list again (#15811)
Bartosz Majewskie136e0148a96
diff --git a/packages/web/src/app/connections/oauth2-connection-settings.tsx b/packages/web/src/app/connections/oauth2-connection-settings.tsxindex a9f518e070b..1181a62f80c 100644--- a/packages/web/src/app/connections/oauth2-connection-settings.tsx+++ b/packages/web/src/app/connections/oauth2-connection-settings.tsx@@ -31,6 +31,7 @@ import {MultiSelectValue,} from '@/components/custom/multi-select';import { Button } from '@/components/ui/button';+import { CommandEmpty } from '@/components/ui/command';import {FormControl,FormField,@@ -88,6 +89,10 @@ function OAuth2ConnectionSettings({grantType === OAuth2GrantType.AUTHORIZATION_CODE;const [loading, setLoading] = useState(false);const [scopesEditing, setScopesEditing] = useState(false);+ const [scopeSearch, setScopeSearch] = useState('');+ const filteredScopes = authProperty.scope.filter((scope) =>+ scope.toLowerCase().includes(scopeSearch.toLowerCase()),+ );return (<div className="flex flex-col gap-4">@@ -188,6 +193,12 @@ function OAuth2ConnectionSettings({value: scope,label: scope,}))}+ onSearch={(keyword) => setScopeSearch(keyword ?? '')}+ onOpenChange={(open) => {+ if (!open) {+ setScopeSearch('');+ }+ }}><MultiSelectTrigger>{selected.length < 10 ? (@@ -205,24 +216,31 @@ function OAuth2ConnectionSettings({placeholder={t('Search permissions')}/><MultiSelectList>- <div- onClick={(e) => {- e.stopPropagation();- e.preventDefault();- field.onChange(authProperty.scope.join(' '));- }}- >- <MultiSelectItem>- {t('Select All')}- </MultiSelectItem>- </div>- {authProperty.scope.map((scope) => (+ {scopeSearch === '' && (+ <div+ onClick={(e) => {+ e.stopPropagation();+ e.preventDefault();+ field.onChange(authProperty.scope.join(' '));+ }}+ >+ <MultiSelectItem>+ {t('Select All')}+ </MultiSelectItem>+ </div>+ )}+ {filteredScopes.map((scope) => (<MultiSelectItem key={scope} value={scope}><span className="truncate min-w-0">{scope}</span></MultiSelectItem>))}+ {filteredScopes.length === 0 && (+ <CommandEmpty>+ {t('No results found.')}+ </CommandEmpty>+ )}</MultiSelectList></MultiSelectContent></MultiSelect>diff --git a/packages/web/src/components/custom/multi-select.tsx b/packages/web/src/components/custom/multi-select.tsxindex eb51420e295..2ffdd2eecbc 100644--- a/packages/web/src/components/custom/multi-select.tsx+++ b/packages/web/src/components/custom/multi-select.tsx@@ -44,9 +44,7 @@ interface MultiSelectContextValue {onDeselect(value: string, item: MultiSelectOptionItem): void;- onSearch?(keyword: string | undefined): void;-- filter?: boolean | ((keyword: string, current: string) => boolean);+ onSearch(keyword: string | undefined): void;disabled?: boolean;@@ -79,8 +77,7 @@ type MultiSelectProps = React.ComponentPropsWithoutRef<onSelect?(value: string, item: MultiSelectOptionItem): void;onDeselect?(value: string, item: MultiSelectOptionItem): void;defaultValue?: string[];- onSearch?(keyword: string | undefined): void;- filter?: boolean | ((keyword: string, current: string) => boolean);+ onSearch(keyword: string | undefined): void;disabled?: boolean;maxCount?: number;items?: MultiSelectOptionItem[];@@ -96,7 +93,6 @@ const MultiSelect: React.FC<MultiSelectProps> = ({onOpenChange,defaultOpen,onSearch,- filter,disabled,maxCount,items = [],@@ -162,7 +158,6 @@ const MultiSelect: React.FC<MultiSelectProps> = ({value: value || [],open: open || false,onSearch,- filter,disabled,maxCount,onSelect: handleSelect,@@ -173,7 +168,6 @@ const MultiSelect: React.FC<MultiSelectProps> = ({value,open,onSearch,- filter,disabled,maxCount,handleSelect,@@ -417,7 +411,10 @@ const MultiSelectContent = React.forwardRef<if (!context.open) {return fragmentRef.current- ? createPortal(<Command>{children}</Command>, fragmentRef.current)+ ? createPortal(+ <Command shouldFilter={false}>{children}</Command>,+ fragmentRef.current,+ ): null;}@@ -449,7 +446,7 @@ const MultiSelectContent = React.forwardRef<><CommandclassName={cn('px-1 max-h-96 w-full', className)}- shouldFilter={!context.onSearch}+ shouldFilter={false}>{children}</Command>diff --git a/packages/web/test/app/connections/oauth2-connection-settings.test.tsx b/packages/web/test/app/connections/oauth2-connection-settings.test.tsxnew file mode 100644index 00000000000..c78d198d488--- /dev/null+++ b/packages/web/test/app/connections/oauth2-connection-settings.test.tsx@@ -0,0 +1,217 @@+/**+ * @vitest-environment jsdom+ */+import { PieceAuth } from '@activepieces/pieces-framework';+import {+ AppConnectionType,+ OAuth2GrantType,+ PackageType,+ PieceType,+} from '@activepieces/shared';+import * as React from 'react';+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { FormProvider, useForm } from 'react-hook-form';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('i18next', () => ({ t: (key: string) => key }));+vi.mock('@/hooks/flags-hooks', () => ({+ flagsHooks: { useFlag: () => ({ data: undefined }) },+}));+vi.mock('@/features/connections', () => ({+ oauth2Utils: { resolveRedirectUrl: () => 'https://redirect.example' },+}));+vi.mock('@/features/connections/api/app-connections', () => ({+ appConnectionsApi: {},+}));+vi.mock('@/lib/api', () => ({ api: {} }));+vi.mock('@/app/builder/piece-properties/generic-properties-form', () => ({+ GenericPropertiesForm: () => null,+}));++import { OAuth2ConnectionSettings } from '@/app/connections/oauth2-connection-settings';++declare global {+ var IS_REACT_ACT_ENVIRONMENT: boolean;+}++Element.prototype.scrollIntoView = () => undefined;+globalThis.ResizeObserver = class {+ observe() {}+ unobserve() {}+ disconnect() {}+} as never;+if (!globalThis.PointerEvent) {+ globalThis.PointerEvent = MouseEvent as never;+}+globalThis.IS_REACT_ACT_ENVIRONMENT = true;++const SCOPES = [+ 'https://www.googleapis.com/auth/gmail.send',+ 'https://www.googleapis.com/auth/gmail.modify',+ 'https://www.googleapis.com/auth/gmail.readonly',+];++const AUTH = PieceAuth.OAuth2({+ authUrl: 'https://accounts.google.com/o/oauth2/auth',+ tokenUrl: 'https://oauth2.googleapis.com/token',+ required: true,+ scope: SCOPES,+});++const PIECE = {+ name: '@activepieces/piece-gmail',+ displayName: 'Gmail',+ logoUrl: 'https://cdn.activepieces.com/pieces/gmail.png',+ description: '',+ authors: [],+ version: '0.1.0',+ actions: 0,+ triggers: 0,+ contextInfo: undefined,+ projectUsage: 0,+ pieceType: PieceType.OFFICIAL,+ packageType: PackageType.REGISTRY,+};++function Harness() {+ const form = useForm({+ defaultValues: {+ request: {+ value: { client_id: 'id', client_secret: 'secret', scope: '' },+ },+ },+ });+ return (+ <FormProvider {...form}>+ <OAuth2ConnectionSettings+ authProperty={AUTH}+ oauth2App={{+ oauth2Type: AppConnectionType.CLOUD_OAUTH2,+ clientId: 'client-id',+ }}+ piece={PIECE}+ grantType={OAuth2GrantType.CLIENT_CREDENTIALS}+ />+ </FormProvider>+ );+}++const click = (element: Element | null | undefined) => {+ act(() => {+ element?.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }));+ element?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ });+};++const openTrigger = () =>+ click(+ Array.from(document.querySelectorAll('button')).find((button) =>+ button.textContent?.includes('Select permissions'),+ ),+ );++const openPicker = () => {+ act(() => {+ document+ .querySelector<HTMLElement>('[role="button"]')+ ?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ });+ openTrigger();+};++const closePicker = () => {+ act(() => {+ document+ .querySelector('[cmdk-input]')+ ?.dispatchEvent(+ new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }),+ );+ });+};++const typeSearch = (value: string) => {+ const input = document.querySelector<HTMLInputElement>('[cmdk-input]');+ const setter = Object.getOwnPropertyDescriptor(+ HTMLInputElement.prototype,+ 'value',+ )?.set;+ act(() => {+ setter?.call(input, value);+ input?.dispatchEvent(new Event('input', { bubbles: true }));+ });+ return input;+};++const listedItems = () =>+ Array.from(document.querySelectorAll('[cmdk-item]')).map(+ (item) => item.textContent,+ );++describe('OAuth2ConnectionSettings scope search', () => {+ let root: Root | undefined;+ let unhandled: unknown[] = [];+ const collect = (error: unknown) => unhandled.push(error);++ beforeEach(() => {+ unhandled = [];+ process.on('uncaughtException', collect);+ });++ afterEach(() => {+ act(() => root?.unmount());+ process.off('uncaughtException', collect);+ document.body.innerHTML = '';+ expect(unhandled).toEqual([]);+ });++ const mountAndOpen = () => {+ act(() => {+ root = createRoot(+ document.body.appendChild(document.createElement('div')),+ );+ root.render(<Harness />);+ });+ openPicker();+ };++ it('keeps the typed keyword and filters the scope list', () => {+ mountAndOpen();+ expect(listedItems()).toEqual(['Select All', ...SCOPES]);++ const input = typeSearch('modify');++ expect(input?.value).toBe('modify');+ expect(listedItems()).toEqual([+ 'https://www.googleapis.com/auth/gmail.modify',+ ]);++ typeSearch('');+ expect(listedItems()).toEqual(['Select All', ...SCOPES]);+ });++ it('shows the empty state when no scope matches', () => {+ mountAndOpen();++ typeSearch('zzz');++ expect(listedItems()).toEqual([]);+ expect(document.querySelector('[cmdk-empty]')?.textContent).toBe(+ 'No results found.',+ );+ });++ it('resets the search when the picker is closed and reopened', () => {+ mountAndOpen();+ typeSearch('modify');++ closePicker();+ expect(document.querySelector('[cmdk-item]')).toBeNull();+ openTrigger();++ expect(+ document.querySelector<HTMLInputElement>('[cmdk-input]')?.value,+ ).toBe('');+ expect(listedItems()).toEqual(['Select All', ...SCOPES]);+ });+});