Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7499 - Update react router dom #7591

Draft
wants to merge 43 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ed06afc
update package
Zasa-san Jan 16, 2025
e052ca7
update package to new name
Zasa-san Jan 16, 2025
3702a25
remove @remix-run/router
Zasa-san Jan 16, 2025
3883fb4
bulk update imports, types, mocks
Zasa-san Jan 16, 2025
f4b1ad8
add missing import update
Zasa-san Jan 16, 2025
44d9ebb
update dependabot ignores
Zasa-san Jan 16, 2025
6a4fccb
Merge branch 'development' into 7499-update-react-router-dom
Zasa-san Jan 20, 2025
d848ffb
relative splat path
Zasa-san Jan 20, 2025
6b825b6
keep element defined in parent route
Zasa-san Jan 20, 2025
694c20b
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Jan 20, 2025
11576d3
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Jan 21, 2025
3291d32
wip await useNavigate and useRevalidator
Zasa-san Jan 21, 2025
54eccc4
await navigates and revalidators
Zasa-san Jan 21, 2025
b3e4162
Merge branch 'development' into 7499-update-react-router-dom
Zasa-san Jan 21, 2025
038167d
sets TextEncoder/TextDecoder for jsdom in jest config
mfacar Jan 22, 2025
57bfcae
Merge branch 'development' into 7499-update-react-router-dom
Zasa-san Jan 22, 2025
cca70da
updates snapshots
mfacar Jan 23, 2025
0472d33
Commented lines to diagnose rendering problem
mfacar Jan 23, 2025
a163c78
Merge branch '7499-update-react-router-dom' of https://github.com/hur…
mfacar Jan 23, 2025
aef169d
wait for navigation to finish
Zasa-san Jan 23, 2025
19633d1
add missing future flags
Zasa-san Jan 23, 2025
90aab4c
use same config in server side render
Zasa-san Jan 23, 2025
ae20a6b
upgrade library route layout
Zasa-san Jan 23, 2025
e7ce32d
wip possible solution for index element
Zasa-san Jan 23, 2025
f35f325
only run cleanup when leaving library
Zasa-san Jan 24, 2025
32de251
wip update library tests
Zasa-san Jan 24, 2025
c98e999
library cards as default
mfacar Jan 24, 2025
65c27b1
check library status
mfacar Jan 25, 2025
fab5376
move from useEffect to componentWillUnmount
mfacar Jan 26, 2025
79da954
Merge branch 'development' into 7499-update-react-router-dom
Zasa-san Jan 27, 2025
8dd7a3b
remove outdated asserts
Zasa-san Jan 27, 2025
d0c64b2
use array method
Zasa-san Jan 27, 2025
46fbe94
await fetcher
Zasa-san Jan 27, 2025
3bd1e5d
wait for selectors in puppeteer
Zasa-san Jan 27, 2025
d118aa8
migrate e2e/mobile/sidePanels.test.ts
Zasa-san Jan 27, 2025
f7512d1
migrate private instance e2e
Zasa-san Jan 27, 2025
80f5bcb
Merge branch 'development' into 7499-update-react-router-dom
Zasa-san Jan 28, 2025
7121298
wait for navigations
Zasa-san Jan 28, 2025
af2c8af
wait for notifications and paginator + realclick
Zasa-san Jan 28, 2025
7efa994
wait selectors
Zasa-san Jan 28, 2025
712e144
single viewport set
Zasa-san Jan 28, 2025
10a773b
Merge branch 'development' of https://github.com/huridocs/uwazi into …
Zasa-san Jan 28, 2025
4a8b74a
update import
Zasa-san Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ updates:
- dependency-name: '@typescript-eslint/parser'
- dependency-name: eslint #6784
- dependency-name: fetch-mock
- dependency-name: react-router-dom
- dependency-name: react-datepicker
- dependency-name: recharts
- dependency-name: '@headlessui/react'
Expand Down
2 changes: 1 addition & 1 deletion app/react/App/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-named-as-default */
import React, { useState, useMemo } from 'react';
import PropTypes from 'prop-types';
import { Outlet, useLocation, useParams } from 'react-router-dom';
import { Outlet, useLocation, useParams } from 'react-router';
import { useAtom } from 'jotai';
import Notifications from 'app/Notifications';
import Cookiepopup from 'app/App/Cookiepopup';
Expand Down
2 changes: 1 addition & 1 deletion app/react/App/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router';
import { bindActionCreators, Dispatch } from 'redux';
import { connect, ConnectedProps } from 'react-redux';
import { fromJS } from 'immutable';
Expand Down
4 changes: 2 additions & 2 deletions app/react/App/specs/Menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { I18NLink } from 'app/I18N';
import { renderConnected } from 'app/utils/test/renderConnected';
import { Menu } from '../Menu';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useLocation: () => ({
search: '?q=(searchTerm:%27asd%27)',
}),
Expand Down
2 changes: 1 addition & 1 deletion app/react/Attachments/components/ViewDocumentLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import { Link, useLocation } from 'react-router';
import { CurrentLocationLink } from 'app/Layout';
import { EntitySchema } from 'shared/types/entityType';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from 'react-router-dom';
import { Link } from 'react-router';
import React from 'react';
import { shallow } from 'enzyme';

Expand All @@ -13,8 +13,8 @@ const mockUseLocation = jest.fn().mockImplementation(() => ({
pathname: `?page=${pathname}`,
}));

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useLocation: () => mockUseLocation(),
}));
const renderComponent = (entity: EntitySchema) => {
Expand Down
2 changes: 1 addition & 1 deletion app/react/Forms/components/MultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-classes-per-file */
/* eslint-disable class-methods-use-this,max-lines */

import { Link } from 'react-router-dom';
import { Link } from 'react-router';
import ShowIf from 'app/App/ShowIf';
import { filterOptions } from 'shared/optionsUtils';
import { t, Translate } from 'app/I18N';
Expand Down
2 changes: 1 addition & 1 deletion app/react/I18N/I18NLinkV2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { NavLinkProps, NavLink } from 'react-router';
import { useAtomValue } from 'jotai';
import { NavLinkProps, NavLink } from 'react-router-dom';
import { localeAtom } from 'V2/atoms';

type I18NLinkProps = NavLinkProps & { to: string; activeClassname?: string };
Expand Down
16 changes: 8 additions & 8 deletions app/react/I18N/components/I18NLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { useNavigate, NavLink, useLocation } from 'react-router-dom';
import { useNavigate, NavLink, useLocation } from 'react-router';
import { omit } from 'lodash';

const defaultProps = {
Expand Down Expand Up @@ -48,20 +48,20 @@ const I18NLink = (props: I18NLinkProps) => {
}, delay);
};

const _navigate = () => {
navigate(to, { replace });
const _navigate = async () => {
await navigate(to, { replace });
scrollToHashWithRetry(location.hash);
};

const onClickHandler = (e: { preventDefault: () => void }) => {
const onClickHandler = async (e: { preventDefault: () => void }) => {
e.preventDefault();
if (disabled) return;

if (onClick && confirmTitle) {
props.mainContext.confirm({
accept: () => {
accept: async () => {
onClick(e);
_navigate();
await _navigate();
},
title: confirmTitle,
message: confirmMessage,
Expand All @@ -71,10 +71,10 @@ const I18NLink = (props: I18NLinkProps) => {

if (onClick) {
onClick(e);
_navigate();
await _navigate();
return;
}
_navigate();
await _navigate();
};

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions app/react/I18N/components/I18NMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable react/no-multi-comp */
/* eslint-disable react-hooks/rules-of-hooks */
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Location, useLocation } from 'react-router-dom';
import { Location, useLocation } from 'react-router';
import { useAtom, useAtomValue } from 'jotai';
import { ChevronUpIcon, ChevronDownIcon } from '@heroicons/react/20/solid';
import { LanguagesListSchema } from 'shared/types/commonTypes';
import { NeedAuthorization } from 'V2/Components/UI';
import { Translate, t } from 'app/I18N';
import { useOnClickOutsideElement } from 'app/utils/useOnClickOutsideElementHook';
import { NeedAuthorization } from 'V2/Components/UI';
import { inlineEditAtom, localeAtom, settingsAtom, userAtom } from 'V2/atoms';
import { Translate, t } from 'app/I18N';

const locationSearch = (location: Location) => {
const cleanSearch = location.search.split(/page=\d+|&page=\d+/).join('');
Expand Down
2 changes: 1 addition & 1 deletion app/react/I18N/components/specs/I18NLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/* eslint-disable max-statements */
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { MemoryRouter, Route, Routes } from 'react-router';
import { I18NLink } from '../I18NLink';
import { MemoryRouter, Route, Routes } from 'react-router-dom';

describe('I18NLink', () => {
let props;
Expand Down
2 changes: 1 addition & 1 deletion app/react/I18N/components/specs/I18NMenu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import React from 'react';
import { act, fireEvent, RenderResult, screen, render } from '@testing-library/react';
import { Location, MemoryRouter } from 'react-router-dom';
import { Location, MemoryRouter } from 'react-router';
import { createStore, Provider } from 'jotai';
import { ClientUserSchema } from 'app/apiResponseTypes';
import { inlineEditAtom, localeAtom, settingsAtom, userAtom } from 'V2/atoms';
Expand Down
2 changes: 1 addition & 1 deletion app/react/I18N/specs/I18NLinkV2.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import { render, RenderResult } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import { BrowserRouter } from 'react-router';
import { TestAtomStoreProvider } from 'V2/testing';
import { localeAtom } from 'V2/atoms';
import { I18NLink } from '../I18NLinkV2';
Expand Down
2 changes: 1 addition & 1 deletion app/react/Layout/CurrentLocationLink.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link, useLocation } from 'react-router-dom';
import { Link, useLocation } from 'react-router';

const validProps = props => {
const { to, ...valid } = props;
Expand Down
2 changes: 1 addition & 1 deletion app/react/Layout/DocumentsList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-lines */
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';
import { toUrlParams } from 'shared/JSONRequest';
import rison from 'rison-node';
import { SearchBar } from 'app/Library/components/SearchBar';
Expand Down
4 changes: 2 additions & 2 deletions app/react/Layout/specs/CurrentLocationLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { shallow } from 'enzyme';
import { CurrentLocationLink } from '../CurrentLocationLink';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useLocation: () => ({ pathname: 'pathanem', search: 'param=value&param2=value2' }),
}));

Expand Down
80 changes: 48 additions & 32 deletions app/react/Library/Library.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react';
import { Outlet, matchPath } from 'react-router';
import RouteHandler from 'app/App/RouteHandler';
import { actions } from 'app/BasicReducer';
import { enterLibrary, unsetDocuments, zoomIn, zoomOut } from 'app/Library/actions/libraryActions';
import DocumentsList from 'app/Library/components/DocumentsList';
import { requestState } from 'app/Library/helpers/requestState';
import LibraryLayout from 'app/Library/LibraryLayout';
import { wrapDispatch } from 'app/Multireducer';
import { withRouter } from 'app/componentWrappers';
import { trackPage } from 'app/App/GoogleAnalytics';
import { routes as appRoutes } from 'app/appRoutes';

class Library extends RouteHandler {
class LibraryRootComponent extends RouteHandler {
constructor(props, context) {
super(props, context);
this.superComponentWillReceiveProps = super.componentWillReceiveProps;
Expand All @@ -22,26 +20,51 @@ class Library extends RouteHandler {
this.state = { scrollCount: 0 };
}

static async requestState(requestParams, globalResources) {
return requestState(requestParams, globalResources);
}

urlHasChanged(nextProps) {
const nextSearchParams = new URLSearchParams(nextProps.location.search);
const currentSearchParams = new URLSearchParams(this.props.location.search);
return nextSearchParams.get('q') !== currentSearchParams.get('q');
}

componentWillUnmount() {
this.emptyState();
}

componentDidUpdate(prevProps) {
if (this.urlHasChanged(prevProps)) {
this.getClientState(this.props);
}
}

findMatchingRoute = (pathname, routes, parentPath = '') => {
let result = null;

routes.every(route => {
if (result !== null) {
return false;
}

const currentPath = `${parentPath}/${route.path || ''}`.replace('//', '/');
const match = matchPath({ path: currentPath, end: false }, pathname);

if (match) {
if (currentPath === pathname && route.handle?.library) result = route;

if (route.children) {
const childMatch = this.findMatchingRoute(pathname, route.children, currentPath);
if (childMatch) result = childMatch;
}
}
return true;
});

return result;
};

componentWillUnmount() {
const nextLocation = window?.location?.pathname;
const matchedRoute = this.findMatchingRoute(nextLocation, appRoutes);
if (!matchedRoute && !nextLocation.includes('library')) {
this.emptyState();
}
}

emptyState() {
wrapDispatch(this.context.store.dispatch, 'library')(unsetDocuments());
actions.set('library.sidepanel.quickLabelState', {});
Expand All @@ -56,26 +79,19 @@ class Library extends RouteHandler {
}

render() {
trackPage();
return (
<LibraryLayout
sidePanelMode={this.props.sidePanelMode}
scrollCallback={this.scrollCallback}
scrollCount={this.state.scrollCount}
>
<DocumentsList
storeKey="library"
CollectionViewer={this.props.viewer}
zoomIn={this.zoomIn}
zoomOut={this.zoomOut}
scrollCount={this.state.scrollCount}
/>
</LibraryLayout>
);
if (this.props.children) {
return this.props.children;
}

return <Outlet />;
}
}

const SSRLibrary = withRouter(Library);
const SSRLibrary = withRouter(LibraryRootComponent);

export const LibraryRoot = Object.assign(SSRLibrary, {
requestState: LibraryRootComponent.requestState,
});

export const LibraryCards = Object.assign(SSRLibrary, { requestState: Library.requestState });
export default Library;
export { LibraryRootComponent };
export default LibraryRoot;
41 changes: 41 additions & 0 deletions app/react/Library/LibraryCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { LibraryRootComponent } from 'app/Library/Library';
import LibraryLayout from 'app/Library/LibraryLayout';
import DocumentsList from 'app/Library/components/DocumentsList';
import { withRouter } from 'app/componentWrappers';
import { trackPage } from 'app/App/GoogleAnalytics';
import { requestState } from 'app/Library/helpers/requestState';

class LibraryCardsComponent extends LibraryRootComponent {
static async requestState(requestParams, globalResources) {
return requestState(requestParams, globalResources);
}

render() {
trackPage();
return (
<LibraryLayout
sidePanelMode={this.props.sidePanelMode}
scrollCallback={this.scrollCallback}
scrollCount={this.state.scrollCount}
>
<DocumentsList
storeKey="library"
CollectionViewer={this.props.viewer}
zoomIn={this.zoomIn}
zoomOut={this.zoomOut}
scrollCount={this.state.scrollCount}
/>
</LibraryLayout>
);
}
}

const SSRLibraryComponent = withRouter(LibraryCardsComponent);

const LibraryCards = Object.assign(SSRLibraryComponent, {
requestState: LibraryCardsComponent.requestState,
});

export { LibraryCardsComponent };
export { LibraryCards };
4 changes: 2 additions & 2 deletions app/react/Library/LibraryMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import { withRouter } from 'app/componentWrappers';
import { requestState } from 'app/Library/helpers/requestState';
import { MapView } from 'app/Library/components/MapView';
import { LibraryRootComponent } from 'app/Library/Library';
import LibraryLayout from 'app/Library/LibraryLayout';
import Library from 'app/Library/Library';
import LibraryModeToggleButtons from 'app/Library/components/LibraryModeToggleButtons';
import { trackPage } from 'app/App/GoogleAnalytics';

class LibraryMapComponent extends Library {
class LibraryMapComponent extends LibraryRootComponent {
static async requestState(requestParams, globalResources) {
return requestState(requestParams, globalResources, { geolocation: true });
}
Expand Down
4 changes: 2 additions & 2 deletions app/react/Library/LibraryTable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { TableViewer } from 'app/Layout/TableViewer';
import Library from 'app/Library/Library';
import { LibraryRootComponent } from 'app/Library/Library';
import LibraryLayout from 'app/Library/LibraryLayout';
import DocumentsList from 'app/Library/components/DocumentsList';
import { requestState } from 'app/Library/helpers/requestState';
import { withRouter } from 'app/componentWrappers';
import { trackPage } from 'app/App/GoogleAnalytics';

class LibraryTableComponent extends Library {
class LibraryTableComponent extends LibraryRootComponent {
static async requestState(requestParams, globalResources) {
return requestState(requestParams, globalResources, { calculateTableColumns: true });
}
Expand Down
Loading
Loading