Commit a6fc27f6 by Archer Committed by GitHub

fix: slider title (#7130)

parent eb27fafe
......@@ -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({
id,
chatAuthData,
......@@ -65,11 +77,6 @@ const CiteLink = React.memo(function CiteLink({
const { t } = useTranslation();
const { isOpen, onOpen, onClose } = useDisclosure();
if (!isObjectId(id)) {
return <></>;
}
const {
data: datasetCiteData,
loading,
......@@ -86,6 +93,10 @@ const CiteLink = React.memo(function CiteLink({
[sourceData]
);
if (!isObjectId(id)) {
return <></>;
}
return (
<Popover
isLazy
......@@ -199,7 +210,7 @@ const A = ({
showAnimation: boolean;
[key: string]: any;
}) => {
const content = useMemo(() => (children === undefined ? '' : String(children)), [children]);
const content = useMemo(() => getLinkTextContent(children), [children]);
// empty href link
if (!props.href && typeof children?.[0] === 'string') {
......
......@@ -18,6 +18,8 @@ const streamingIncompleteMarkdownTailPatterns = [
/!\[[^\]\n]*\]\([^\s\n)]*$/,
/!\[[^\]\n]*\]$/,
/!\[[^\]\n]*$/,
/\[[a-f0-9]{0,24}\]\((?:CITE|QUOTE)?$/i,
/\[[a-f0-9]{1,24}\]?$/i,
/\[[^\]\n]*\]\([^\s\n)]*$/
];
const streamingIncompleteTextMarkdownTailMarkers = ['**', '__', '~~'] as const;
......
......@@ -44,12 +44,17 @@ const ChatSliderList = () => {
hasBeenRead?: boolean;
isTemporary?: boolean;
}[] = 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 realtimeTitle = chatBoxData.title?.trim() ? chatBoxData.title : undefined;
const title = (isActiveChat ? realtimeTitle : undefined) || customTitle || item.title;
return {
id: item.chatId,
title: getHistoryDisplayTitle(customTitle || item.title),
title: getHistoryDisplayTitle(title),
customTitle,
top: item.top,
updateTime: item.updateTime,
......@@ -88,6 +93,7 @@ const ChatSliderList = () => {
histories,
t,
chatBoxData.chatId,
chatBoxData.appId,
chatBoxData.title,
chatBoxData.chatGenerateStatus,
chatBoxData.hasBeenRead
......
......@@ -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) {
await recordAppUsage({
appId: app._id,
......
......@@ -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) {
await recordAppUsage({
appId: app._id,
......
......@@ -114,6 +114,29 @@ describe('Markdown utils', () => {
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', () => {
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