This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new dd5933a50 fix(ai): refresh current history after delayed deletion
(#7019)
dd5933a50 is described below
commit dd5933a50fbf19fd5cc03a20e9335425cfee159e
Author: aias00 <[email protected]>
AuthorDate: Fri Nov 27 12:05:37 2026 +0800
fix(ai): refresh current history after delayed deletion (#7019)
---
.../pages/ai/components/ConversationListModal.tsx | 17 ++++---
.../__tests__/ConversationListModal.test.tsx | 54 ++++++++++++++++++++--
2 files changed, 59 insertions(+), 12 deletions(-)
diff --git a/web/src/pages/ai/components/ConversationListModal.tsx
b/web/src/pages/ai/components/ConversationListModal.tsx
index 4a10e54f0..0185496bf 100644
--- a/web/src/pages/ai/components/ConversationListModal.tsx
+++ b/web/src/pages/ai/components/ConversationListModal.tsx
@@ -178,7 +178,11 @@ const ConversationListPanel = ({
const deleting = deletingIds.length > 0;
// Pulled out of `list` for the callback below: the hook returns a fresh
object every render, so
// depending on it would rebuild `columns` — and with it every cell — on
each one.
- const { items, page, setPage, reload, archived } = list;
+ const { items, reload, archived } = list;
+ const reloadRef = useRef(reload);
+ useEffect(() => {
+ reloadRef.current = reload;
+ }, [reload]);
const rowCount = items.length;
const mountedRef = useRef(false);
useEffect(() => {
@@ -256,15 +260,10 @@ const ConversationListPanel = ({
// belong to the panel is the refresh below: re-querying a list nobody
renders any more wastes a
// request and drives this hook's state from a component that is already
gone.
if (!mountedRef.current) return;
- // A page emptied by the delete has to fall back one, or the pager keeps
offering a page that
- // no longer exists; `setPage` re-queries through the hook, `reload`
covers every other case.
- if (deletedCount > 0 && deletedCount >= rowCount && page > 1) {
- setPage(page - 1);
- } else {
- reload();
- }
+ // Refresh today's query; the hook clamps an emptied page using the
current server total.
+ reloadRef.current();
},
- [onDeleted, page, reload, rowCount, setPage, t],
+ [onDeleted, t],
);
const columns = useMemo<ColumnsType<AiConversationListItemVO>>(
diff --git
a/web/src/pages/ai/components/__tests__/ConversationListModal.test.tsx
b/web/src/pages/ai/components/__tests__/ConversationListModal.test.tsx
index 1df2a5e59..3733f021d 100644
--- a/web/src/pages/ai/components/__tests__/ConversationListModal.test.tsx
+++ b/web/src/pages/ai/components/__tests__/ConversationListModal.test.tsx
@@ -487,6 +487,51 @@ describe('ConversationListModal', () => {
);
});
+ it.each(['archive', 'search', 'page'] as const)(
+ 'keepsTheCurrentQueryWhenAnEarlierPageDeletionFinishesTest (%s)',
+ async (change) => {
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ listMock.mockImplementation(async (query) => {
+ const id = (query?.page ?? 1) + (query?.archived ? 100 : 0) +
(query?.search ? 200 : 0);
+ return page([conversation(id, `conversation-${id}`)], 45, query?.page
?? 1);
+ });
+ let finish!: () => void;
+ deleteMock.mockImplementation(
+ () =>
+ new Promise<void>((resolve) => {
+ finish = resolve;
+ }),
+ );
+ renderModal();
+ await screen.findByText('conversation-1');
+ await user.click(document.querySelector<HTMLElement>('li[title="3"]')!);
+ await screen.findByText('conversation-3');
+ await user.click(screen.getByTestId('ai-conversation-page-delete'));
+ await confirmDelete(user);
+ await waitFor(() => expect(deleteMock).toHaveBeenCalledWith(3));
+ if (change === 'archive') await user.click(screen.getByText('已归档'));
+ else if (change === 'page')
+ await
user.click(document.querySelector<HTMLElement>('li[title="1"]')!);
+ else {
+ const search = screen.getByPlaceholderText('搜索会话标题');
+ await user.type(search, 'needle{Enter}');
+ }
+ const visibleId = change === 'archive' ? 101 : change === 'search' ? 201
: 1;
+ await screen.findByText(`conversation-${visibleId}`);
+ await act(async () => {
+ finish();
+ });
+ await screen.findByText('已删除 1 条会话');
+
expect(screen.getByText(`conversation-${visibleId}`)).toBeInTheDocument();
+ expect(listMock).toHaveBeenLastCalledWith({
+ page: 1,
+ size: 15,
+ archived: change === 'archive',
+ search: change === 'search' ? 'needle' : undefined,
+ });
+ },
+ );
+
it('deletesEveryConversationOnThePageTest', async () => {
const user = userEvent.setup();
listMock
@@ -598,12 +643,15 @@ describe('ConversationListModal', () => {
it('stepsBackAPageWhenTheDeleteEmptiesItTest', async () => {
const user = userEvent.setup();
+ let deleted = false;
listMock.mockImplementation(async (params) =>
params?.page === 2
- ? page([conversation(21, '会话二十一')], 21, 2)
- : page([conversation(1, '会话一')], 21, 1),
+ ? page(deleted ? [] : [conversation(21, '会话二十一')], deleted ? 15 : 16,
2)
+ : page([conversation(1, '会话一')], deleted ? 15 : 16, 1),
);
- deleteMock.mockResolvedValue(undefined);
+ deleteMock.mockImplementation(async () => {
+ deleted = true;
+ });
renderModal();
await screen.findByText('会话一');