Skip to content

Commit

Permalink
Merge pull request #35 from bcgsc/refactor/upgrade-and-swap-fully-to-…
Browse files Browse the repository at this point in the history
…react-query

Refactor/upgrade and swap fully to react query
  • Loading branch information
areisle authored Feb 11, 2022
2 parents b7d745d + 14b4c18 commit 0f112a4
Show file tree
Hide file tree
Showing 39 changed files with 1,050 additions and 1,252 deletions.
127 changes: 104 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-google-charts": "^3.0.15",
"react-query": "^2.26.4",
"react-query": "~3.34.14",
"react-router-dom": "~5.3.0",
"react-select": "^2.4.4",
"slugify": "^1.4.0",
Expand Down
18 changes: 11 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {
import { create } from 'jss';
import { SnackbarProvider } from 'notistack';
import React from 'react';
import { QueryClientProvider } from 'react-query';
import { BrowserRouter } from 'react-router-dom';

import { AuthProvider } from '@/components/Auth';
import api from '@/services/api';

import * as cssTheme from './_theme.scss';
import MainView from './views/MainView';
Expand Down Expand Up @@ -78,13 +80,15 @@ function App() {
<StylesProvider jss={jss}>
<CssBaseline />
<MuiThemeProvider theme={theme}>
<SnackbarProvider anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
<BrowserRouter basename={window._env_.PUBLIC_PATH}>
<AuthProvider>
<MainView />
</AuthProvider>
</BrowserRouter>
</SnackbarProvider>
<QueryClientProvider client={api.queryClient}>
<SnackbarProvider anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
<BrowserRouter basename={window._env_.PUBLIC_PATH}>
<AuthProvider>
<MainView />
</AuthProvider>
</BrowserRouter>
</SnackbarProvider>
</QueryClientProvider>
</MuiThemeProvider>
</StylesProvider>
);
Expand Down
6 changes: 4 additions & 2 deletions src/components/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const useAuth = () => {
const AuthProvider = (props) => {
const { children } = props;

const [logInOrOut, { isLoading: isAuthenticating, data, error }] = useMutation(
const {
mutate: logInOrOut, isLoading: isAuthenticating, data, error,
} = useMutation(
async ({ loggingIn }) => {
if (loggingIn) {
const loggedIn = await keycloak.init({
Expand All @@ -54,7 +56,7 @@ const AuthProvider = (props) => {
await keycloak.login({ redirectUri: window.location.href });
}

const { kbToken: authorizationToken } = await api.post('/token', { keyCloakToken: keycloak.token }).request();
const { kbToken: authorizationToken } = await api.post('/token', { keyCloakToken: keycloak.token });
const { user } = jwt.decode(authorizationToken);

await keycloak.loadUserInfo();
Expand Down
8 changes: 4 additions & 4 deletions src/components/FormField/FilteredRecordAutocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './index.scss';
import { FormControl, FormHelperText } from '@material-ui/core';
import FilterIcon from '@material-ui/icons/FilterList';
import PropTypes from 'prop-types';
import React, { useCallback, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';

import DropDownSelect from '@/components/DropDownSelect';
import RecordAutocomplete from '@/components/RecordAutocomplete';
Expand Down Expand Up @@ -52,9 +52,9 @@ const FilteredRecordAutocomplete = ({

const itemToString = item => schema.getLabel(item);

const searchHandler = api.defaultSuggestionHandler(
const getQueryBody = useMemo(() => api.getDefaultSuggestionQueryBody(
schema.get(selectedClassName),
);
), [selectedClassName]);

const valueToString = (record) => {
if (record && record['@rid']) {
Expand Down Expand Up @@ -90,13 +90,13 @@ const FilteredRecordAutocomplete = ({
disabled={disabled}
getOptionKey={opt => opt['@rid']}
getOptionLabel={itemToString}
getQueryBody={getQueryBody}
isMulti={isMulti}
name={name}
placeholder={isMulti
? `Search for Existing ${selectedClassName} Record(s)`
: `Search for an Existing ${selectedClassName} Record`
}
searchHandler={searchHandler}
/>
</div>
{helperText && (<FormHelperText>{helperText}</FormHelperText>)}
Expand Down
Loading

0 comments on commit 0f112a4

Please sign in to comment.