fix: tooltip for date

This commit is contained in:
Stephen Zhou
2025-10-22 17:07:57 +08:00
parent 25dc8fce93
commit bddab57de7
10 changed files with 23 additions and 41 deletions
@@ -13,7 +13,6 @@ import { $applyNodeReplacement, DecoratorNode } from "lexical"
import * as React from "react"
import { MentionComponent } from "./components/MentionComponent"
import { RANGE_WITH_LABEL_KEY } from "./hooks/dateMentionConfig"
import { getDateMentionDisplayName } from "./hooks/dateMentionUtils"
import type { MentionData } from "./types"
@@ -166,5 +165,5 @@ const resolveMentionDisplayName = (mentionData: MentionData): string => {
const language = i18next.language || i18next.resolvedLanguage || i18next.options?.lng || "en"
const translate = i18next.getFixedT(language, "ai")
return getDateMentionDisplayName(mentionData, translate, language, RANGE_WITH_LABEL_KEY)
return getDateMentionDisplayName(mentionData, translate, language)
}
@@ -15,7 +15,6 @@ import * as React from "react"
import { useTranslation } from "react-i18next"
import { MentionLikePill } from "../../shared/components/MentionLikePill"
import { RANGE_WITH_LABEL_KEY } from "../hooks/dateMentionConfig"
import {
createDateMentionData,
getDateMentionDisplayName,
@@ -34,7 +33,9 @@ interface MentionComponentProps {
}
const MentionTooltipContent = ({ mentionData }: { mentionData: MentionData }) => {
const displayValue = getMentionDisplayTextValue(mentionData)
const { t, i18n } = useTranslation("ai")
const language = i18n.language || i18n.resolvedLanguage || "en"
const displayValue = getMentionDisplayTextValue(mentionData, t, language)
const getIconBgColor = () => {
if (mentionData.type === "view" && typeof mentionData.value === "number") {
@@ -126,7 +127,7 @@ export const MentionComponent: React.FC<MentionComponentProps> = ({
const displayName = React.useMemo(() => {
if (mentionData.type === "date") {
return getDateMentionDisplayName(mentionData, t, language, RANGE_WITH_LABEL_KEY)
return getDateMentionDisplayName(mentionData, t, language)
}
return `@${mentionData.name}`
}, [mentionData, t, language])
@@ -142,8 +143,6 @@ export const MentionComponent: React.FC<MentionComponentProps> = ({
const newMentionData = createDateMentionData({
range,
translate: t,
locale: language,
withRangeKey: RANGE_WITH_LABEL_KEY,
})
editor.update(() => {
@@ -153,7 +152,7 @@ export const MentionComponent: React.FC<MentionComponentProps> = ({
}
})
},
[nodeKey, editor, t, language],
[nodeKey, editor, t],
)
const currentDateRange = React.useMemo(() => {
@@ -6,7 +6,6 @@ import { useTranslation } from "react-i18next"
import type { TypeaheadGroup } from "../../shared/components/TypeaheadDropdown"
import { TypeaheadDropdown } from "../../shared/components/TypeaheadDropdown"
import { MENTION_TRIGGER_PATTERN } from "../constants"
import { RANGE_WITH_LABEL_KEY } from "../hooks/dateMentionConfig"
import { getDateMentionDisplayName } from "../hooks/dateMentionUtils"
import type { MentionData } from "../types"
import { MentionTypeIcon } from "./shared/MentionTypeIcon"
@@ -43,7 +42,7 @@ const MentionSuggestionItem = React.memo(
const displayName = React.useMemo(() => {
if (mention.type === "date") {
return getDateMentionDisplayName(mention, t, language, RANGE_WITH_LABEL_KEY)
return getDateMentionDisplayName(mention, t, language)
}
return mention.name
}, [mention, t, language])
@@ -188,5 +188,3 @@ export interface WeekdayTranslationDescriptor {
labelKey: string
searchKey: string
}
export const RANGE_WITH_LABEL_KEY = "mentions.date.display.with_range"
@@ -6,7 +6,7 @@ import type { TFunction } from "i18next"
import type { MentionData, MentionLabelDescriptor } from "../types"
import type { RelativeDateDefinition } from "./dateMentionConfig"
import { RANGE_WITH_LABEL_KEY, RELATIVE_DATE_DEFINITIONS } from "./dateMentionConfig"
import { RELATIVE_DATE_DEFINITIONS } from "./dateMentionConfig"
import type { DateRange } from "./dateMentionUtils"
import {
createDateMentionData,
@@ -118,8 +118,6 @@ const buildRangeMention = (
label: candidate.label,
labelOptions: appendRange ? { appendRange: true } : undefined,
translate: context.t,
locale: context.language,
withRangeKey: RANGE_WITH_LABEL_KEY,
})
}
@@ -215,8 +213,6 @@ export const createDateMentionBuilder = (context: DateMentionBuilderContext) =>
const chronoMention = createDateMentionData({
range: naturalDateRange,
translate: context.t,
locale: context.language,
withRangeKey: RANGE_WITH_LABEL_KEY,
displayName: formatLocalizedRange(naturalDateRange, context.language),
})
mentions.push(chronoMention)
@@ -116,8 +116,6 @@ export const createDateMentionData = ({
label,
labelOptions,
translate,
locale,
withRangeKey,
displayName,
}: {
id?: string
@@ -125,8 +123,6 @@ export const createDateMentionData = ({
label?: MentionLabelDescriptor
labelOptions?: DateMentionData["labelOptions"]
translate: LabelTranslator
locale: string
withRangeKey: I18nKeysForAi
displayName?: string
}): DateMentionData => {
// For relative dates with an id, use the relative format
@@ -138,15 +134,7 @@ export const createDateMentionData = ({
: formatRangeValue(range)
const text = value // Use the same value for text
const baseLabel = displayName ?? resolveMentionLabel(label, translate) ?? value
let resolvedName = baseLabel
if (labelOptions?.appendRange) {
resolvedName = translate(withRangeKey, {
label: baseLabel,
range: formatLocalizedRange(range, locale),
})
}
const resolvedName = displayName ?? resolveMentionLabel(label, translate) ?? value
return {
id: id ?? `date:${value}`,
@@ -207,7 +195,7 @@ export const getDateMentionDisplayName = (
mention: Pick<DateMentionData, "label" | "labelOptions" | "value" | "name">,
translate: LabelTranslator,
locale: string,
withRangeKey: I18nKeysForAi,
asRange = false,
): string => {
// Only rely on value range to determine the display name
if (typeof mention.value !== "string") {
@@ -235,12 +223,8 @@ export const getDateMentionDisplayName = (
}
const matched = matchRelative()
if (matched) {
const label = translate(matched.labelKey)
return translate(withRangeKey, {
label,
range: formatLocalizedRange(range, locale),
})
if (matched && !asRange) {
return translate(matched.labelKey)
}
// Fallback: show the localized date range only
@@ -6,6 +6,8 @@ import { ROUTE_FEED_IN_FOLDER } from "~/constants"
import { getRouteParams } from "~/hooks/biz/useRouteParams"
import { getI18n } from "~/i18n"
import type { LabelTranslator } from "../hooks/dateMentionUtils"
import { getDateMentionDisplayName } from "../hooks/dateMentionUtils"
import type { MentionData } from "../types"
export function getMentionTextValue(mentionData: {
@@ -27,7 +29,11 @@ export function getMentionTextValue(mentionData: {
return `<mention-${type} id="${value}"></mention-${type}>`
}
export function getMentionDisplayTextValue(mentionData: MentionData): string {
export function getMentionDisplayTextValue(
mentionData: MentionData,
translate: LabelTranslator,
locale: string,
): string {
const { type, value } = mentionData
switch (type) {
@@ -50,6 +56,10 @@ export function getMentionDisplayTextValue(mentionData: MentionData): string {
}
return "Unknown View"
}
case "date": {
return getDateMentionDisplayName(mentionData, translate, locale, true)
}
default: {
return value
}
-1
View File
@@ -80,7 +80,6 @@
"integration.mcp.services.empty.title": "No MCP Services Connected",
"integration.mcp.services.title": "MCP Services",
"integration.title": "Integration",
"mentions.date.display.with_range": "{{label}} ({{range}})",
"mentions.date.relative.last_15_days.label": "Last 15 days",
"mentions.date.relative.last_15_days.search": "last 15 days|past 15 days|last half month|past half month",
"mentions.date.relative.last_30_days.label": "Last 30 days",
-1
View File
@@ -74,7 +74,6 @@
"integration.mcp.services.empty.title": "MCPサービスが接続されていません",
"integration.mcp.services.title": "MCPサービス",
"integration.title": "統合",
"mentions.date.display.with_range": "{{label}}({{range}})",
"mentions.date.relative.last_15_days.label": "過去15日間",
"mentions.date.relative.last_15_days.search": "過去15日間|直近15日間|半月",
"mentions.date.relative.last_30_days.label": "過去30日間",
-1
View File
@@ -76,7 +76,6 @@
"integration.mcp.services.empty.title": "未连接MCP服务",
"integration.mcp.services.title": "MCP服务",
"integration.title": "集成",
"mentions.date.display.with_range": "{{label}}({{range}})",
"mentions.date.relative.last_15_days.label": "最近15天",
"mentions.date.relative.last_15_days.search": "最近15天|近半个月",
"mentions.date.relative.last_30_days.label": "最近30天",