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

upgrade to react v18 #119

Merged
merged 4 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"file-saver": "^2.0.5",
"i18next": "^20.3.1",
"papaparse": "^5.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-highlight-words": "^0.17.0",
"react-i18next": "^12.0.0",
"react-router-dom": "^5.2.0",
"react-router-dom": "^6.4.3",
"react-syntax-highlighter": "^15.4.4",
"set-value": "^4.1.0",
"socket.io-client": "^4.1.3",
Expand All @@ -42,10 +42,10 @@
"@types/loadable__component": "^5.13.4",
"@types/node": "^12.0.0",
"@types/papaparse": "^5.2.6",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"@types/react-highlight-words": "^0.16.2",
"@types/react-router-dom": "^5.1.7",
"@types/react-router-dom": "^5.3.3",
"@types/react-syntax-highlighter": "^13.5.2",
"@types/webpack-env": "^1.16.3",
"@vitest/coverage-c8": "^0.25.0",
Expand Down
64 changes: 11 additions & 53 deletions client/src/components/customInput/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InputAdornment, makeStyles, TextField } from '@material-ui/core';
import { useRef, FC, useState, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { useSearchParams } from 'react-router-dom';
import Icons from '../icons/Icons';
import { SearchType } from './Types';

Expand Down Expand Up @@ -75,64 +75,24 @@ const useSearchStyles = makeStyles(theme => ({
},
}));

let timer: NodeJS.Timeout | null = null;

const SearchInput: FC<SearchType> = props => {
const { searchText = '', onClear = () => {}, onSearch = () => {} } = props;
const [searchValue, setSearchValue] = useState<string | null>(
searchText || null
);

const [isInit, setIsInit] = useState<boolean>(true);

const searched = useMemo(
() => searchValue !== '' && searchValue !== null,
[searchValue]
);

const [searchParams, setSearchParams] = useSearchParams();
const [searchValue, setSearchValue] = useState<string>(searchText || '');
const searched = useMemo(() => searchValue !== '', [searchValue]);
const classes = useSearchStyles({ searched });
const { t: commonTrans } = useTranslation();

const history = useHistory();

const inputRef = useRef<any>(null);

const savedSearchFn = useRef<(value: string) => void>(() => {});
useEffect(() => {
savedSearchFn.current = onSearch;
}, [onSearch]);
const handleSearch = (value: string) => {
onSearch(value);
};

useEffect(() => {
if (timer) {
clearTimeout(timer);
}
if (searchValue !== null && !isInit) {
timer = setTimeout(() => {
// save other params data and remove last time search info
const location = history.location;
const params = new URLSearchParams(location.search);
params.delete('search');

if (searchValue) {
params.append('search', searchValue);
}
// add search value in url
history.push({ search: params.toString() });

savedSearchFn.current(searchValue);
}, 300);
}

return () => {
timer && clearTimeout(timer);
};
}, [searchValue, history, isInit]);

const handleSearch = (value: string | null) => {
if (value !== null) {
onSearch(value);
}
};
searchParams[searchValue ? 'set' : 'delete']('search', searchValue);
setSearchParams(searchParams);
handleSearch(searchValue);
}, [searchValue]);

return (
<div className={classes.wrapper}>
Expand All @@ -150,7 +110,6 @@ const SearchInput: FC<SearchType> = props => {
className={`flex-center ${classes.iconWrapper}`}
onClick={e => {
setSearchValue('');
setIsInit(false);
inputRef.current.focus();
onClear();
}}
Expand All @@ -173,7 +132,6 @@ const SearchInput: FC<SearchType> = props => {
onChange={e => {
const value = e.target.value.trim();
setSearchValue(value);
setIsInit(false);
if (value === '') {
onClear();
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { makeStyles, Theme, createStyles, Typography } from '@material-ui/core';
import { HeaderType } from './Types';
import { navContext } from '../../context/Navigation';
import icons from '../icons/Icons';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { authContext } from '../../context/Auth';
import { useTranslation } from 'react-i18next';
import { MILVUS_ADDRESS } from '../../consts/Localstorage';
Expand Down Expand Up @@ -60,14 +60,14 @@ const Header: FC<HeaderType> = props => {
const classes = useStyles();
const { navInfo } = useContext(navContext);
const { address, setAddress, setIsAuth } = useContext(authContext);
const history = useHistory();
const navigate = useNavigate();
const { t: commonTrans } = useTranslation();
const statusTrans = commonTrans('status');
const BackIcon = icons.back;
const LogoutIcon = icons.logout;

const handleBack = (path: string) => {
history.push(path);
navigate(-1);
};

const handleLogout = () => {
Expand Down
152 changes: 0 additions & 152 deletions client/src/components/layout/Layout.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions client/src/components/menu/Types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ButtonProps } from '@material-ui/core/Button';
import { ReactElement } from 'react';
import { LoadableClassComponent } from '@loadable/component';

export type SimpleMenuType = {
label: string;
Expand All @@ -20,7 +19,7 @@ type CustomIcon = (
) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;

export type NavMenuItem = {
icon: CustomIcon | LoadableClassComponent<any>;
icon: CustomIcon;
iconActiveClass?: string;
iconNormalClass?: string;
label: string;
Expand Down
12 changes: 4 additions & 8 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { StrictMode } from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import './index.css';
import './i18n';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<StrictMode>
<App />
</StrictMode>,
document.getElementById('root')
);
const container = document.getElementById('root');
const root = createRoot(container!); // createRoot(container!) if you use TypeScript
root.render(<App />);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/collections/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ALL_ROUTER_TYPES } from '../../router/Types';
import CustomTabList from '../../components/customTabList/CustomTabList';
import { ITab } from '../../components/customTabList/Types';
import Partitions from '../partitions/Partitions';
import { useHistory, useLocation, useParams } from 'react-router-dom';
import { useNavigate, useLocation, useParams } from 'react-router-dom';
import { useMemo } from 'react';
import { parseLocationSearch } from '../../utils/Format';
import Schema from '../schema/Schema';
Expand All @@ -22,7 +22,7 @@ const Collection = () => {

useNavigationHook(ALL_ROUTER_TYPES.COLLECTION_DETAIL, { collectionName });

const history = useHistory();
const navigate = useNavigate();
const location = useLocation();

const { t: collectionTrans } = useTranslation('collection');
Expand All @@ -36,7 +36,7 @@ const Collection = () => {

const handleTabChange = (activeIndex: number) => {
const path = location.pathname;
history.push(`${path}?activeIndex=${activeIndex}`);
navigate(`${path}?activeIndex=${activeIndex}`);
};

const tabs: ITab[] = [
Expand Down
Loading