-
Notifications
You must be signed in to change notification settings - Fork 6
feat: visual design for disabled state of mcp servers page #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a3b23b5
feat: visual design for disbled state of mcp servers page
kantord 32d4cd7
consolidate test files
kantord 2c2e5d6
make cards on disabled group transparent
kantord ac69d4a
make cards also grayscale when disabled
kantord 4d877eb
add enable group button
kantord f150709
visual adjustments
kantord ca45926
margin adjustment
kantord 161d8c0
cleanup
kantord 6bf01ff
cleanup
kantord 3e6eee6
fallback for when feature flag is off
kantord 40d5e5e
visual touchup
kantord 80901b1
Merge branch 'main' into add-disabled-state-for-mcp-servers
kantord b059fea
consolidate tests
kantord 3dc383a
fix
kantord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
renderer/src/features/clients/components/__tests__/enable-group-button.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { describe, it, expect, beforeEach } from 'vitest' | ||
import { Suspense } from 'react' | ||
import { render, screen, waitFor } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { server, recordRequests } from '@/common/mocks/node' | ||
import { http, HttpResponse } from 'msw' | ||
import { PromptProvider } from '@/common/contexts/prompt/provider' | ||
import { EnableGroupButton } from '../enable-group-button' | ||
import { mswEndpoint } from '@/common/mocks/customHandlers' | ||
|
||
describe('EnableGroupButton – flows', () => { | ||
let queryClient: QueryClient | ||
|
||
beforeEach(() => { | ||
queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { retry: false }, | ||
mutations: { retry: false }, | ||
}, | ||
}) | ||
}) | ||
|
||
const renderWithProviders = (props: { groupName: string }) => | ||
render( | ||
<QueryClientProvider client={queryClient}> | ||
<PromptProvider> | ||
<Suspense fallback={null}> | ||
<EnableGroupButton {...props} /> | ||
</Suspense> | ||
</PromptProvider> | ||
</QueryClientProvider> | ||
) | ||
|
||
it('enables multiple clients for a disabled group', async () => { | ||
// Group disabled initially | ||
server.use( | ||
http.get(mswEndpoint('/api/v1beta/groups'), () => | ||
HttpResponse.json({ | ||
groups: [{ name: 'default', registered_clients: [] }], | ||
}) | ||
), | ||
http.get(mswEndpoint('/api/v1beta/clients'), () => HttpResponse.json([])) | ||
) | ||
|
||
const rec = recordRequests() | ||
|
||
const user = userEvent.setup() | ||
renderWithProviders({ groupName: 'default' }) | ||
await user.click( | ||
await screen.findByRole('button', { name: /enable group/i }) | ||
) | ||
|
||
await user.click(await screen.findByRole('switch', { name: 'vscode' })) | ||
await user.click(await screen.findByRole('switch', { name: /cursor/i })) | ||
await user.click(await screen.findByRole('button', { name: /enable/i })) | ||
|
||
await waitFor(() => | ||
expect( | ||
rec.recordedRequests.filter( | ||
(r) => | ||
r.pathname.startsWith('/api/v1beta/clients') && | ||
(r.method === 'POST' || r.method === 'DELETE') | ||
) | ||
).toHaveLength(2) | ||
) | ||
const snapshot = rec.recordedRequests | ||
.filter( | ||
(r) => | ||
r.pathname.startsWith('/api/v1beta/clients') && | ||
(r.method === 'POST' || r.method === 'DELETE') | ||
) | ||
.map(({ method, pathname, payload }) => ({ | ||
method, | ||
path: pathname, | ||
body: payload, | ||
})) | ||
expect(snapshot).toEqual([ | ||
{ | ||
method: 'POST', | ||
path: '/api/v1beta/clients', | ||
body: { name: 'vscode', groups: ['default'] }, | ||
}, | ||
{ | ||
method: 'POST', | ||
path: '/api/v1beta/clients', | ||
body: { name: 'cursor', groups: ['default'] }, | ||
}, | ||
]) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
renderer/src/features/clients/components/enable-group-button.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Button } from '@/common/components/ui/button' | ||
import { Power, Code } from 'lucide-react' | ||
import { useManageClientsDialog } from '../hooks/use-manage-clients-dialog' | ||
import { useFeatureFlag } from '@/common/hooks/use-feature-flag' | ||
import { featureFlagKeys } from '../../../../../utils/feature-flags' | ||
|
||
export function EnableGroupButton({ | ||
groupName, | ||
className, | ||
}: { | ||
groupName: string | ||
className?: string | ||
}) { | ||
const { openDialog } = useManageClientsDialog(groupName) | ||
const groupsEnabled = useFeatureFlag(featureFlagKeys.GROUPS) | ||
|
||
if (groupsEnabled) { | ||
return ( | ||
<Button | ||
variant="enable" | ||
onClick={() => | ||
openDialog({ title: 'Enable Group', confirmText: 'Enable' }) | ||
} | ||
className={className} | ||
> | ||
Enable group | ||
<Power className="ml-2 h-4 w-4" /> | ||
</Button> | ||
) | ||
} | ||
|
||
// Temporary behavior while feature flag is off: keep green look | ||
return ( | ||
<Button | ||
variant="enable" | ||
onClick={() => openDialog({ title: 'Add a client', confirmText: 'Add' })} | ||
className={className} | ||
> | ||
<Code className="mr-2 h-4 w-4" /> | ||
Add a client | ||
</Button> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
renderer/src/features/clients/hooks/use-manage-clients-dialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { usePrompt } from '@/common/hooks/use-prompt' | ||
import type { UseFormReturn } from 'react-hook-form' | ||
import { Label } from '@/common/components/ui/label' | ||
import { Switch } from '@/common/components/ui/switch' | ||
import { z } from 'zod/v4' | ||
import { zodV4Resolver } from '@/common/lib/zod-v4-resolver' | ||
import { useManageClients } from './use-manage-clients' | ||
import { useToastMutation } from '@/common/hooks/use-toast-mutation' | ||
|
||
export function useManageClientsDialog(groupName: string) { | ||
const promptForm = usePrompt() | ||
const { | ||
installedClients, | ||
defaultValues, | ||
reconcileGroupClients, | ||
getClientFieldName, | ||
} = useManageClients(groupName) | ||
|
||
const { mutateAsync: saveClients } = useToastMutation({ | ||
mutationFn: reconcileGroupClients, | ||
loadingMsg: 'Saving client settings...', | ||
successMsg: 'Client settings saved', | ||
errorMsg: 'Failed to save client settings', | ||
}) | ||
|
||
const openDialog = async (opts?: { | ||
title?: string | ||
confirmText?: string | ||
}) => { | ||
const formSchema = z.object( | ||
installedClients.reduce( | ||
(acc, client) => { | ||
const fieldName = getClientFieldName(client.client_type!) | ||
acc[fieldName] = z.boolean() | ||
return acc | ||
}, | ||
{} as Record<string, z.ZodBoolean> | ||
) | ||
) | ||
|
||
const result = await promptForm({ | ||
title: opts?.title ?? 'Manage Clients', | ||
defaultValues, | ||
resolver: zodV4Resolver(formSchema), | ||
fields: (form: UseFormReturn<Record<string, boolean>>) => ( | ||
<div className="rounded-xl border"> | ||
{installedClients.map((client) => { | ||
const fieldName = getClientFieldName(client.client_type!) | ||
const displayName = client.client_type! | ||
|
||
return ( | ||
<div | ||
key={client.client_type} | ||
className="flex items-start gap-2 border-b p-4 align-middle last:border-b-0" | ||
> | ||
<Switch | ||
id={fieldName} | ||
checked={form.watch(fieldName) as boolean} | ||
onCheckedChange={(checked) => { | ||
form.setValue(fieldName, checked) | ||
form.trigger(fieldName) | ||
}} | ||
/> | ||
|
||
<Label htmlFor={fieldName} className="text-sm font-medium"> | ||
{displayName} | ||
</Label> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
), | ||
buttons: { | ||
confirm: opts?.confirmText ?? 'Save', | ||
cancel: 'Cancel', | ||
}, | ||
}) | ||
|
||
if (result) { | ||
await saveClients(result) | ||
} | ||
} | ||
|
||
return { openDialog } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.