Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(thread-comment-ui): use RegionService for comment timestamps (#7326)
白熱7876071f723d
diff --git a/packages/docs-ui/src/views/ParagraphMenu.tsx b/packages/docs-ui/src/views/ParagraphMenu.tsxindex bc02a7b17a..68c290f9bd 100644--- a/packages/docs-ui/src/views/ParagraphMenu.tsx+++ b/packages/docs-ui/src/views/ParagraphMenu.tsx@@ -14,11 +14,19 @@* limitations under the License.*/-import type { DocumentDataModel, IDocumentBlockRange, IDocumentBody, IParagraph, ITextRun, JSONXActions } from '@univerjs/core';+import type {+ DocumentDataModel,+ IDocumentBlockRange,+ IDocumentBody,+ IParagraph,+ ITextRun,+ JSONXActions,+} from '@univerjs/core';import type { IDocBlockMoveValidationContext } from '@univerjs/docs';import type { ITextRangeWithStyle } from '@univerjs/engine-render';import type { IPopup, IValueOption, RectPopupDirection } from '@univerjs/ui';import type { CSSProperties } from 'react';+import type { LocaleKey } from '../locale/types';import type { IMutiPageParagraphBound } from '../services/doc-event-manager.service';import type { IDocBlockMenuTarget } from '../services/doc-paragraph-menu.service';import {@@ -35,7 +43,12 @@ import {UniverInstanceType,} from '@univerjs/core';import { clsx } from '@univerjs/design';-import { DocBlockMoveValidatorService, DocContentInsertService, DocSelectionManagerService, RichTextEditingMutation } from '@univerjs/docs';+import {+ DocBlockMoveValidatorService,+ DocContentInsertService,+ DocSelectionManagerService,+ RichTextEditingMutation,+} from '@univerjs/docs';import { IRenderManagerService } from '@univerjs/engine-render';import {ContextMenuPanel,@@ -128,19 +141,6 @@ const PARAGRAPH_MENU_HOVER_BRIDGE_EDGE_OVERLAP = 12;const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;type ParagraphMenuOpenMode = 'pointer' | 'slash';-function getParagraphMenuTriggerClassName(visible: boolean) {- return clsx(`- univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-md- univer-border univer-border-gray-200 univer-bg-white univer-px-2 univer-py-0 univer-shadow-sm- univer-transition-colors- hover:univer-bg-gray-50 hover:univer-shadow-md- dark:!univer-border-gray-700 dark:!univer-bg-gray-900- dark:hover:!univer-bg-gray-800- `, {- 'univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800': visible,- });-}-export function shouldExecuteParagraphMenuMove(validatorService: Pick<DocBlockMoveValidatorService, 'canMoveBlock'>,context: IDocBlockMoveValidationContext@@ -1269,7 +1269,16 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; t<divdata-u-comp="paragraph-menu"ref={anchorRef}- className={getParagraphMenuTriggerClassName(visible)}+ className={clsx(`+ univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1+ univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-px-2 univer-py-0+ univer-shadow-sm univer-transition-colors+ hover:univer-bg-gray-50 hover:univer-shadow-md+ dark:!univer-border-gray-700 dark:!univer-bg-gray-900+ dark:hover:!univer-bg-gray-800+ `, {+ 'univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800': visible,+ })}onMouseEnter={(e) => {popup.onPointerEnter?.(e);setParagraphMenuInteractionActive(docParagraphMenuService, true);@@ -1298,8 +1307,8 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; tuniver-justify-center univer-border-none univer-bg-transparent univer-p-0active:univer-cursor-grabbing`}- aria-label={localeService.t('docs-ui.doc.blockMenu.dragBlock')}- title={localeService.t('docs-ui.doc.blockMenu.dragBlock')}+ aria-label={localeService.t<LocaleKey>('docs-ui.doc.blockMenu.dragBlock')}+ title={localeService.t<LocaleKey>('docs-ui.doc.blockMenu.dragBlock')}onPointerDown={(event) => {const latestTarget = docParagraphMenuService?.activeTarget ?? activeTarget;const moveRange = latestTarget?.moveRange;diff --git a/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx b/packages/thread-comment-ui/src/views/ThreadCommentTree.tsxindex b1f6452040..9f212c852b 100644--- a/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx+++ b/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx@@ -19,7 +19,7 @@ import type { IAddCommentCommandParams, IThreadComment, IUpdateCommentCommandParimport type { IUniverUIConfig } from '@univerjs/ui';import type { LocaleKey } from '../locale/types';import type { IThreadCommentEditorInstance } from './ThreadCommentEditor';-import { dateKit, generateRandomId, ICommandService, LOCALE_META, LocaleService, UserManagerService } from '@univerjs/core';+import { dateKit, generateRandomId, ICommandService, LOCALE_META, LocaleService, RegionService, UserManagerService } from '@univerjs/core';import { borderClassName, clsx, Dropdown, scrollbarClassName, Tooltip } from '@univerjs/design';import { DeleteIcon, MoreHorizontalIcon, ReplyToCommentIcon, SuccessIcon, SuccessOutlineIcon } from '@univerjs/icons';import {@@ -85,11 +85,11 @@ export interface IThreadCommentItemProps {const MOCK_ID = '__mock__';-function formatCommentDateTime(value: string, locale: LocaleType): string {+function formatCommentDateTime(value: string, region: LocaleType): string {const date = dateKit(value);- const localeTag = LOCALE_META[locale].tag;+ const regionTag = LOCALE_META[region].tag;- return date.formatIntl(localeTag, {+ return date.formatIntl(regionTag, {year: 'numeric',month: 'numeric',day: 'numeric',@@ -100,9 +100,23 @@ function formatCommentDateTime(value: string, locale: LocaleType): string {}const ThreadCommentItem = (props: IThreadCommentItemProps) => {- const { item, unitId, subUnitId, editing, onEditingChange, onReply, resolved, isRoot, onClose, onDeleteComment, type, threadCommentEditorId } = props;+ const {+ item,+ unitId,+ subUnitId,+ editing,+ onEditingChange,+ onReply,+ resolved,+ isRoot,+ onClose,+ onDeleteComment,+ type,+ threadCommentEditorId,+ } = props;const commandService = useDependency(ICommandService);const localeService = useDependency(LocaleService);+ const regionService = useDependency(RegionService);const userManagerService = useDependency(UserManagerService);const user = userManagerService.getUser(item.personId);const currentUser = useObservable(userManagerService.currentUser$);@@ -111,8 +125,8 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {const [showReply, setShowReply] = useState(false);const uiConfig = useConfigValue<IUniverUIConfig>(UI_PLUGIN_CONFIG_KEY);const avatarFallback = uiConfig?.avatarFallback;- const currentLocale = useObservable(localeService.currentLocale$, localeService.getCurrentLocale());- const dateText = formatCommentDateTime(item.dT, currentLocale);+ const currentRegion = useObservable(regionService.currentRegion$, regionService.getCurrentRegion());+ const dateText = isMock ? null : formatCommentDateTime(item.dT, currentRegion);const handleDeleteItem = () => {if (onDeleteComment?.(item) === false) {@@ -232,15 +246,17 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {</div>): null}- <time- dir="ltr"- className={`- univer-mb-1 univer-block univer-text-xs/normal univer-text-gray-600- dark:!univer-text-gray-200- `}- >- {dateText}- </time>+ {dateText && (+ <time+ dir="ltr"+ className={`+ univer-mb-1 univer-block univer-text-xs/normal univer-text-gray-600+ dark:!univer-text-gray-200+ `}+ >+ {dateText}+ </time>+ )}{editing? (<ThreadCommentEditordiff --git a/packages/thread-comment-ui/src/views/thread-comment-panel/__tests__/index.spec.tsx b/packages/thread-comment-ui/src/views/thread-comment-panel/__tests__/index.spec.tsxindex f1cab20b75..71f3da2c7f 100644--- a/packages/thread-comment-ui/src/views/thread-comment-panel/__tests__/index.spec.tsx+++ b/packages/thread-comment-ui/src/views/thread-comment-panel/__tests__/index.spec.tsx@@ -36,6 +36,7 @@ import {LocaleService,LocaleType,LogLevel,+ RegionService,toDisposable,UniverInstanceType,UserManagerService,@@ -350,6 +351,7 @@ function createPanelTestBed() {[IContextService, { useClass: ContextService }],[IConfigService, { useClass: ConfigService }],[LocaleService, { useClass: TestLocaleService as never }],+ [RegionService],[IEditorService, { useClass: TestEditorService as never }],[IRenderManagerService, { useClass: TestRenderManagerService as never }],[IShortcutService, { useClass: TestShortcutService as never }],diff --git a/packages/thread-comment-ui/src/views/thread-comment-tree/__tests__/index.spec.tsx b/packages/thread-comment-ui/src/views/thread-comment-tree/__tests__/index.spec.tsxindex c5771cdbdc..1cd5429bf3 100644--- a/packages/thread-comment-ui/src/views/thread-comment-tree/__tests__/index.spec.tsx+++ b/packages/thread-comment-ui/src/views/thread-comment-tree/__tests__/index.spec.tsx@@ -38,6 +38,7 @@ import {LocaleService,LocaleType,LogLevel,+ RegionService,toDisposable,UniverInstanceType,UserManagerService,@@ -367,6 +368,7 @@ function createTreeTestBed() {[IContextService, { useClass: ContextService }],[IConfigService, { useClass: ConfigService }],[LocaleService, { useClass: TestLocaleService as never }],+ [RegionService],[IEditorService, { useClass: TestEditorService as never }],[IRenderManagerService, { useClass: TestRenderManagerService as never }],[IShortcutService, { useClass: TestShortcutService as never }],@@ -422,7 +424,7 @@ function renderTree(injector: Injector, element: React.ReactElement) {return { container, root };}-function renderDefaultTree(injector: Injector, commentId: string) {+function renderDefaultTree(injector: Injector, commentId?: string) {return renderTree(injector,<ThreadCommentTree@@ -562,10 +564,11 @@ describe('ThreadCommentTree', () => {expect(time?.getAttribute('dir')).toBe('ltr');});- it('formats comment timestamps with dateKit intl using the current locale', () => {+ it('formats comment timestamps with dateKit intl using the current region', () => {const testBed = createTreeTestBed();const rawDate = '2026/07/07 20:35';- testBed.injector.get(LocaleService).setLocale(LocaleType.EN_US);+ testBed.injector.get(LocaleService).setLocale(LocaleType.ZH_CN);+ testBed.injector.get(RegionService).setRegion(LocaleType.EN_US);addRootComment(testBed.threadCommentModel, createComment({ id: 'root-thread', ref: 'A1', dT: rawDate }));const rendered = renderDefaultTree(testBed.injector, 'root-thread');@@ -586,6 +589,16 @@ describe('ThreadCommentTree', () => {expect(time?.textContent).not.toBe(rawDate);});+ it('does not render a timestamp for a new comment', () => {+ const testBed = createTreeTestBed();++ const rendered = renderDefaultTree(testBed.injector);+ root = rendered.root;+ container = rendered.container;++ expect(container.querySelector('time')).toBeNull();+ });+it('adds a reply through the tree editor and stores it under the root thread', async () => {const testBed = createTreeTestBed();addRootComment(testBed.threadCommentModel, createComment({ id: 'root-thread', ref: 'A1' }));diff --git a/packages/ui/src/commands/operations/open-feature-search.operation.ts b/packages/ui/src/commands/operations/open-feature-search.operation.tsindex 99904e2d47..4e6801c99c 100644--- a/packages/ui/src/commands/operations/open-feature-search.operation.ts+++ b/packages/ui/src/commands/operations/open-feature-search.operation.ts@@ -15,6 +15,7 @@*/import type { IOperation } from '@univerjs/core';+import type { LocaleKey } from '../../locale/types';import { CommandType, LocaleService } from '@univerjs/core';import { IDialogService } from '../../services/dialog/dialog.service';import {@@ -32,7 +33,7 @@ export const OpenFeatureSearchOperation: IOperation = {dialogService.open({id: FEATURE_SEARCH_DIALOG_ID,width: 560,- title: { title: localeService.t('ui.featureSearch.title') },+ title: { title: localeService.t<LocaleKey>('ui.featureSearch.title') },children: { label: FEATURE_SEARCH_COMPONENT },onClose: () => dialogService.close(FEATURE_SEARCH_DIALOG_ID),});diff --git a/packages/ui/src/views/components/feature-search/FeatureSearch.tsx b/packages/ui/src/views/components/feature-search/FeatureSearch.tsxindex ee5068958e..fca971b6e8 100644--- a/packages/ui/src/views/components/feature-search/FeatureSearch.tsx+++ b/packages/ui/src/views/components/feature-search/FeatureSearch.tsx@@ -14,7 +14,13 @@* limitations under the License.*/-import type { IMenuCommandParams, IMenuItem, IValueOption, MenuItemDefaultValueType } from '../../../services/menu/menu';+import type { LocaleKey } from '../../../locale/types';+import type {+ IMenuCommandParams,+ IMenuItem,+ IValueOption,+ MenuItemDefaultValueType,+} from '../../../services/menu/menu';import type { IMenuSchema } from '../../../services/menu/menu-manager.service';import { ICommandService, LocaleService, Tools } from '@univerjs/core';import {@@ -217,12 +223,12 @@ export function FeatureSearch() {const candidates = [...collectCandidates(ribbon,- [localeService.t('ui.featureSearch.ribbon')],+ [localeService.t<LocaleKey>('ui.featureSearch.ribbon')],[MenuManagerPosition.RIBBON]),...collectCandidates(menuManagerService.getMenuByPositionKey(MenuManagerPosition.CONTEXT_MENU),- [localeService.t('ui.featureSearch.contextMenu')],+ [localeService.t<LocaleKey>('ui.featureSearch.contextMenu')],[MenuManagerPosition.CONTEXT_MENU]),];@@ -251,10 +257,10 @@ export function FeatureSearch() {}return (- <Command label={localeService.t('ui.featureSearch.title')} loop>- <CommandInput autoFocus placeholder={localeService.t('ui.featureSearch.placeholder')} />+ <Command label={localeService.t<LocaleKey>('ui.featureSearch.title')} loop>+ <CommandInput autoFocus placeholder={localeService.t<LocaleKey>('ui.featureSearch.placeholder')} /><CommandList>- <CommandEmpty>{localeService.t('ui.featureSearch.empty')}</CommandEmpty>+ <CommandEmpty>{localeService.t<LocaleKey>('ui.featureSearch.empty')}</CommandEmpty><CommandGroup>{items.map((item) => (<CommandItem