Commit a6fc27f6 by Archer Committed by GitHub

fix: slider title (#7130)

parent eb27fafe
...@@ -56,6 +56,18 @@ const EmptyHrefLink = function EmptyHrefLink({ content }: { content: string }) { ...@@ -56,6 +56,18 @@ const EmptyHrefLink = function EmptyHrefLink({ content }: { content: string }) {
); );
}; };
const getLinkTextContent = (children: React.ReactNode): string => {
if (children === undefined || children === null || typeof children === 'boolean') return '';
if (typeof children === 'string' || typeof children === 'number') return String(children);
if (Array.isArray(children)) return children.map(getLinkTextContent).join('');
if (React.isValidElement<{ children?: React.ReactNode }>(children)) {
return getLinkTextContent(children.props.children);
}
return '';
};
const CiteLink = React.memo(function CiteLink({ const CiteLink = React.memo(function CiteLink({
id, id,
chatAuthData, chatAuthData,
...@@ -65,11 +77,6 @@ const CiteLink = React.memo(function CiteLink({ ...@@ -65,11 +77,6 @@ const CiteLink = React.memo(function CiteLink({
const { t } = useTranslation(); const { t } = useTranslation();
const { isOpen, onOpen, onClose } = useDisclosure(); const { isOpen, onOpen, onClose } = useDisclosure();
if (!isObjectId(id)) {
return <></>;
}
const { const {
data: datasetCiteData, data: datasetCiteData,
loading, loading,
...@@ -86,6 +93,10 @@ const CiteLink = React.memo(function CiteLink({ ...@@ -86,6 +93,10 @@ const CiteLink = React.memo(function CiteLink({
[sourceData] [sourceData]
); );
if (!isObjectId(id)) {
return <></>;
}
return ( return (
<Popover <Popover
isLazy isLazy
...@@ -199,7 +210,7 @@ const A = ({ ...@@ -199,7 +210,7 @@ const A = ({
showAnimation: boolean; showAnimation: boolean;
[key: string]: any; [key: string]: any;
}) => { }) => {
const content = useMemo(() => (children === undefined ? '' : String(children)), [children]); const content = useMemo(() => getLinkTextContent(children), [children]);
// empty href link // empty href link
if (!props.href && typeof children?.[0] === 'string') { if (!props.href && typeof children?.[0] === 'string') {
......
...@@ -18,6 +18,8 @@ const streamingIncompleteMarkdownTailPatterns = [ ...@@ -18,6 +18,8 @@ const streamingIncompleteMarkdownTailPatterns = [
/!\[[^\]\n]*\]\([^\s\n)]*$/, /!\[[^\]\n]*\]\([^\s\n)]*$/,
/!\[[^\]\n]*\]$/, /!\[[^\]\n]*\]$/,
/!\[[^\]\n]*$/, /!\[[^\]\n]*$/,
/\[[a-f0-9]{0,24}\]\((?:CITE|QUOTE)?$/i,
/\[[a-f0-9]{1,24}\]?$/i,
/\[[^\]\n]*\]\([^\s\n)]*$/ /\[[^\]\n]*\]\([^\s\n)]*$/
]; ];
const streamingIncompleteTextMarkdownTailMarkers = ['**', '__', '~~'] as const; const streamingIncompleteTextMarkdownTailMarkers = ['**', '__', '~~'] as const;
......
...@@ -44,12 +44,17 @@ const ChatSliderList = () => { ...@@ -44,12 +44,17 @@ const ChatSliderList = () => {
hasBeenRead?: boolean; hasBeenRead?: boolean;
isTemporary?: boolean; isTemporary?: boolean;
}[] = scopedHistories.map((item) => { }[] = scopedHistories.map((item) => {
const isActiveChat = item.chatId === activeChatId && chatBoxData.chatId === item.chatId; const isActiveChat =
item.chatId === activeChatId &&
chatBoxData.chatId === item.chatId &&
chatBoxData.appId === item.appId;
const customTitle = item.customTitle?.trim() ? item.customTitle : undefined; const customTitle = item.customTitle?.trim() ? item.customTitle : undefined;
const realtimeTitle = chatBoxData.title?.trim() ? chatBoxData.title : undefined;
const title = (isActiveChat ? realtimeTitle : undefined) || customTitle || item.title;
return { return {
id: item.chatId, id: item.chatId,
title: getHistoryDisplayTitle(customTitle || item.title), title: getHistoryDisplayTitle(title),
customTitle, customTitle,
top: item.top, top: item.top,
updateTime: item.updateTime, updateTime: item.updateTime,
...@@ -88,6 +93,7 @@ const ChatSliderList = () => { ...@@ -88,6 +93,7 @@ const ChatSliderList = () => {
histories, histories,
t, t,
chatBoxData.chatId, chatBoxData.chatId,
chatBoxData.appId,
chatBoxData.title, chatBoxData.title,
chatBoxData.chatGenerateStatus, chatBoxData.chatGenerateStatus,
chatBoxData.hasBeenRead chatBoxData.hasBeenRead
......
...@@ -403,7 +403,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { ...@@ -403,7 +403,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
}); });
} }
const isOwnerUse = !shareId && !spaceTeamId && String(tmbId) === String(app.tmbId); const isOwnerUse = !shareId && !spaceTeamId;
if (isOwnerUse && source === ChatSourceEnum.online) { if (isOwnerUse && source === ChatSourceEnum.online) {
await recordAppUsage({ await recordAppUsage({
appId: app._id, appId: app._id,
......
...@@ -412,7 +412,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { ...@@ -412,7 +412,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
}); });
} }
const isOwnerUse = !shareId && !spaceTeamId && String(tmbId) === String(app.tmbId); const isOwnerUse = !shareId && !spaceTeamId;
if (isOwnerUse && source === ChatSourceEnum.online) { if (isOwnerUse && source === ChatSourceEnum.online) {
await recordAppUsage({ await recordAppUsage({
appId: app._id, appId: app._id,
......
...@@ -114,6 +114,29 @@ describe('Markdown utils', () => { ...@@ -114,6 +114,29 @@ describe('Markdown utils', () => {
expect(hideStreamingIncompleteMarkdownTail(text)).toBe(text); expect(hideStreamingIncompleteMarkdownTail(text)).toBe(text);
}); });
it('should hide incomplete cite markdown at the streaming tail', () => {
expect(hideStreamingIncompleteMarkdownTail('before [507f1f77bcf86cd799439011](CITE')).toBe(
'before '
);
expect(hideStreamingIncompleteMarkdownTail('before [507f1f77bcf86cd799439011](QUOTE')).toBe(
'before '
);
expect(hideStreamingIncompleteMarkdownTail('before [507f1f77bcf86cd799439011]')).toBe(
'before '
);
expect(hideStreamingIncompleteMarkdownTail('before [507f1f77bcf86cd79943901')).toBe(
'before '
);
});
it('should keep complete cite markdown unchanged', () => {
const cite = 'before [507f1f77bcf86cd799439011](CITE)';
const quote = 'before [507f1f77bcf86cd799439011](QUOTE)';
expect(hideStreamingIncompleteMarkdownTail(cite)).toBe(cite);
expect(hideStreamingIncompleteMarkdownTail(quote)).toBe(quote);
});
it('should hide incomplete text style markdown at the streaming tail', () => { it('should hide incomplete text style markdown at the streaming tail', () => {
expect(hideStreamingIncompleteMarkdownTail('before **bold')).toBe('before '); expect(hideStreamingIncompleteMarkdownTail('before **bold')).toBe('before ');
expect(hideStreamingIncompleteMarkdownTail('before __bold')).toBe('before '); expect(hideStreamingIncompleteMarkdownTail('before __bold')).toBe('before ');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment