2025-12-10 16:36:41 +01:00
|
|
|
import { useState, useRef, useMemo } from 'react';
|
🪄 refactor: UI Polish and Admin Dialog Unification (#11108)
* refactor(OpenSidebar): removed useless classNames
* style(Header): update hover styles across various components for improved UI consistency
* style(Nav): update hover styles in AccountSettings and SearchBar for improved UI consistency
* style: update button classes for consistent hover effects and improved UI responsiveness
* style(Nav, OpenSidebar, Header, Convo): improve UI responsiveness and animation transitions
* style(PresetsMenu, NewChat): update icon sizes and improve component styling for better UI consistency
* style(Nav, Root): enhance sidebar mobile animations and responsiveness for better UI experience
* style(ExportAndShareMenu, BookmarkMenu): update icon sizes for improved UI consistency
* style: remove transition duration from button classes for improved UI responsiveness
* style(CustomMenu, ModelSelector): update background colors for improved UI consistency and responsiveness
* style(ExportAndShareMenu): update icon color for improved UI consistency
* style(TemporaryChat): refine button styles for improved UI consistency and responsiveness
* style(BookmarkNav): refactor to use DropdownPopup and remove BookmarkNavItems for improved UI consistency and functionality
* style(CustomMenu, EndpointItem): enhance UI elements for improved consistency and accessibility
* style(EndpointItem): adjust gap in icon container for improved layout consistency
* style(CustomMenu, EndpointItem): update focus ring color for improved UI consistency
* style(EndpointItem): update icon color for improved UI consistency in dark theme
* style: update focus styles for improved accessibility and consistency across components
* refactor(Nav): extract sidebar width to NAV_WIDTH constant
Centralize mobile (320px) and desktop (260px) sidebar widths in a single
exported constant to avoid magic numbers and ensure consistency.
* fix(BookmarkNav): memoize handlers used in useMemo
Wrap handleTagClick and handleClear in useCallback and add them to the
dropdownItems useMemo dependency array to prevent stale closures.
* feat: introduce FilterInput component and replace existing inputs with it across multiple components
* feat(DataTable): replace custom input with FilterInput component for improved filtering
* fix: Nested dialog overlay stacking issue
Fixes overlay appearing behind content when opening nested dialogs.
Introduced dynamic z-index calculation based on dialog depth using React context.
- First dialog: overlay z-50, content z-100
- Nested dialogs increment by 60: overlay z-110/content z-160, etc.
Preserves a11y escape key handling from #10975 and #10851.
Regression from #11008 (afb67fcf1) which increased content z-index
without adjusting overlay z-index for nested dialog scenarios.
* Refactor admin settings components to use a unified AdminSettingsDialog
- Removed redundant code from AdminSettings, MCPAdminSettings, and Memories AdminSettings components.
- Introduced AdminSettingsDialog component to handle permission management for different sections.
- Updated permission handling logic to use a consistent structure across components.
- Enhanced role selection and permission confirmation features in the new dialog.
- Improved UI consistency and maintainability by centralizing dialog functionality.
* refactor(Memory): memory management UI components and replace MemoryViewer with MemoryPanel
* refactor(Memory): enhance UI components for Memory dialogs and improve input styling
* refactor(Bookmarks): improve bookmark management UI with enhanced styling
* refactor(translations): remove redundant filter input and bookmark count entries
* refactor(Convo): integrate useShiftKey hook for enhanced keyboard interaction and improve UI responsiveness
2025-12-28 17:01:25 +01:00
|
|
|
import { Plus } from 'lucide-react';
|
2025-12-04 21:37:23 +01:00
|
|
|
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
2025-12-28 18:20:15 +01:00
|
|
|
import { Button, Spinner, FilterInput, OGDialogTrigger, TooltipAnchor } from '@librechat/client';
|
2025-12-04 21:37:23 +01:00
|
|
|
import { useLocalize, useMCPServerManager, useHasAccess } from '~/hooks';
|
|
|
|
|
import MCPConfigDialog from '~/components/MCP/MCPConfigDialog';
|
|
|
|
|
import MCPAdminSettings from './MCPAdminSettings';
|
2025-12-28 18:20:15 +01:00
|
|
|
import MCPServerDialog from './MCPServerDialog';
|
|
|
|
|
import MCPServerList from './MCPServerList';
|
2025-12-04 21:37:23 +01:00
|
|
|
|
|
|
|
|
export default function MCPBuilderPanel() {
|
|
|
|
|
const localize = useLocalize();
|
|
|
|
|
const { availableMCPServers, isLoading, getServerStatusIconProps, getConfigDialogProps } =
|
|
|
|
|
useMCPServerManager();
|
|
|
|
|
|
|
|
|
|
const hasCreateAccess = useHasAccess({
|
|
|
|
|
permissionType: PermissionTypes.MCP_SERVERS,
|
|
|
|
|
permission: Permissions.CREATE,
|
|
|
|
|
});
|
|
|
|
|
const [showDialog, setShowDialog] = useState(false);
|
2025-12-10 16:36:41 +01:00
|
|
|
const [searchQuery, setSearchQuery] = useState('');
|
2025-12-04 21:37:23 +01:00
|
|
|
const addButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
|
|
|
const configDialogProps = getConfigDialogProps();
|
|
|
|
|
|
2025-12-10 16:36:41 +01:00
|
|
|
const filteredServers = useMemo(() => {
|
|
|
|
|
if (!searchQuery.trim()) {
|
|
|
|
|
return availableMCPServers;
|
|
|
|
|
}
|
|
|
|
|
const query = searchQuery.toLowerCase();
|
|
|
|
|
return availableMCPServers.filter((server) => {
|
|
|
|
|
const displayName = server.config?.title || server.serverName;
|
|
|
|
|
return (
|
|
|
|
|
displayName.toLowerCase().includes(query) || server.serverName.toLowerCase().includes(query)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}, [availableMCPServers, searchQuery]);
|
|
|
|
|
|
2025-12-04 21:37:23 +01:00
|
|
|
return (
|
2025-12-09 17:17:23 -08:00
|
|
|
<div className="flex h-full w-full flex-col overflow-visible">
|
2025-12-28 18:20:15 +01:00
|
|
|
<div role="region" aria-label={localize('com_ui_mcp_servers')} className="mt-2 space-y-2">
|
|
|
|
|
{/* Toolbar: Search + Add Button */}
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<FilterInput
|
|
|
|
|
inputId="mcp-filter"
|
|
|
|
|
label={localize('com_ui_filter_mcp_servers')}
|
|
|
|
|
value={searchQuery}
|
|
|
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
|
|
|
containerClassName="flex-1"
|
|
|
|
|
/>
|
|
|
|
|
{hasCreateAccess && (
|
|
|
|
|
<MCPServerDialog
|
|
|
|
|
open={showDialog}
|
|
|
|
|
onOpenChange={setShowDialog}
|
|
|
|
|
triggerRef={addButtonRef}
|
|
|
|
|
>
|
|
|
|
|
<OGDialogTrigger asChild>
|
|
|
|
|
<TooltipAnchor
|
|
|
|
|
description={localize('com_ui_add_mcp')}
|
|
|
|
|
side="bottom"
|
|
|
|
|
render={
|
|
|
|
|
<Button
|
|
|
|
|
ref={addButtonRef}
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="shrink-0 bg-transparent"
|
|
|
|
|
onClick={() => setShowDialog(true)}
|
|
|
|
|
aria-label={localize('com_ui_add_mcp')}
|
|
|
|
|
>
|
|
|
|
|
<Plus className="size-4" aria-hidden="true" />
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</OGDialogTrigger>
|
|
|
|
|
</MCPServerDialog>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-12-04 21:37:23 +01:00
|
|
|
|
2025-12-28 18:20:15 +01:00
|
|
|
{/* Server Cards List */}
|
2025-12-04 21:37:23 +01:00
|
|
|
{isLoading ? (
|
|
|
|
|
<div className="flex items-center justify-center p-8">
|
2025-12-28 18:20:15 +01:00
|
|
|
<Spinner className="size-6" aria-label={localize('com_ui_loading')} />
|
2025-12-04 21:37:23 +01:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<MCPServerList
|
2025-12-10 16:36:41 +01:00
|
|
|
servers={filteredServers}
|
2025-12-04 21:37:23 +01:00
|
|
|
getServerStatusIconProps={getServerStatusIconProps}
|
2025-12-10 16:36:41 +01:00
|
|
|
isFiltered={searchQuery.trim().length > 0}
|
2025-12-04 21:37:23 +01:00
|
|
|
/>
|
|
|
|
|
)}
|
2025-12-28 18:20:15 +01:00
|
|
|
|
|
|
|
|
{/* Config Dialog for custom user vars */}
|
2025-12-04 21:37:23 +01:00
|
|
|
{configDialogProps && <MCPConfigDialog {...configDialogProps} />}
|
2025-12-28 18:20:15 +01:00
|
|
|
|
|
|
|
|
{/* Admin Settings Section */}
|
|
|
|
|
<MCPAdminSettings />
|
2025-12-04 21:37:23 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|