From 063fafb81852a6e0da1392dea98a488b52efcf2f Mon Sep 17 00:00:00 2001 From: johnnyjoygh Date: Sat, 14 Nov 2026 15:00:04 +0800 Subject: [PATCH] chore(ui): standardize controls and component sizing --- AGENTS.md | 2 + web/package.json | 2 +- web/pnpm-lock.yaml | 10 +- .../components/AppSidebar/QuickFindDialog.tsx | 27 +- web/src/components/AppSidebar/TagsSection.tsx | 2 +- .../components/AppSidebar/ViewsSection.tsx | 2 +- .../components/CreateAccessTokenDialog.tsx | 39 ++- web/src/components/CreateUserDialog.tsx | 44 ++-- web/src/components/CreateWebhookDialog.tsx | 2 +- .../MemoActionMenu/MemoActionMenu.tsx | 4 +- web/src/components/MemoDisplaySettingMenu.tsx | 6 +- .../MemoEditor/edit/Toolbar/AudienceMenu.tsx | 2 +- .../MemoEditor/edit/Toolbar/EditorToolbar.tsx | 2 +- .../MemoEditor/edit/Toolbar/InsertMenu.tsx | 2 +- .../edit/components/TimestampPopover.tsx | 19 +- .../Attachment/AttachmentListEditor.tsx | 2 +- .../MemoReactionListView/ReactionSelector.tsx | 2 +- .../MemoView/components/MemoHeader.tsx | 10 +- .../Settings/LinkedIdentitySection.tsx | 73 ++---- web/src/components/Settings/MemberSection.tsx | 165 ++++++------ .../Settings/NotificationSection.tsx | 245 +++++++++--------- web/src/components/Settings/SSOSection.tsx | 100 +++---- web/src/components/Settings/SettingList.tsx | 18 +- web/src/components/Settings/SettingRow.tsx | 25 -- .../components/Settings/StorageSection.tsx | 158 +++++------ web/src/components/Settings/TagsSection.tsx | 6 +- .../components/Settings/WebhookSection.tsx | 50 ++-- web/src/locales/ar.json | 5 - web/src/locales/az.json | 5 - web/src/locales/bg.json | 5 - web/src/locales/ca.json | 5 - web/src/locales/cs.json | 5 - web/src/locales/da.json | 5 - web/src/locales/de.json | 5 - web/src/locales/el.json | 5 - web/src/locales/en-GB.json | 5 - web/src/locales/en.json | 5 - web/src/locales/es.json | 5 - web/src/locales/et.json | 5 - web/src/locales/fa.json | 5 - web/src/locales/fi.json | 5 - web/src/locales/fr.json | 5 - web/src/locales/gl.json | 5 - web/src/locales/he.json | 5 - web/src/locales/hi.json | 5 - web/src/locales/hr.json | 5 - web/src/locales/hu.json | 5 - web/src/locales/id.json | 5 - web/src/locales/it.json | 5 - web/src/locales/ja.json | 5 - web/src/locales/ka-GE.json | 5 - web/src/locales/ko.json | 5 - web/src/locales/lt.json | 5 - web/src/locales/lv.json | 5 - web/src/locales/mr.json | 5 - web/src/locales/nb.json | 5 - web/src/locales/nl.json | 5 - web/src/locales/nn.json | 7 +- web/src/locales/pl.json | 5 - web/src/locales/pt-BR.json | 5 - web/src/locales/pt-PT.json | 5 - web/src/locales/ro.json | 5 - web/src/locales/ru.json | 5 - web/src/locales/sk.json | 5 - web/src/locales/sl.json | 5 - web/src/locales/sr.json | 5 - web/src/locales/sv.json | 5 - web/src/locales/th.json | 5 - web/src/locales/tr.json | 5 - web/src/locales/uk.json | 5 - web/src/locales/vi.json | 5 - web/src/locales/zh-Hans.json | 5 - web/src/locales/zh-Hant.json | 5 - web/tests/app-sidebar-logo.test.tsx | 4 +- web/tests/create-access-token-dialog.test.tsx | 23 +- web/tests/create-user-dialog.test.tsx | 64 +++++ web/tests/memo-editor-timestamps.test.tsx | 16 +- web/tests/quick-find-navigation.test.tsx | 10 + web/tests/setting-list.test.tsx | 48 ++++ 79 files changed, 635 insertions(+), 781 deletions(-) delete mode 100644 web/src/components/Settings/SettingRow.tsx create mode 100644 web/tests/create-user-dialog.test.tsx create mode 100644 web/tests/setting-list.test.tsx diff --git a/AGENTS.md b/AGENTS.md index 2672dd9ef..5f6d5cdab 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -131,6 +131,8 @@ Black-box service tests live in `server/api/test/`, unit tests next to the code. components). Controls come from the package; build a part it lacks on Base UI as its `custom-components.md` describes. - Use a package component when one fits (`Button`, `Link`, `Spinner`, `Badge`). Its class functions (`buttonClasses()`, `menuClasses()`, `badgeClasses()`) are for elements it can't render, such as a router link or a Base UI trigger. +- Action menus use `md`, including custom rows styled with `menuClasses()`. Compact three-dot trigger buttons keep `sm`. +- Field text follows its component size on every device; do not add touch-specific font sizing. - Style with Tailwind CSS v4 and the package's `mu-` utilities (`bg-mu-surface`, `text-mu-text-secondary`, `rounded-mu-md`), text with its type classes (`mu-caption`, `mu-body`, `mu-label`, `mu-title`), and `cn()` for class merging. No Tailwind text sizes or old color names (`muted-foreground`, `destructive`, `popover`). The exceptions are the brand wordmark and diff --git a/web/package.json b/web/package.json index 2892b53de..9524e5285 100644 --- a/web/package.json +++ b/web/package.json @@ -28,7 +28,7 @@ "@tanstack/react-query-devtools": "^5.100.9", "@usememos/canvas": "26.11.2", "@usememos/editor": "26.11.3", - "@usememos/ui": "26.11.18", + "@usememos/ui": "26.11.20", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "copy-to-clipboard": "^4.0.2", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index b465ac88d..338f3ec1f 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -45,8 +45,8 @@ importers: specifier: 26.11.3 version: 26.11.3(react-dom@19.2.6(react@19.2.6))(react@19.2.6) '@usememos/ui': - specifier: 26.11.18 - version: 26.11.18(@base-ui/react@1.9.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6))(lucide-react@1.34.0(react@19.2.6))(react-dom@19.2.6(react@19.2.6))(react@19.2.6) + specifier: 26.11.20 + version: 26.11.20(@base-ui/react@1.9.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6))(lucide-react@1.34.0(react@19.2.6))(react-dom@19.2.6(react@19.2.6))(react@19.2.6) class-variance-authority: specifier: ^0.7.1 version: 0.7.1 @@ -973,8 +973,8 @@ packages: react-dom: optional: true - '@usememos/ui@26.11.18': - resolution: {integrity: sha512-+KaFiHeKSDhyDBxyhHysbfroAMOBq+fsOhbbq8EZIO0r68+pb2XKAxGnn+/6ZbXkb0zcvomf0gd01MGxX2U1+Q==} + '@usememos/ui@26.11.20': + resolution: {integrity: sha512-jm2Il+Xa1/o381n2JJo/X3nozPunKMXsfWudnYNkqWfKSrOMitJNPcvgL6S8+/3+DM8beKssLdRz17o7CdVNqw==} peerDependencies: '@base-ui/react': 1.9.0 lucide-react: '>=1.0.0' @@ -2392,7 +2392,7 @@ snapshots: react: 19.2.6 react-dom: 19.2.6(react@19.2.6) - '@usememos/ui@26.11.18(@base-ui/react@1.9.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6))(lucide-react@1.34.0(react@19.2.6))(react-dom@19.2.6(react@19.2.6))(react@19.2.6)': + '@usememos/ui@26.11.20(@base-ui/react@1.9.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6))(lucide-react@1.34.0(react@19.2.6))(react-dom@19.2.6(react@19.2.6))(react@19.2.6)': dependencies: '@base-ui/react': 1.9.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6) lucide-react: 1.34.0(react@19.2.6) diff --git a/web/src/components/AppSidebar/QuickFindDialog.tsx b/web/src/components/AppSidebar/QuickFindDialog.tsx index 0e4edcb93..57579e6e2 100644 --- a/web/src/components/AppSidebar/QuickFindDialog.tsx +++ b/web/src/components/AppSidebar/QuickFindDialog.tsx @@ -1,4 +1,4 @@ -import { Button, Dialog, Textarea, Toggle, ToggleGroup, Tooltip } from "@usememos/ui"; +import { Button, Dialog, Input, Textarea, Toggle, ToggleGroup, Tooltip } from "@usememos/ui"; import { CornerDownLeftIcon, SearchIcon } from "lucide-react"; import { type ChangeEvent, type FormEvent, type KeyboardEvent, useEffect, useId, useState } from "react"; import { useLocation, useNavigate } from "react-router-dom"; @@ -205,22 +205,23 @@ const QuickFindDialog = () => { ) : ( -
- - {/* The dialog's own field, focused whenever it is open: the caret marks focus, as in a - command palette, so it draws no outline around the borderless header. */} - + } placeholder={`${t("common.search")} ${compactScopeLabel}`} aria-label={`${t("common.search")} ${scopeLabel}`} + suffix={ + + } /> + } + /> + {t("common.search")} + + } /> - - } />} - /> - {t("common.search")} -
)} diff --git a/web/src/components/AppSidebar/TagsSection.tsx b/web/src/components/AppSidebar/TagsSection.tsx index be96e9c02..8566b29b2 100644 --- a/web/src/components/AppSidebar/TagsSection.tsx +++ b/web/src/components/AppSidebar/TagsSection.tsx @@ -96,7 +96,7 @@ const TagsSection = ({ tagCount, onSelect, scope }: Props) => { + { {memoView.title} - + { - setPartialState({ - expiration: Number(value), - }); - }; - const handleSaveBtnClick = async () => { if (!state.description) { fieldErrors.set("description", t("message.description-is-required")); @@ -139,20 +133,25 @@ function CreateAccessTokenDialog({ open, onOpenChange, onSuccess }: Props) { {fieldErrors.errors.description && {fieldErrors.errors.description}} - } + + {t("setting.access-token.create-dialog.expiration")} * + + expiration !== null && setPartialState({ expiration })} > - - {t("setting.access-token.create-dialog.expiration")} * - - {expirationOptions.map((option) => ( - - - {option.label} - - - ))} - + + + + + {expirationOptions.map((option) => ( + + {option.label} + + ))} + + )} diff --git a/web/src/components/CreateUserDialog.tsx b/web/src/components/CreateUserDialog.tsx index abf76112c..876e046fe 100644 --- a/web/src/components/CreateUserDialog.tsx +++ b/web/src/components/CreateUserDialog.tsx @@ -1,6 +1,6 @@ import { create } from "@bufbuild/protobuf"; import { FieldMaskSchema } from "@bufbuild/protobuf/wkt"; -import { Button, Dialog, Field, Fieldset, Input, Radio, RadioGroup } from "@usememos/ui"; +import { Button, Dialog, Field, Input, Select } from "@usememos/ui"; import { useEffect, useState } from "react"; import { userServiceClient } from "@/connect"; import { isFieldManaged, useManagedResource } from "@/hooks/useConfigurationQueries"; @@ -29,6 +29,10 @@ function CreateUserDialog({ open, onOpenChange, user: initialUser, onSuccess }: const isCreating = !initialUser; // The password is write-only, so configuration never locks it. const managed = useManagedResource(initialUser?.name ?? ""); + const roleOptions = [ + { value: User_Role.USER, label: t("setting.member.user") }, + { value: User_Role.ADMIN, label: t("setting.member.admin") }, + ]; useEffect(() => { if (initialUser) { @@ -127,28 +131,24 @@ function CreateUserDialog({ open, onOpenChange, user: initialUser, onSuccess }: {fieldErrors.errors.password && {fieldErrors.errors.password}} - setPartialUser({ role: Number(value) as User_Role })} - orientation="horizontal" - /> - } + {t("common.role")} + role !== null && setPartialUser({ role })} > - {t("common.role")} - - - {t("setting.member.user")} - - - - - {t("setting.member.admin")} - - - + + + + + {roleOptions.map((option) => ( + + {option.label} + + ))} + + diff --git a/web/src/components/CreateWebhookDialog.tsx b/web/src/components/CreateWebhookDialog.tsx index f2e424e15..235dec1f3 100644 --- a/web/src/components/CreateWebhookDialog.tsx +++ b/web/src/components/CreateWebhookDialog.tsx @@ -205,7 +205,7 @@ function CreateWebhookDialog({ open, onOpenChange, webhookName, onSuccess }: Pro + ) + ) : ( + - ) - ) : ( - - ), - }, - ]} - data={rows} - emptyMessage={t("setting.sso.no-sso-found")} - getRowKey={(row) => row.name} - /> + )} + + + ))} + + )} ); }; diff --git a/web/src/components/Settings/MemberSection.tsx b/web/src/components/Settings/MemberSection.tsx index c1b82551d..2eb03c503 100644 --- a/web/src/components/Settings/MemberSection.tsx +++ b/web/src/components/Settings/MemberSection.tsx @@ -1,6 +1,6 @@ import { create } from "@bufbuild/protobuf"; import { FieldMaskSchema } from "@bufbuild/protobuf/wkt"; -import { Badge, Button, Menu, Tooltip } from "@usememos/ui"; +import { Badge, Button, List, Menu, Tooltip } from "@usememos/ui"; import { sortBy } from "lodash-es"; import { MoreVerticalIcon, PlusIcon } from "lucide-react"; import { useMemo, useState } from "react"; @@ -19,8 +19,8 @@ import { User, User_Role } from "@/types/proto/api/user_service_pb"; import { useTranslate } from "@/utils/i18n"; import CreateUserDialog from "../CreateUserDialog"; import ManagedByConfigurationChip from "./ManagedByConfigurationChip"; +import { SettingList } from "./SettingList"; import SettingSection from "./SettingSection"; -import SettingTable from "./SettingTable"; import { useExportMemos } from "./useExportMemos"; const MemberSection = () => { @@ -117,95 +117,86 @@ const MemberSection = () => { } > - ( -
- -
-
- - {user.displayName || t("common.empty-placeholder")} - - {currentUser?.name === user.name ? ( - {t("common.yourself")} - ) : null} + {sortedUsers.length === 0 ? ( +

{t("setting.member.no-members-found")}

+ ) : ( + + {sortedUsers.map((user) => ( + +
+
+ +
+
+ + {user.displayName || t("common.empty-placeholder")} + + {currentUser?.name === user.name ? ( + {t("common.yourself")} + ) : null} +
+ @{user.username}
- @{user.username} +
+
+
+ {stringifyUserRole(user.role)} + + {user.state === State.ARCHIVED ? t("setting.member.archived") : t("setting.member.active")} + +
+ {user.email || findManagedResource(configurationStatus, user.name) ? ( +
+ {user.email ? : null} + +
+ ) : null}
- ), - }, - { - key: "summary", - header: t("setting.member.summary-column"), - render: (_, user: User) => ( -
-
- {stringifyUserRole(user.role)} - - {user.state === State.ARCHIVED ? t("setting.member.archived") : t("setting.member.active")} - + {currentUser?.name === user.name ? null : ( +
+ + + } /> + } + /> + } + /> + {t("common.more")} + + + handleEditUser(user)}>{t("common.update")} + exportMemos(user.username)}> + {t("setting.member.export-memos")} + + {user.state === State.NORMAL ? ( + handleArchiveUserClick(user)}>{t("setting.member.archive-member")} + ) : ( + <> + handleRestoreUserClick(user)}>{t("common.restore")} + {findManagedResource(configurationStatus, user.name) ? null : ( + handleDeleteUserClick(user)} danger> + {t("setting.member.delete-member")} + + )} + + )} + +
- {user.email || findManagedResource(configurationStatus, user.name) ? ( -
- {user.email ? : null} - -
- ) : null} -
- ), - }, - { - key: "actions", - header: "", - className: "w-px", - alignEnd: true, - render: (_, user: User) => - currentUser?.name === user.name ? null : ( - - - } /> - } - /> - } - /> - {t("common.more")} - - - handleEditUser(user)}>{t("common.update")} - exportMemos(user.username)}> - {t("setting.member.export-memos")} - - {user.state === State.NORMAL ? ( - handleArchiveUserClick(user)}>{t("setting.member.archive-member")} - ) : ( - <> - handleRestoreUserClick(user)}>{t("common.restore")} - {findManagedResource(configurationStatus, user.name) ? null : ( - handleDeleteUserClick(user)} danger> - {t("setting.member.delete-member")} - - )} - - )} - - - ), - }, - ]} - data={sortedUsers} - emptyMessage={t("setting.member.no-members-found")} - getRowKey={(user) => user.name} - /> + )} + + ))} + + )} {/* Create User Dialog */} diff --git a/web/src/components/Settings/NotificationSection.tsx b/web/src/components/Settings/NotificationSection.tsx index e6f8ff2e0..1cc807717 100644 --- a/web/src/components/Settings/NotificationSection.tsx +++ b/web/src/components/Settings/NotificationSection.tsx @@ -21,7 +21,7 @@ import { import { useTranslate } from "@/utils/i18n"; import ManagedByConfigurationChip from "./ManagedByConfigurationChip"; import SettingGroup from "./SettingGroup"; -import SettingRow from "./SettingRow"; +import { SettingList, SettingListItem } from "./SettingList"; import SettingSection from "./SettingSection"; import useInstanceSettingUpdater, { buildInstanceSettingName } from "./useInstanceSettingUpdater"; @@ -187,134 +187,139 @@ const NotificationSection = () => { description={t("setting.notification.email-description")} actions={EMAIL_FIELDS.some(emailLocked) ? : undefined} > - - updateEmailSetting({ enabled })} - /> - + + + updateEmailSetting({ enabled })} + /> + - - updateEmailSetting({ smtpHost: e.target.value })} - /> - + + updateEmailSetting({ smtpHost: e.target.value })} + /> + - - - + + + - - updateEmailSetting({ smtpUsername: e.target.value })} - /> - + + updateEmailSetting({ smtpUsername: e.target.value })} + /> + - - updateEmailSetting({ smtpPassword: e.target.value })} - /> - + + updateEmailSetting({ smtpPassword: e.target.value })} + /> + - - updateEmailSetting({ fromEmail: e.target.value })} - /> - + + updateEmailSetting({ fromEmail: e.target.value })} + /> + - - updateEmailSetting({ fromName: e.target.value })} - /> - + + updateEmailSetting({ fromName: e.target.value })} + /> + - - updateEmailSetting({ replyTo: e.target.value })} - /> - + + updateEmailSetting({ replyTo: e.target.value })} + /> + - - - + + + - - - + + + +
diff --git a/web/src/components/Settings/SSOSection.tsx b/web/src/components/Settings/SSOSection.tsx index 55ff978ca..50962382d 100644 --- a/web/src/components/Settings/SSOSection.tsx +++ b/web/src/components/Settings/SSOSection.tsx @@ -1,4 +1,4 @@ -import { Badge, Button, Menu, Tooltip } from "@usememos/ui"; +import { Badge, Button, List, Menu, Tooltip } from "@usememos/ui"; import { MoreVerticalIcon, PlusIcon } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import ConfirmDialog from "@/components/ConfirmDialog"; @@ -19,10 +19,10 @@ import { useTranslate } from "@/utils/i18n"; import CreateIdentityProviderDialog from "../CreateIdentityProviderDialog"; import LearnMore from "../LearnMore"; import ManagedByConfigurationChip from "./ManagedByConfigurationChip"; +import { SettingList } from "./SettingList"; import SettingSection from "./SettingSection"; -import SettingTable from "./SettingTable"; -interface IdentityProviderRow extends Record { +interface IdentityProviderRow { name: string; providerUid: string; title: string; @@ -121,30 +121,21 @@ const SSOSection = () => { } > - ( -
+ {rows.length === 0 ? ( +

{t("setting.sso.no-sso-found")}

+ ) : ( + + {rows.map((row) => ( + +
- {row.title} + {row.title} {row.typeLabel}
-
- ), - }, - { - key: "summaryItems", - header: t("setting.sso.configuration"), - render: (_, row: IdentityProviderRow) => ( -

{t("setting.sso.configuration-summary-description")}

{row.summaryItems.map((item) => ( @@ -152,46 +143,37 @@ const SSOSection = () => { ))}
- ), - }, - { - key: "actions", - header: "", - className: "w-px", - alignEnd: true, - render: (_, row: IdentityProviderRow) => ( - - - } />} - /> - } - /> - {t("common.more")} - - - handleEditIdentityProvider(row.provider)} - > - {t("common.edit")} - - {findManagedResource(configurationStatus, row.name) ? null : ( - handleDeleteIdentityProvider(row.provider)} danger> - {t("common.delete")} +
+ + + } />} + /> + } + /> + {t("common.more")} + + + handleEditIdentityProvider(row.provider)} + > + {t("common.edit")} - )} - - - ), - }, - ]} - data={rows} - emptyMessage={t("setting.sso.no-sso-found")} - getRowKey={(row) => row.name} - /> + {findManagedResource(configurationStatus, row.name) ? null : ( + handleDeleteIdentityProvider(row.provider)} danger> + {t("common.delete")} + + )} + + +
+
+ ))} +
+ )} (undefined); @@ -25,15 +26,24 @@ export const SettingList = ({ children, ...props }: SettingListProps) => { interface SettingListItemProps { label: ReactNode; description?: ReactNode; + orientation?: "horizontal" | "vertical"; /** The row's one control, placed at the end of the row. */ children?: ReactNode; } -/** A settings row: a horizontal Field, so the label and description name the one control at the end. */ -export const SettingListItem = ({ label, description, children }: SettingListItemProps) => { +/** A labeled settings control; wide controls stack when the row has little room. */ +export const SettingListItem = ({ label, description, children, orientation = "horizontal" }: SettingListItemProps) => { return ( - - + + {label} {description && {description}} {children} diff --git a/web/src/components/Settings/SettingRow.tsx b/web/src/components/Settings/SettingRow.tsx deleted file mode 100644 index a193166c9..000000000 --- a/web/src/components/Settings/SettingRow.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { Field } from "@usememos/ui"; -import type React from "react"; -import { cn } from "@/lib/utils"; - -interface SettingRowProps { - label: React.ReactNode; - description?: string; - children: React.ReactNode; - vertical?: boolean; -} - -/** One setting: its label and description name the single control beside them. */ -const SettingRow: React.FC = ({ label, description, children, vertical = false }) => { - return ( - -
- {label} - {description && {description}} -
-
{children}
-
- ); -}; - -export default SettingRow; diff --git a/web/src/components/Settings/StorageSection.tsx b/web/src/components/Settings/StorageSection.tsx index a4ee4b258..a310d4f5b 100644 --- a/web/src/components/Settings/StorageSection.tsx +++ b/web/src/components/Settings/StorageSection.tsx @@ -21,7 +21,7 @@ import { import { useTranslate } from "@/utils/i18n"; import ManagedByConfigurationChip from "./ManagedByConfigurationChip"; import SettingGroup from "./SettingGroup"; -import SettingRow from "./SettingRow"; +import { SettingList, SettingListItem } from "./SettingList"; import SettingSection from "./SettingSection"; import useInstanceSettingUpdater, { buildInstanceSettingName } from "./useInstanceSettingUpdater"; @@ -330,19 +330,21 @@ const StorageSection = () => {
{selectedStorageType !== InstanceSetting_StorageType.DATABASE && ( - - - + + + + + )} @@ -352,75 +354,77 @@ const StorageSection = () => { description={t("setting.storage.s3-configuration-description")} showSeparator > - - handleS3FieldChange("accessKeyId", e.target.value)} - /> - + + + handleS3FieldChange("accessKeyId", e.target.value)} + /> + - - handleS3FieldChange("accessKeySecret", e.target.value)} - /> - + + handleS3FieldChange("accessKeySecret", e.target.value)} + /> + - - handleS3FieldChange("endpoint", e.target.value)} - /> - + + handleS3FieldChange("endpoint", e.target.value)} + /> + - - handleS3FieldChange("region", e.target.value)} - /> - + + handleS3FieldChange("region", e.target.value)} + /> + - - handleS3FieldChange("bucket", e.target.value)} - /> - + + handleS3FieldChange("bucket", e.target.value)} + /> + - - handleS3FieldChange("usePathStyle", checked)} - /> - + + handleS3FieldChange("usePathStyle", checked)} + /> + - - handleS3FieldChange("insecureSkipTlsVerify", checked)} - /> - + + handleS3FieldChange("insecureSkipTlsVerify", checked)} + /> + + )} diff --git a/web/src/components/Settings/TagsSection.tsx b/web/src/components/Settings/TagsSection.tsx index 509f2651e..a33bd69a3 100644 --- a/web/src/components/Settings/TagsSection.tsx +++ b/web/src/components/Settings/TagsSection.tsx @@ -192,7 +192,7 @@ const TagsSection = () => { {newTagError && {newTagError}} -
+
{t("setting.tags.background-color")} { onChange={(e) => setNewTagColor(e.target.value)} aria-label={t("setting.tags.background-color")} /> -
@@ -259,7 +259,7 @@ const TagsSection = () => { onChange={(e) => handleColorChange(row.name, e.target.value)} aria-label={t("setting.tags.background-color")} /> -
diff --git a/web/src/components/Settings/WebhookSection.tsx b/web/src/components/Settings/WebhookSection.tsx index 9cca889cf..ef6e0d64c 100644 --- a/web/src/components/Settings/WebhookSection.tsx +++ b/web/src/components/Settings/WebhookSection.tsx @@ -1,4 +1,4 @@ -import { Button, Table, Tooltip } from "@usememos/ui"; +import { Button, List, Tooltip } from "@usememos/ui"; import { PencilIcon, PlusIcon, TrashIcon } from "lucide-react"; import { useEffect, useState } from "react"; import ConfirmDialog from "@/components/ConfirmDialog"; @@ -9,8 +9,8 @@ import { UserWebhook } from "@/types/proto/api/user_service_pb"; import { useTranslate } from "@/utils/i18n"; import CreateWebhookDialog from "../CreateWebhookDialog"; import LearnMore from "../LearnMore"; +import { SettingList } from "./SettingList"; import SettingSection from "./SettingSection"; -import SettingTable from "./SettingTable"; const WebhookSection = () => { const t = useTranslate(); @@ -77,28 +77,17 @@ const WebhookSection = () => { } > - {webhook.displayName}, - }, - { - key: "url", - header: t("setting.webhook.url"), - render: (_, webhook: UserWebhook) => ( - - {webhook.url} - - ), - }, - { - key: "actions", - header: "", - alignEnd: true, - render: (_, webhook: UserWebhook) => ( - + {webhooks.length === 0 ? ( +

{t("setting.webhook.no-webhooks-found")}

+ ) : ( + + {webhooks.map((webhook) => ( + +
+

{webhook.displayName}

+

{webhook.url}

+
+
{ /> {t("common.delete")} - - ), - }, - ]} - data={webhooks} - emptyMessage={t("setting.webhook.no-webhooks-found")} - getRowKey={(webhook) => webhook.name} - /> +
+
+ ))} +
+ )} { expect(sidebarState.setMobileOpen).toHaveBeenCalledWith(false); }); - it("uses compact text-only actions for a saved view", async () => { + it("uses md text-only actions for a saved view", async () => { authState.memoViews = [{ name: "memoViews/1", title: "testgp" }]; render( @@ -612,7 +612,7 @@ describe("App sidebar logo", () => { fireEvent.click(screen.getByRole("button", { name: "common.edit testgp" })); const menu = await screen.findByRole("menu"); - expect(menu.closest(".mu-s-sm") ?? menu.querySelector(".mu-s-sm")).not.toBeNull(); + expect(menu.closest(".mu-s-md") ?? menu.querySelector(".mu-s-md")).not.toBeNull(); const editItem = screen.getByRole("menuitem", { name: "common.edit" }); const deleteItem = screen.getByRole("menuitem", { name: "common.delete" }); expect(editItem.querySelector("svg")).toBeNull(); diff --git a/web/tests/create-access-token-dialog.test.tsx b/web/tests/create-access-token-dialog.test.tsx index 7db1b0252..8abf02f31 100644 --- a/web/tests/create-access-token-dialog.test.tsx +++ b/web/tests/create-access-token-dialog.test.tsx @@ -34,7 +34,9 @@ describe("CreateAccessTokenDialog", () => { it("creates a non-expiring token by default", async () => { render(); - expect(screen.getByRole("radio", { name: "setting.access-token.create-dialog.duration-never" })).toBeChecked(); + expect(screen.getByRole("combobox", { name: /setting.access-token.create-dialog.expiration/ })).toHaveTextContent( + "setting.access-token.create-dialog.duration-never", + ); fireEvent.change(screen.getByRole("textbox"), { target: { value: "CLI token" } }); fireEvent.click(screen.getByRole("button", { name: "common.create" })); @@ -46,4 +48,23 @@ describe("CreateAccessTokenDialog", () => { }), ); }); + + it("creates a token with the selected expiration", async () => { + render(); + + fireEvent.click(screen.getByRole("combobox", { name: /setting.access-token.create-dialog.expiration/ })); + const option = await screen.findByRole("option", { name: "setting.access-token.create-dialog.duration-90d" }); + fireEvent.pointerDown(option, { pointerType: "mouse" }); + fireEvent.click(option); + fireEvent.change(screen.getByRole("textbox"), { target: { value: "CLI token" } }); + fireEvent.click(screen.getByRole("button", { name: "common.create" })); + + await waitFor(() => + expect(createPersonalAccessToken).toHaveBeenCalledWith({ + parent: "users/alice", + description: "CLI token", + expiresInDays: 90, + }), + ); + }); }); diff --git a/web/tests/create-user-dialog.test.tsx b/web/tests/create-user-dialog.test.tsx new file mode 100644 index 000000000..04f778e06 --- /dev/null +++ b/web/tests/create-user-dialog.test.tsx @@ -0,0 +1,64 @@ +import { create } from "@bufbuild/protobuf"; +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import CreateUserDialog from "@/components/CreateUserDialog"; +import { User_Role, UserSchema } from "@/types/proto/api/user_service_pb"; + +const state = vi.hoisted(() => ({ + updateUser: vi.fn(), + managed: false, +})); + +vi.mock("@/connect", () => ({ + userServiceClient: { updateUser: state.updateUser }, +})); + +vi.mock("@/hooks/useConfigurationQueries", () => ({ + useManagedResource: () => undefined, + isFieldManaged: (_resource: unknown, field: string) => state.managed && field === "role", +})); + +vi.mock("@/utils/i18n", () => ({ + useTranslate: () => (key: string) => key, +})); + +describe("CreateUserDialog", () => { + beforeAll(() => { + Element.prototype.scrollIntoView = vi.fn(); + Element.prototype.hasPointerCapture = vi.fn(() => false); + Element.prototype.setPointerCapture = vi.fn(); + Element.prototype.releasePointerCapture = vi.fn(); + }); + + beforeEach(() => { + state.managed = false; + state.updateUser.mockReset().mockResolvedValue(undefined); + }); + + const user = create(UserSchema, { name: "users/alice", username: "alice", role: User_Role.USER }); + + it("updates only the role after selecting an admin", async () => { + render(); + + fireEvent.click(screen.getByRole("combobox", { name: "common.role" })); + const option = await screen.findByRole("option", { name: "setting.member.admin" }); + fireEvent.pointerDown(option, { pointerType: "mouse" }); + fireEvent.click(option); + fireEvent.click(screen.getByRole("button", { name: "common.confirm" })); + + await waitFor(() => + expect(state.updateUser).toHaveBeenCalledWith({ + user: expect.objectContaining({ name: "users/alice", role: User_Role.ADMIN }), + updateMask: expect.objectContaining({ paths: ["role"] }), + }), + ); + }); + + it("keeps a role managed by configuration disabled", () => { + state.managed = true; + render(); + + expect(screen.getByRole("combobox", { name: "common.role" })).toBeDisabled(); + expect(screen.getByRole("combobox", { name: "common.role" })).toHaveTextContent("setting.member.user"); + }); +}); diff --git a/web/tests/memo-editor-timestamps.test.tsx b/web/tests/memo-editor-timestamps.test.tsx index 35dec468c..0f7c6dc80 100644 --- a/web/tests/memo-editor-timestamps.test.tsx +++ b/web/tests/memo-editor-timestamps.test.tsx @@ -50,6 +50,20 @@ describe("memo editor timestamps", () => { clients.updateMemo.mockImplementation(async ({ memo }: { memo: Memo }) => memo); }); + it("associates the input label and clears its invalid state after a valid edit", () => { + renderEditor(); + const input = screen.getByRole("textbox", { name: "common.created-at" }); + expect(screen.getByText("common.created-at")).toHaveAttribute("for", input.id); + + fireEvent.change(input, { target: { value: "invalid" } }); + fireEvent.blur(input); + expect(input).toHaveAttribute("aria-invalid", "true"); + + fireEvent.change(input, { target: { value: "2024-02-29 12:34:56" } }); + expect(input).toHaveAttribute("aria-invalid", "false"); + expect(editor.getState().timestamps.createTime).toEqual(customTime); + }); + it.each([ [0, "createTime", "create_time"], [1, "updateTime", "update_time"], @@ -79,7 +93,7 @@ describe("memo editor timestamps", () => { const input = screen.getAllByRole("textbox")[0]; fireEvent.change(input, { target: { value } }); fireEvent.blur(input); - expect(input).toHaveAttribute("data-invalid", "true"); + expect(input).toHaveAttribute("aria-invalid", "true"); expect(editor.getState().timestamps.createTime).toEqual(originalCreate); await memoService.save(editor.getState(), { memoName: memo.name }, ops); expect(clients.updateMemo).not.toHaveBeenCalled(); diff --git a/web/tests/quick-find-navigation.test.tsx b/web/tests/quick-find-navigation.test.tsx index 8d714817f..5362f90bb 100644 --- a/web/tests/quick-find-navigation.test.tsx +++ b/web/tests/quick-find-navigation.test.tsx @@ -100,6 +100,16 @@ describe("Quick Find navigation", () => { }; const openQuickFind = () => fireEvent.click(screen.getByRole("button", { name: "Open Quick Find" })); + it("submits a text query from the input's search action", async () => { + renderSearch(); + openQuickFind(); + fireEvent.change(await screen.findByRole("textbox"), { target: { value: "roadmap" } }); + fireEvent.click(screen.getByRole("button", { name: "common.search" })); + + expect(state.setFilters).toHaveBeenCalledWith([{ factor: "contentSearch", value: "roadmap" }]); + await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); + }); + it("preserves the draft when changing modes and submits CEL with Enter", async () => { renderSearch(); openQuickFind(); diff --git a/web/tests/setting-list.test.tsx b/web/tests/setting-list.test.tsx new file mode 100644 index 000000000..a228cdf6f --- /dev/null +++ b/web/tests/setting-list.test.tsx @@ -0,0 +1,48 @@ +import { fireEvent, render, screen, within } from "@testing-library/react"; +import { Input, Switch } from "@usememos/ui"; +import { useState } from "react"; +import { describe, expect, it, vi } from "vitest"; +import SettingGroup from "@/components/Settings/SettingGroup"; +import { SettingList, SettingListItem } from "@/components/Settings/SettingList"; + +describe("setting rows", () => { + it("associates a list, input and description with their visible labels", () => { + render( + + + + + + + + + + , + ); + + const list = screen.getByRole("list", { name: "Storage" }); + expect(within(list).getAllByRole("listitem")).toHaveLength(2); + expect(within(list).getByRole("textbox", { name: "Bucket" })).toHaveAccessibleDescription("The bucket used for uploads."); + expect(within(list).getByRole("textbox", { name: "File path" })).toHaveAccessibleDescription("The path for new uploads."); + }); + + it("toggles a setting through its label", () => { + const changed = vi.fn(); + const Harness = () => { + const [checked, setChecked] = useState(false); + return ( + + + (setChecked(value), changed(value))} /> + + + ); + }; + render(); + + fireEvent.click(screen.getByText("Link previews")); + + expect(screen.getByRole("switch", { name: "Link previews" })).toBeChecked(); + expect(changed).toHaveBeenCalledWith(true); + }); +});