mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 20:14:16 +00:00
Open the connector a ?connector= link names on the mounted page
The Connectors page read ?connector= only when it mounted, so the Reconnect link in the global toast did nothing while the page was already open.
This commit is contained in:
1 parent
4b87f97785
commit
875118ed20
2 files changed
+26
-4
No files matched your search
@@ -2,7 +2,7 @@ import { configureStore } from '@reduxjs/toolkit';
|
||||
import { act } from 'react';
|
||||
import { createRoot, type Root } from 'react-dom/client';
|
||||
import { Provider } from 'react-redux';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { Link, MemoryRouter } from 'react-router-dom';
|
||||
|
||||
vi.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
@@ -144,6 +144,10 @@ describe('Connectors page', () => {
|
||||
root.render(
|
||||
<Provider store={store}>
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<Link
|
||||
data-testid="reconnect-link"
|
||||
to="/settings/connectors?connector=google_drive"
|
||||
/>
|
||||
<Connectors />
|
||||
</MemoryRouter>
|
||||
</Provider>,
|
||||
@@ -378,6 +382,18 @@ describe('Connectors page', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('opens the page a ?connector= link names while already on the list', async () => {
|
||||
await render();
|
||||
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
|
||||
await act(async () =>
|
||||
container
|
||||
.querySelector<HTMLAnchorElement>('[data-testid="reconnect-link"]')!
|
||||
.click(),
|
||||
);
|
||||
const dialog = document.body.querySelector('[role="dialog"]');
|
||||
expect(dialog?.textContent).toContain('Google Drive');
|
||||
});
|
||||
|
||||
it('shows a retry when the catalog fails to load', async () => {
|
||||
service.getCatalog.mockResolvedValue({ success: false });
|
||||
await render();
|
||||
|
||||
@@ -82,9 +82,15 @@ export default function Connectors() {
|
||||
const [filter, setFilter] = useState<Filter>(
|
||||
initialFilter && FILTERS.includes(initialFilter) ? initialFilter : 'all',
|
||||
);
|
||||
const [openKey, setOpenKey] = useState<string | null>(
|
||||
searchParams.get('connector'),
|
||||
);
|
||||
const connectorParam = searchParams.get('connector');
|
||||
const [openKey, setOpenKey] = useState<string | null>(connectorParam);
|
||||
// A `?connector=` link followed while this page is already open (the
|
||||
// global Reconnect toast) changes only the search: open what it names.
|
||||
const [seenConnectorParam, setSeenConnectorParam] = useState(connectorParam);
|
||||
if (connectorParam !== seenConnectorParam) {
|
||||
setSeenConnectorParam(connectorParam);
|
||||
if (connectorParam) setOpenKey(connectorParam);
|
||||
}
|
||||
const { launch, modals } = useConnectorLauncher();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user