@bevel-software/platform-core-frontend 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -3
- package/src/core/CoreAppShell.tsx +195 -56
- package/src/core/__tests__/AppChrome.test.tsx +125 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
- package/src/core/__tests__/bootstrap.test.ts +63 -0
- package/src/core/bootstrap.ts +73 -0
- package/src/core/events.ts +12 -0
- package/src/core/registry.ts +58 -9
- package/src/index.css +100 -11
- package/src/index.ts +24 -23
- package/src/lib/utils.ts +93 -117
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
- package/src/modules/access/api.ts +49 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
- package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
- package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
- package/src/modules/admin/state/admin.context.tsx +15 -6
- package/src/modules/auth/components/AccountPage.tsx +11 -11
- package/src/modules/auth/components/LoginScreen.tsx +12 -12
- package/src/modules/auth/services/sso.ts +47 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
- package/src/modules/change-requests/__tests__/author.test.ts +48 -0
- package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
- package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
- package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
- package/src/modules/change-requests/change-requests.css +22 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
- package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
- package/src/modules/change-requests/services/change-requests.api.ts +45 -0
- package/src/modules/change-requests/services/propose.api.ts +162 -0
- package/src/modules/change-requests/utils/author.ts +47 -0
- package/src/modules/change-requests/utils/conflict.ts +38 -0
- package/src/modules/change-requests/utils/diff.ts +80 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
- package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
- package/src/modules/git/components/BranchSwitcher.tsx +68 -31
- package/src/modules/git/components/DiffView.tsx +4 -4
- package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
- package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
- package/src/modules/git/components/PullNeededBanner.tsx +6 -13
- package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
- package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
- package/src/modules/git/hooks/useGitState.ts +15 -14
- package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
- package/src/modules/git/services/error-messages.ts +7 -7
- package/src/modules/git/services/git.api.ts +17 -11
- package/src/modules/git/services/pr-prompts.ts +2 -2
- package/src/modules/git/state/git.context.ts +10 -1
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
- package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
- package/src/modules/layout/breakpoints.ts +6 -0
- package/src/modules/layout/components/AppLayout.tsx +17 -5
- package/src/modules/layout/components/DemoBanner.tsx +10 -1
- package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
- package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
- package/src/modules/layout/components/SidebarFrame.tsx +317 -0
- package/src/modules/layout/components/SidebarToggle.tsx +86 -0
- package/src/modules/layout/components/SlideOverlay.tsx +1 -1
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
- package/src/modules/layout/state/sidebar.ts +200 -0
- package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
- package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
- package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
- package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
- package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
- package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
- package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
- package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
- package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
- package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
- package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
- package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
- package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
- package/src/modules/library/__tests__/auth-harness.tsx +37 -0
- package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
- package/src/modules/library/__tests__/status.test.ts +113 -20
- package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
- package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
- package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
- package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
- package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
- package/src/modules/library/components/GroupIndexRow.tsx +63 -0
- package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
- package/src/modules/library/components/GroupPage.tsx +373 -0
- package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
- package/src/modules/library/components/GroupsSidebar.tsx +338 -0
- package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
- package/src/modules/library/components/LibraryCard.tsx +123 -102
- package/src/modules/library/components/LibraryLayout.tsx +344 -0
- package/src/modules/library/components/LibraryPage.tsx +111 -227
- package/src/modules/library/components/LockGlyph.tsx +31 -0
- package/src/modules/library/components/LockedGroupView.tsx +159 -0
- package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
- package/src/modules/library/components/NewGroupDialog.tsx +112 -0
- package/src/modules/library/components/NewSkillPanel.tsx +151 -0
- package/src/modules/library/components/PageActions.tsx +156 -0
- package/src/modules/library/components/PendingSkillReview.tsx +63 -0
- package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
- package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
- package/src/modules/library/components/StatusDot.tsx +25 -0
- package/src/modules/library/components/ToolLogo.tsx +171 -0
- package/src/modules/library/components/group-page-parts.tsx +419 -0
- package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
- package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
- package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
- package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
- package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
- package/src/modules/library/hooks/useJoinRequests.ts +114 -0
- package/src/modules/library/hooks/useLibraryData.ts +134 -119
- package/src/modules/library/hooks/useSkillDetail.ts +119 -74
- package/src/modules/library/hooks/useToolPage.ts +145 -0
- package/src/modules/library/library.css +33 -245
- package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
- package/src/modules/library/routes/library-paths.ts +191 -0
- package/src/modules/library/services/groups.api.ts +189 -0
- package/src/modules/library/services/library.api.ts +291 -164
- package/src/modules/library/services/tools.api.ts +60 -0
- package/src/modules/library/state/library-context.ts +22 -0
- package/src/modules/library/state/library-data.tsx +223 -0
- package/src/modules/library/state/toast.context.ts +32 -0
- package/src/modules/library/state/toast.tsx +84 -42
- package/src/modules/library/utils/clipboard.ts +33 -0
- package/src/modules/library/utils/group-summary.ts +68 -0
- package/src/modules/library/utils/names.ts +30 -0
- package/src/modules/library/utils/navigate-external.ts +15 -0
- package/src/modules/library/utils/oauth-fragment.ts +32 -0
- package/src/modules/library/utils/personal-group.ts +36 -0
- package/src/modules/library/utils/status.ts +108 -25
- package/src/modules/library/utils/toast-duration.ts +16 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
- package/src/modules/onboarding/agent-clients.ts +48 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
- package/src/modules/onboarding/components/RootLanding.tsx +54 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
- package/src/modules/onboarding/paths.ts +9 -0
- package/src/modules/onboarding/state/onboarding.ts +191 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
- package/src/modules/pr/services/pr-approvals.api.ts +19 -0
- package/src/modules/pr/services/pr-cancel.api.ts +11 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
- package/src/modules/review/components/DiffViewer.tsx +4 -4
- package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
- package/src/modules/review/components/ReviewFileRow.tsx +10 -10
- package/src/modules/review/components/ReviewPanel.tsx +49 -17
- package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
- package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
- package/src/modules/secrets-vault/services/connect.api.ts +24 -3
- package/src/modules/settings/components/DeploymentPage.tsx +90 -0
- package/src/modules/settings/components/SettingsLayout.tsx +135 -0
- package/src/modules/settings/components/SettingsNav.tsx +114 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
- package/src/modules/settings/settings-nav-items.tsx +166 -0
- package/src/modules/setup/__tests__/setup.test.tsx +540 -0
- package/src/modules/setup/components/SetupGate.tsx +67 -0
- package/src/modules/setup/components/SetupScreen.tsx +573 -0
- package/src/modules/setup/services/setup.api.ts +106 -0
- package/src/modules/setup/utils/git-host.ts +34 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
- package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
- package/src/modules/toolbar/components/Toolbar.tsx +56 -54
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
- package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
- package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
- package/src/modules/workspace/components/EditorTabs.tsx +82 -50
- package/src/modules/workspace/components/FileExplorer.tsx +413 -189
- package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
- package/src/modules/workspace/components/FileRoute.tsx +89 -84
- package/src/modules/workspace/components/FileViewer.tsx +700 -294
- package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
- package/src/modules/workspace/components/KbFileRail.tsx +128 -0
- package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
- package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
- package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
- package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
- package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
- package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
- package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
- package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
- package/src/modules/workspace/components/renderers/index.ts +78 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
- package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
- package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
- package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
- package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
- package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
- package/src/modules/workspace/services/workspace.api.ts +9 -2
- package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
- package/src/modules/workspace/state/open-change-requests.tsx +185 -0
- package/src/modules/workspace/state/workspace.context.ts +9 -0
- package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
- package/src/modules/workspace/utils/diff.ts +130 -53
- package/src/modules/workspace/utils/fileTree.ts +7 -4
- package/src/modules/workspace/workspace.css +28 -0
- package/src/shared/components/Badge.tsx +62 -0
- package/src/shared/components/Banner.tsx +58 -0
- package/src/shared/components/Button.tsx +90 -0
- package/src/shared/components/Dialog.tsx +6 -6
- package/src/shared/components/Field.tsx +45 -0
- package/src/shared/components/IconButton.tsx +74 -0
- package/src/shared/components/ListRow.tsx +96 -0
- package/src/shared/components/Menu.tsx +88 -0
- package/src/shared/components/PageShell.tsx +8 -5
- package/src/shared/components/Surface.tsx +86 -0
- package/src/shared/components/__tests__/primitives.test.tsx +333 -0
- package/src/shared/components/index.ts +48 -0
- package/src/shared/components/useDismissableMenu.ts +71 -0
- package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
- package/src/shared/theme/index.css +12 -0
- package/src/shared/theme/measure.ts +64 -0
- package/src/shared/theme/shadows.css +34 -0
- package/src/shared/theme/tokens.css +193 -0
- package/src/test-setup.ts +9 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
- package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
- package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
- package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
- package/src/modules/library/__tests__/diff.test.ts +0 -62
- package/src/modules/library/__tests__/loadout.test.tsx +0 -72
- package/src/modules/library/components/CompareView.tsx +0 -357
- package/src/modules/library/components/DetailDialog.tsx +0 -566
- package/src/modules/library/components/GearIcon.tsx +0 -12
- package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
- package/src/modules/library/components/StatusGem.tsx +0 -21
- package/src/modules/library/components/SuggestChange.tsx +0 -171
- package/src/modules/library/components/particles.ts +0 -50
- package/src/modules/library/state/loadout.tsx +0 -129
- package/src/modules/library/utils/diff.ts +0 -102
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
- package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
- package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
- package/src/modules/pr/components/PrCancelButton.tsx +0 -99
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
- package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
- package/src/modules/pr/components/PrCommentThread.tsx +0 -168
- package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
- package/src/modules/pr/components/PrDiffPane.tsx +0 -425
- package/src/modules/pr/components/PrFileRow.tsx +0 -164
- package/src/modules/pr/components/PrFilesList.tsx +0 -53
- package/src/modules/pr/components/PrHeader.tsx +0 -45
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
- package/src/modules/pr/components/PrMergeButton.tsx +0 -268
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
- package/src/modules/pr/components/PrViewer.tsx +0 -364
- package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
- package/src/modules/pr/state/pr-viewer.context.ts +0 -34
- package/src/modules/pr/utils/bucketize-comments.ts +0 -55
- package/src/modules/pr/utils/parsePatch.ts +0 -57
- package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import type { ToolSecrets } from '../../services/tool-secrets.api';
|
|
3
5
|
import { SecretsPage } from '../SecretsPage';
|
|
4
6
|
|
|
7
|
+
const toolSecretsMock = vi.hoisted(() => ({ listToolSecrets: vi.fn() }));
|
|
8
|
+
|
|
5
9
|
vi.mock('../../services/secrets.api', () => ({
|
|
6
10
|
listSecrets: vi.fn(async () => []),
|
|
7
11
|
createOAuthSecret: vi.fn(async () => {}),
|
|
@@ -9,7 +13,7 @@ vi.mock('../../services/secrets.api', () => ({
|
|
|
9
13
|
startOAuth: vi.fn(async () => ''),
|
|
10
14
|
}));
|
|
11
15
|
vi.mock('../../services/tool-secrets.api', () => ({
|
|
12
|
-
listToolSecrets:
|
|
16
|
+
listToolSecrets: toolSecretsMock.listToolSecrets,
|
|
13
17
|
setAdminVar: vi.fn(async () => {}),
|
|
14
18
|
setUserVar: vi.fn(async () => {}),
|
|
15
19
|
setOAuthClientSecret: vi.fn(async () => {}),
|
|
@@ -17,14 +21,24 @@ vi.mock('../../services/tool-secrets.api', () => ({
|
|
|
17
21
|
deleteUserVar: vi.fn(async () => {}),
|
|
18
22
|
}));
|
|
19
23
|
|
|
24
|
+
/** The page carries links now, so it needs a router around it. */
|
|
25
|
+
function renderPage() {
|
|
26
|
+
return render(
|
|
27
|
+
<MemoryRouter>
|
|
28
|
+
<SecretsPage />
|
|
29
|
+
</MemoryRouter>,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
describe('SecretsPage', () => {
|
|
21
34
|
beforeEach(() => {
|
|
22
35
|
// Each test starts on a clean /secrets URL (no leftover fragment).
|
|
23
36
|
window.history.replaceState(null, '', '/secrets');
|
|
37
|
+
toolSecretsMock.listToolSecrets.mockReset().mockResolvedValue([]);
|
|
24
38
|
});
|
|
25
39
|
|
|
26
40
|
it('renders as a full page (no dialog) and loads the secret lists', async () => {
|
|
27
|
-
|
|
41
|
+
renderPage();
|
|
28
42
|
expect(screen.getByRole('heading', { name: 'Secrets' })).toBeInTheDocument();
|
|
29
43
|
expect(
|
|
30
44
|
await screen.findByText('No tools you can access declare secrets yet.'),
|
|
@@ -33,9 +47,26 @@ describe('SecretsPage', () => {
|
|
|
33
47
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
34
48
|
});
|
|
35
49
|
|
|
50
|
+
it('links each tool name at its own page', async () => {
|
|
51
|
+
const heyreach: ToolSecrets = {
|
|
52
|
+
slug: 'heyreach',
|
|
53
|
+
name: 'heyreach',
|
|
54
|
+
path: 'Groups/GTM/heyreach.tool',
|
|
55
|
+
type: 'inline',
|
|
56
|
+
setup: null,
|
|
57
|
+
canWrite: false,
|
|
58
|
+
variables: [],
|
|
59
|
+
};
|
|
60
|
+
toolSecretsMock.listToolSecrets.mockResolvedValue([heyreach]);
|
|
61
|
+
|
|
62
|
+
renderPage();
|
|
63
|
+
const link = await screen.findByRole('link', { name: 'Open heyreach' });
|
|
64
|
+
expect(link).toHaveAttribute('href', '/skills-and-tools/tools/heyreach');
|
|
65
|
+
});
|
|
66
|
+
|
|
36
67
|
it('surfaces the OAuth-callback success carried in the #authorized fragment and strips it', async () => {
|
|
37
68
|
window.history.replaceState(null, '', '/secrets#authorized');
|
|
38
|
-
|
|
69
|
+
renderPage();
|
|
39
70
|
expect(await screen.findByText('Authorization complete.')).toBeInTheDocument();
|
|
40
71
|
// The fragment is consumed so a refresh doesn't re-announce it.
|
|
41
72
|
expect(window.location.hash).toBe('');
|
|
@@ -44,7 +75,7 @@ describe('SecretsPage', () => {
|
|
|
44
75
|
|
|
45
76
|
it('surfaces the OAuth-callback error carried in the #error fragment and strips it', async () => {
|
|
46
77
|
window.history.replaceState(null, '', '/secrets#error=Access%20denied');
|
|
47
|
-
|
|
78
|
+
renderPage();
|
|
48
79
|
expect(await screen.findByText('Access denied')).toBeInTheDocument();
|
|
49
80
|
expect(window.location.hash).toBe('');
|
|
50
81
|
});
|
|
@@ -72,11 +72,32 @@ export async function getConnectPending(): Promise<ConnectPending> {
|
|
|
72
72
|
return (await res.json()) as ConnectPending;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Start a tool-scoped OAuth sign-in for one of a tool's OAuth-backed variables.
|
|
77
|
+
*
|
|
78
|
+
* `returnTo` is where the provider round-trip should deposit the browser — a
|
|
79
|
+
* same-origin PATH, signed into the OAuth state server-side and re-validated at
|
|
80
|
+
* the callback, so it cannot be turned into an open redirect. Pass the BARE
|
|
81
|
+
* path: the validator rejects `#`, and the callback appends `#authorized=…` /
|
|
82
|
+
* `#error=…` itself.
|
|
83
|
+
*
|
|
84
|
+
* The body is sent ONLY when a `returnTo` is given, which is what keeps the
|
|
85
|
+
* `/connect` call sites byte-identical to their pre-`returnTo` behavior (no
|
|
86
|
+
* body ⇒ the server's legacy `'connect'` destination).
|
|
87
|
+
*/
|
|
88
|
+
export async function startToolOAuth(
|
|
89
|
+
slug: string,
|
|
90
|
+
varName: string,
|
|
91
|
+
opts?: { returnTo?: string },
|
|
92
|
+
): Promise<string> {
|
|
93
|
+
const init: RequestInit = { method: 'POST' };
|
|
94
|
+
if (opts?.returnTo) {
|
|
95
|
+
init.headers = { 'Content-Type': 'application/json' };
|
|
96
|
+
init.body = JSON.stringify({ returnTo: opts.returnTo });
|
|
97
|
+
}
|
|
77
98
|
const res = await authFetch(
|
|
78
99
|
`/api/secrets/tools/${encodeURIComponent(slug)}/vars/${encodeURIComponent(varName)}/oauth/start`,
|
|
79
|
-
|
|
100
|
+
init,
|
|
80
101
|
);
|
|
81
102
|
if (!res.ok) await fail(res, "Couldn't start sign-in.");
|
|
82
103
|
return ((await res.json()) as { url: string }).url;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { PageShell } from '../../../shared/components/PageShell';
|
|
3
|
+
import { Banner, Button } from '../../../shared/components';
|
|
4
|
+
import { useAdmin } from '../../admin/state/admin.context';
|
|
5
|
+
import { fetchSetupStatus, type SetupStatus } from '../../setup/services/setup.api';
|
|
6
|
+
import { SetupScreen } from '../../setup/components/SetupScreen';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Deployment settings, routed at `/deployment` — the first-run setup screen
|
|
10
|
+
* given a permanent address.
|
|
11
|
+
*
|
|
12
|
+
* Setup used to be reachable exactly once: the gate showed it while the
|
|
13
|
+
* deployment was unconfigured and never again, so adding single sign-on (or
|
|
14
|
+
* rotating its client secret, or renaming a branch) later meant knowing which
|
|
15
|
+
* environment variable to set and restarting — the very thing the setup
|
|
16
|
+
* screen exists to spare people. The FORM was never the limitation — the
|
|
17
|
+
* backend accepts these writes from any admin at any time — only the door
|
|
18
|
+
* was. This page is that door.
|
|
19
|
+
*
|
|
20
|
+
* It reuses `SetupScreen` whole rather than extracting the SSO half: the
|
|
21
|
+
* knowledge-base connection and branch model are exactly as legitimate to
|
|
22
|
+
* revisit, and one form means the env-lock rule, the connection test and the
|
|
23
|
+
* restart notices cannot drift between first run and later.
|
|
24
|
+
*
|
|
25
|
+
* Admin-gated as presentation only — the backend enforces the same gate on
|
|
26
|
+
* every settings endpoint, and non-admin status responses carry no settings
|
|
27
|
+
* at all.
|
|
28
|
+
*/
|
|
29
|
+
export function DeploymentPage() {
|
|
30
|
+
const { isAdmin } = useAdmin();
|
|
31
|
+
const [status, setStatus] = useState<SetupStatus | null>(null);
|
|
32
|
+
const [failed, setFailed] = useState(false);
|
|
33
|
+
const [loaded, setLoaded] = useState(false);
|
|
34
|
+
|
|
35
|
+
const refresh = useCallback(() => {
|
|
36
|
+
// Non-admins never fetch: the endpoint would answer them safely (status
|
|
37
|
+
// without settings), but this page has already told them it is not
|
|
38
|
+
// theirs — a request whose answer nothing renders is noise.
|
|
39
|
+
if (!isAdmin) return;
|
|
40
|
+
fetchSetupStatus()
|
|
41
|
+
.then((s) => {
|
|
42
|
+
setStatus(s);
|
|
43
|
+
setFailed(false);
|
|
44
|
+
})
|
|
45
|
+
.catch(() => setFailed(true))
|
|
46
|
+
.finally(() => setLoaded(true));
|
|
47
|
+
}, [isAdmin]);
|
|
48
|
+
|
|
49
|
+
useEffect(refresh, [refresh]);
|
|
50
|
+
|
|
51
|
+
if (!isAdmin) {
|
|
52
|
+
return (
|
|
53
|
+
<PageShell title="Deployment" width="4xl">
|
|
54
|
+
<div className="text-sm text-ink-muted">
|
|
55
|
+
Admins only. Ask an admin if the sign-in method or the repository connection needs
|
|
56
|
+
changing.
|
|
57
|
+
</div>
|
|
58
|
+
</PageShell>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<PageShell title="Deployment" width="4xl">
|
|
64
|
+
{!loaded && <div className="mt-6 text-sm text-ink-muted">Loading…</div>}
|
|
65
|
+
|
|
66
|
+
{/* A failed fetch never clears `status`, so a refresh that breaks
|
|
67
|
+
AFTER a save leaves the form (and any restart notice inside it)
|
|
68
|
+
mounted below this banner — the failure costs a retry button, never
|
|
69
|
+
the confirmation of what was just saved. The copy tells the two
|
|
70
|
+
apart: nothing on screen yet is a load problem, a form still on
|
|
71
|
+
screen is a refresh problem. */}
|
|
72
|
+
{loaded && (failed || !status?.settings) && (
|
|
73
|
+
<Banner tone="danger" role="alert" className="mt-6">
|
|
74
|
+
{status?.settings
|
|
75
|
+
? "Couldn't refresh the deployment settings."
|
|
76
|
+
: "Couldn't load the deployment settings."}
|
|
77
|
+
<Button variant="outline" size="sm" className="ml-3" onClick={refresh}>
|
|
78
|
+
Try again
|
|
79
|
+
</Button>
|
|
80
|
+
</Banner>
|
|
81
|
+
)}
|
|
82
|
+
|
|
83
|
+
{loaded && status?.settings && (
|
|
84
|
+
<div className="mt-6">
|
|
85
|
+
<SetupScreen settings={status.settings} onSaved={refresh} variant="settings" />
|
|
86
|
+
</div>
|
|
87
|
+
)}
|
|
88
|
+
</PageShell>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { Outlet, useLocation } from 'react-router-dom';
|
|
3
|
+
import { AdminContext } from '../../admin/state/admin.context';
|
|
4
|
+
import type { AdminMenuItem } from '../../../core/registry';
|
|
5
|
+
import { SidebarFrame } from '../../layout/components/SidebarFrame';
|
|
6
|
+
import { useMediaQuery } from '../../layout/hooks/useMediaQuery';
|
|
7
|
+
import {
|
|
8
|
+
isSettingsNavPath,
|
|
9
|
+
normalizeSettingsPath,
|
|
10
|
+
useMenuSections,
|
|
11
|
+
} from '../settings-nav-items';
|
|
12
|
+
import { SettingsNav, type LinkableItem } from './SettingsNav';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The settings surfaces, wrapped in the nav that reaches them.
|
|
16
|
+
*
|
|
17
|
+
* The settings pages used to be reachable ONLY from the profile dropdown,
|
|
18
|
+
* which closes on the way out — so getting from Secrets to Account meant
|
|
19
|
+
* finding a 22px avatar in the far corner and re-summoning a list. The list
|
|
20
|
+
* looked like a nav and behaved like a menu. This makes it a nav: mounted by
|
|
21
|
+
* the route table, so it is a property of being a settings page rather than
|
|
22
|
+
* something each page has to remember to render.
|
|
23
|
+
*
|
|
24
|
+
* It fills the app's ONE `SidebarFrame` — the third renderer of it, after
|
|
25
|
+
* Knowledge's file tree and Skills & Tools' group list. `sidebar.ts` already
|
|
26
|
+
* states the claim this relies on: there is one nav, in one place, holding a
|
|
27
|
+
* different list depending on where you are.
|
|
28
|
+
*
|
|
29
|
+
* Three things here are load-bearing and easy to undo by accident:
|
|
30
|
+
*
|
|
31
|
+
* 1. NO `key={pathname}` anywhere. React Router keeps a layout element
|
|
32
|
+
* mounted across sibling child-route changes, and that is exactly what
|
|
33
|
+
* makes the nav persistent — the collapse state survives `/secrets` →
|
|
34
|
+
* `/account`, focus survives the click, and the child page mounts fresh
|
|
35
|
+
* without the layout blinking. A key here would remount all of it and
|
|
36
|
+
* reintroduce the bug in a subtler form.
|
|
37
|
+
*
|
|
38
|
+
* 2. `useContext(AdminContext)` directly, never `useAdmin()`. That hook
|
|
39
|
+
* throws outside `AdminProvider`, and the shell's route tests render
|
|
40
|
+
* `ShellRoutes` with no providers at all. Reading the context is honest
|
|
41
|
+
* rather than a dodge: this nav is WAYFINDING, not the security boundary
|
|
42
|
+
* — the backend gates every roles/accounts endpoint and each admin page
|
|
43
|
+
* renders its own "Admins only" notice — and no-context reading as "not
|
|
44
|
+
* an admin" is precisely `AdminProvider`'s own starting state.
|
|
45
|
+
*
|
|
46
|
+
* 3. `<main>` is NOT the scroller, which is the one deliberate departure
|
|
47
|
+
* from `LibraryLayout`. All six pages below already own a full-height
|
|
48
|
+
* scrolling container (`PageShell` is `h-full overflow-y-auto`), so
|
|
49
|
+
* scrolling here too would nest two scrollers and float the scrollbar
|
|
50
|
+
* off the page's own edge.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* A row can be shown only if it declares where it goes AND that destination is
|
|
54
|
+
* one of the routes this layout wraps.
|
|
55
|
+
*
|
|
56
|
+
* The first half excludes dialog rows — a dialog has no URL, so it can be
|
|
57
|
+
* neither linked to nor marked current. The second excludes a registry row
|
|
58
|
+
* pointing somewhere else in the app: a settings nav that could navigate you
|
|
59
|
+
* into Knowledge would be a nav that replaces itself mid-click. Neither kind
|
|
60
|
+
* is lost; both keep working in the dropdown, which is the surface that can
|
|
61
|
+
* run arbitrary actions.
|
|
62
|
+
*
|
|
63
|
+
* Module scope, not a closure inside the component: it captures nothing, and
|
|
64
|
+
* as a closure it was a dependency the memos below had to either list (and
|
|
65
|
+
* rebuild on every render) or lie about.
|
|
66
|
+
*
|
|
67
|
+
* The surviving rows come out NORMALIZED, so both halves of the current-row
|
|
68
|
+
* comparison are spelled the same way — the pathname is normalized on its way
|
|
69
|
+
* in, and a registry row that happened to declare `/secrets/` would otherwise
|
|
70
|
+
* render a link that never matches the page it is on.
|
|
71
|
+
*/
|
|
72
|
+
function linkable(items: AdminMenuItem[]): LinkableItem[] {
|
|
73
|
+
return items
|
|
74
|
+
.filter((item): item is LinkableItem => !!item.path && isSettingsNavPath(item.path))
|
|
75
|
+
.map((item) => ({ ...item, path: normalizeSettingsPath(item.path) }));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function SettingsLayout() {
|
|
79
|
+
// Normalized, because the row paths are — see `normalizeSettingsPath`. The
|
|
80
|
+
// page renders at `/secrets/` either way; without this its row is the only
|
|
81
|
+
// one in the nav that is never marked current.
|
|
82
|
+
const currentPath = normalizeSettingsPath(useLocation().pathname);
|
|
83
|
+
// Not `useAdmin()` — see (2) above.
|
|
84
|
+
const isAdmin = useContext(AdminContext)?.isAdmin ?? false;
|
|
85
|
+
const { defaultItems, adminItems } = useMenuSections();
|
|
86
|
+
/* Below `md` the sidebar frame is not mounted AT ALL and the rows become a
|
|
87
|
+
horizontal strip. A 212px rail on a 375px screen is most of the screen. */
|
|
88
|
+
const isCompact = useMediaQuery('(max-width: 767px)');
|
|
89
|
+
|
|
90
|
+
const navDefault = useMemo(() => linkable(defaultItems), [defaultItems]);
|
|
91
|
+
const navAdmin = useMemo(
|
|
92
|
+
() => (isAdmin ? linkable(adminItems) : []),
|
|
93
|
+
[adminItems, isAdmin],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (isCompact) {
|
|
97
|
+
return (
|
|
98
|
+
<div className="flex h-full min-h-0 flex-col bg-canvas text-ink">
|
|
99
|
+
{/* Horizontal-only scroll, the same idiom (and the same reasons) as
|
|
100
|
+
the toolbar's compact item cluster: `overflow-y-hidden` stops a
|
|
101
|
+
tall row growing a vertical scrollbar, and `pan-x` stops touch
|
|
102
|
+
browsers claiming a downward swipe that started on the strip. */}
|
|
103
|
+
<div
|
|
104
|
+
className="shrink-0 border-b border-line bg-sidebar px-3 py-2 overflow-x-auto overflow-y-hidden"
|
|
105
|
+
style={{ touchAction: 'pan-x' }}
|
|
106
|
+
>
|
|
107
|
+
<SettingsNav
|
|
108
|
+
defaultItems={navDefault}
|
|
109
|
+
adminItems={navAdmin}
|
|
110
|
+
currentPath={currentPath}
|
|
111
|
+
orientation="strip"
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
<main className="min-h-0 flex-1">
|
|
115
|
+
<Outlet />
|
|
116
|
+
</main>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div className="flex h-full min-h-0 bg-canvas text-ink">
|
|
123
|
+
<SidebarFrame label="Settings">
|
|
124
|
+
<SettingsNav
|
|
125
|
+
defaultItems={navDefault}
|
|
126
|
+
adminItems={navAdmin}
|
|
127
|
+
currentPath={currentPath}
|
|
128
|
+
/>
|
|
129
|
+
</SidebarFrame>
|
|
130
|
+
<main className="min-w-0 flex-1">
|
|
131
|
+
<Outlet />
|
|
132
|
+
</main>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
import type { AdminMenuItem } from '../../../core/registry';
|
|
4
|
+
import { cn } from '../../../lib/utils';
|
|
5
|
+
|
|
6
|
+
/** A row the nav can render: one that declares where it goes. */
|
|
7
|
+
export type LinkableItem = AdminMenuItem & { path: string };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `rail` is the sidebar column; `strip` is the horizontal row it becomes below
|
|
11
|
+
* the `md` breakpoint. The rows are identical in both — only the axis and the
|
|
12
|
+
* section label change, because a label that introduces a group beneath it is
|
|
13
|
+
* a vertical-list device and reads as noise inline.
|
|
14
|
+
*/
|
|
15
|
+
export type SettingsNavOrientation = 'rail' | 'strip';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The settings nav's CONTENTS — a pure view of the URL, in the same sense
|
|
19
|
+
* `GroupsSidebar` is. It holds no state, decides no membership and fetches
|
|
20
|
+
* nothing; the layout works out which rows exist and which one is current,
|
|
21
|
+
* and this renders them.
|
|
22
|
+
*
|
|
23
|
+
* Row styling is `GroupsSidebar`'s declaration token for token, minus the
|
|
24
|
+
* count slot it has no use for, plus `FileExplorer`'s inset focus ring — the
|
|
25
|
+
* more complete of the two treatments. The two sidebars must not read as two
|
|
26
|
+
* products, and the class string is what that rule actually protects.
|
|
27
|
+
*
|
|
28
|
+
* Two things here differ from both existing sidebars, deliberately, and
|
|
29
|
+
* neither is a style choice:
|
|
30
|
+
*
|
|
31
|
+
* - `<Link>`, not `<button onClick>`. Every row here HAS a URL (that is the
|
|
32
|
+
* membership rule), so cmd-click, middle-click and copy-link-address all
|
|
33
|
+
* work — which matters more for settings than for anything else in the app.
|
|
34
|
+
* The existing sidebars use buttons because their destinations are filter
|
|
35
|
+
* states and tree nodes reached by callback, not because buttons are the
|
|
36
|
+
* house style for navigation.
|
|
37
|
+
* - `aria-current="page"`, not `aria-current={boolean}` (which serialises to
|
|
38
|
+
* `"true"`). These rows go to pages, and `"page"` is the token for that.
|
|
39
|
+
*
|
|
40
|
+
* No icons, also deliberately: neither existing sidebar shows any, and
|
|
41
|
+
* `AdminMenuItem.icon` is optional — so an icon column would be ragged the
|
|
42
|
+
* moment the enterprise shell contributes a row without one. The icons stay in
|
|
43
|
+
* the dropdown, where a short vertical scan benefits from them.
|
|
44
|
+
*/
|
|
45
|
+
export function SettingsNav({
|
|
46
|
+
defaultItems,
|
|
47
|
+
adminItems,
|
|
48
|
+
currentPath,
|
|
49
|
+
orientation = 'rail',
|
|
50
|
+
}: {
|
|
51
|
+
defaultItems: LinkableItem[];
|
|
52
|
+
adminItems: LinkableItem[];
|
|
53
|
+
currentPath: string;
|
|
54
|
+
orientation?: SettingsNavOrientation;
|
|
55
|
+
}) {
|
|
56
|
+
const strip = orientation === 'strip';
|
|
57
|
+
|
|
58
|
+
const row = (item: LinkableItem) => {
|
|
59
|
+
const current = item.path === currentPath;
|
|
60
|
+
return (
|
|
61
|
+
<Link
|
|
62
|
+
key={item.id}
|
|
63
|
+
to={item.path}
|
|
64
|
+
aria-current={current ? 'page' : undefined}
|
|
65
|
+
className={cn(
|
|
66
|
+
'flex items-center gap-2 rounded-sm px-2.5 py-1.5 text-ui transition-colors',
|
|
67
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent',
|
|
68
|
+
// Inline, a row must not shrink to an ellipsis just because the next
|
|
69
|
+
// one wants room — the strip scrolls instead.
|
|
70
|
+
strip && 'shrink-0',
|
|
71
|
+
current
|
|
72
|
+
? 'bg-hover font-semibold text-ink'
|
|
73
|
+
: 'text-ink-muted hover:bg-hover hover:text-ink',
|
|
74
|
+
)}
|
|
75
|
+
>
|
|
76
|
+
<span className="truncate">{item.label}</span>
|
|
77
|
+
</Link>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<nav
|
|
83
|
+
aria-label="Settings"
|
|
84
|
+
className={cn(
|
|
85
|
+
'flex min-h-0',
|
|
86
|
+
strip ? 'flex-row items-center gap-1' : 'flex-col overflow-y-auto',
|
|
87
|
+
)}
|
|
88
|
+
>
|
|
89
|
+
{defaultItems.map(row)}
|
|
90
|
+
{adminItems.length > 0 && (
|
|
91
|
+
<>
|
|
92
|
+
{/* Inline, the rows simply continue — see the orientation docblock. */}
|
|
93
|
+
{!strip && <SectionLabel spaced>Admin only</SectionLabel>}
|
|
94
|
+
{adminItems.map(row)}
|
|
95
|
+
</>
|
|
96
|
+
)}
|
|
97
|
+
</nav>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Copied from `GroupsSidebar`'s `SectionLabel` rather than extracted into a
|
|
103
|
+
* shared component — the same call `FileExplorer` made about its own row
|
|
104
|
+
* class. Three sidebars agreeing on a label's padding is not yet an
|
|
105
|
+
* abstraction, and hoisting it would put a shared dependency between two
|
|
106
|
+
* modules that otherwise know nothing about each other.
|
|
107
|
+
*/
|
|
108
|
+
function SectionLabel({ children, spaced = false }: { children: ReactNode; spaced?: boolean }) {
|
|
109
|
+
return (
|
|
110
|
+
<div className={cn('px-2.5 pb-1.5 text-label uppercase text-ink-faint', spaced && 'pt-5')}>
|
|
111
|
+
{children}
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The deployment settings page — first-run setup with a permanent address.
|
|
7
|
+
* What is worth testing is the door itself: an admin gets the real form (with
|
|
8
|
+
* the same fields the setup gate shows), a non-admin gets told this is not
|
|
9
|
+
* theirs, and a failed status load offers a retry instead of a blank page.
|
|
10
|
+
* The form's own behaviour is covered by the setup suite — same component.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const apiMock = vi.hoisted(() => ({ fetchSetupStatus: vi.fn(), saveSettings: vi.fn() }));
|
|
14
|
+
vi.mock('../../../setup/services/setup.api', async (importOriginal) => ({
|
|
15
|
+
...(await importOriginal<object>()),
|
|
16
|
+
fetchSetupStatus: apiMock.fetchSetupStatus,
|
|
17
|
+
saveSettings: apiMock.saveSettings,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
import { DeploymentPage } from '../DeploymentPage';
|
|
21
|
+
|
|
22
|
+
function admin(isAdmin: boolean): AdminContextValue {
|
|
23
|
+
return { isAdmin } as AdminContextValue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A settled status: setup is COMPLETE — this page exists for exactly then. */
|
|
27
|
+
const COMPLETE_STATUS = {
|
|
28
|
+
complete: true,
|
|
29
|
+
awaitingRestart: false,
|
|
30
|
+
isAdmin: true,
|
|
31
|
+
settings: [
|
|
32
|
+
{ key: 'kbRepoUrl', section: 'knowledge-base', source: 'saved', value: 'https://git.example.com/kb.git' },
|
|
33
|
+
{ key: 'oidcIssuerUrl', section: 'sign-in', source: 'saved', value: '' },
|
|
34
|
+
{ key: 'oidcClientId', section: 'sign-in', source: 'saved', value: '' },
|
|
35
|
+
{ key: 'oidcClientSecret', section: 'sign-in', source: 'saved', value: '' },
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function renderPage(value: AdminContextValue) {
|
|
40
|
+
return render(
|
|
41
|
+
<AdminContext.Provider value={value}>
|
|
42
|
+
<DeploymentPage />
|
|
43
|
+
</AdminContext.Provider>,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('DeploymentPage', () => {
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
apiMock.fetchSetupStatus.mockReset();
|
|
50
|
+
apiMock.fetchSetupStatus.mockResolvedValue(COMPLETE_STATUS);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('shows the setup form to an admin — AFTER setup is complete', async () => {
|
|
54
|
+
renderPage(admin(true));
|
|
55
|
+
// The single-sign-on fields are reachable again: the whole point of the page.
|
|
56
|
+
expect(await screen.findByText('Provider address')).toBeInTheDocument();
|
|
57
|
+
// And the same redirect-URI helper the setup screen shows.
|
|
58
|
+
expect(screen.getByText(/api\/auth\/oidc\/callback/)).toBeInTheDocument();
|
|
59
|
+
// Post-setup only: the caution against repointing a LIVE deployment at a
|
|
60
|
+
// different repository (first-run has nothing to lose yet).
|
|
61
|
+
expect(
|
|
62
|
+
screen.getByText(/Only change this if the same repository was moved or renamed/),
|
|
63
|
+
).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('tells a non-admin this is not theirs, and never fetches the settings', () => {
|
|
67
|
+
renderPage(admin(false));
|
|
68
|
+
expect(screen.getByText(/Admins only/)).toBeInTheDocument();
|
|
69
|
+
expect(screen.queryByText('Provider address')).toBeNull();
|
|
70
|
+
// Never fetched, not merely never rendered: the page already told them
|
|
71
|
+
// this is not theirs, so a request nothing renders is pure noise.
|
|
72
|
+
expect(apiMock.fetchSetupStatus).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('a failed refresh after an awaiting-restart save keeps the form AND the notice', async () => {
|
|
76
|
+
// The save landed; only the follow-up status fetch died. The page must
|
|
77
|
+
// not trade the confirmation of what was saved for a load error — the
|
|
78
|
+
// form stays mounted with its restart notice, and the banner above it
|
|
79
|
+
// says "refresh", not "load", with a retry.
|
|
80
|
+
apiMock.saveSettings.mockResolvedValue({
|
|
81
|
+
restartRequired: true,
|
|
82
|
+
complete: false,
|
|
83
|
+
awaitingRestart: true,
|
|
84
|
+
settings: COMPLETE_STATUS.settings,
|
|
85
|
+
});
|
|
86
|
+
renderPage(admin(true));
|
|
87
|
+
await screen.findByText('Provider address');
|
|
88
|
+
apiMock.fetchSetupStatus.mockRejectedValueOnce(new Error('down'));
|
|
89
|
+
|
|
90
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
|
|
91
|
+
|
|
92
|
+
expect(await screen.findByText(/needs a restart/)).toBeInTheDocument();
|
|
93
|
+
expect(await screen.findByText(/Couldn't refresh the deployment settings/)).toBeInTheDocument();
|
|
94
|
+
// Still the form, not a blank page: the last good settings render on.
|
|
95
|
+
expect(screen.getByText('Provider address')).toBeInTheDocument();
|
|
96
|
+
expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('offers a retry when the status cannot be loaded, and the retry fetches again', async () => {
|
|
100
|
+
apiMock.fetchSetupStatus.mockRejectedValueOnce(new Error('down'));
|
|
101
|
+
renderPage(admin(true));
|
|
102
|
+
expect(await screen.findByText(/Couldn't load the deployment settings/)).toBeInTheDocument();
|
|
103
|
+
expect(apiMock.fetchSetupStatus).toHaveBeenCalledTimes(1);
|
|
104
|
+
|
|
105
|
+
fireEvent.click(screen.getByRole('button', { name: 'Try again' }));
|
|
106
|
+
await waitFor(() => expect(apiMock.fetchSetupStatus).toHaveBeenCalledTimes(2));
|
|
107
|
+
// The second answer (the beforeEach default) is the real settings.
|
|
108
|
+
expect(await screen.findByText('Provider address')).toBeInTheDocument();
|
|
109
|
+
});
|
|
110
|
+
});
|