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

Tanstack: React Query (dev) #1261

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
93c4685
First pass at implementing tanstack react query
cccs-nr Oct 3, 2024
3e892d8
More changes
cccs-nr Oct 4, 2024
3340303
More changes
cccs-nr Oct 6, 2024
5b82f89
Cleaned the code
cccs-nr Oct 6, 2024
b0c46da
More changes
cccs-nr Oct 6, 2024
3dfb8c4
Changes
cccs-nr Oct 8, 2024
9cc6e62
Changes
cccs-nr Oct 8, 2024
53fa891
Added sorting on the al.score in the Alerts components
cccs-nr Oct 8, 2024
c4b59b6
Changed the names
cccs-nr Oct 8, 2024
32071ce
Merge pull request #1262 from CybercentreCanada/feature/alert_sort
cccs-nr Oct 8, 2024
f52ee7b
Merge pull request #1250 from CybercentreCanada/feature/signature_status
cccs-nr Oct 8, 2024
71510ac
Merge pull request #1248 from CybercentreCanada/bugfix/dashboard
cccs-nr Oct 8, 2024
c69de76
Merge pull request #1242 from CybercentreCanada/bugfix/workflow_detail
cccs-nr Oct 8, 2024
07647d4
more changes
cccs-nr Oct 9, 2024
4e1bd78
changes
cccs-nr Oct 9, 2024
450cac3
changes
cccs-nr Oct 9, 2024
b4abcb7
changes
cccs-nr Oct 9, 2024
27cee4a
Removed the '*' on no query and filters
cccs-nr Oct 9, 2024
df83298
Fixed the logic of the body value
cccs-nr Oct 9, 2024
c9c6485
Reverted toSorted() to plain sort()
cccs-nr Oct 9, 2024
2792cea
Moved the Typescript test first cause thats the most important.
cccs-nr Oct 9, 2024
9757fad
Changes to the sort
cccs-nr Oct 9, 2024
0e62fc0
Added a "Show more" button to incrementaly show more files in the fil…
cccs-nr Oct 9, 2024
a773b6c
minor change
cccs-nr Oct 9, 2024
83ddd63
More changes
cccs-nr Oct 10, 2024
1efeda0
Merge pull request #1275 from CybercentreCanada/bugfix/filetree
cccs-nr Oct 10, 2024
6be4adc
Merge pull request #1272 from CybercentreCanada/bugfix/pipeline
cccs-nr Oct 10, 2024
6c5d5aa
Merge pull request #1270 from CybercentreCanada/bugfix/create_workflow
cccs-nr Oct 10, 2024
0640695
Merge pull request #1268 from CybercentreCanada/bugfix/api
cccs-nr Oct 10, 2024
23d58a6
Merge pull request #1265 from CybercentreCanada/bugfix/toSorted
cccs-nr Oct 10, 2024
764ee87
Merge branch 'master' into tanstack-react-query
cccs-nr Oct 10, 2024
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
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:react/recommended"
"plugin:react/recommended",
"plugin:@tanstack/query/recommended"
],
"root": true,
"ignorePatterns": ["vite.config.mts"],
Expand Down Expand Up @@ -50,6 +51,7 @@
}
},
"rules": {
"@tanstack/query/exhaustive-deps": "warn",
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/no-base-to-string": "warn",
"@typescript-eslint/consistent-type-imports": "warn",
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"@mui/styles": "^5.11.9",
"@mui/x-date-pickers": "^5.0.18",
"@mui/x-tree-view": "^7.6.2",
"@tanstack/query-sync-storage-persister": "^5.59.0",
"@tanstack/react-query": "^5.56.2",
"@tanstack/react-query-persist-client": "^5.59.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"autosuggest-highlight": "^3.3.4",
Expand All @@ -41,6 +44,7 @@
"i18next": "^22.4.9",
"i18next-browser-languagedetector": "^7.0.1",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"md5": "^2.3.0",
"moment": "^2.30.1",
"moment-timezone": "^0.5.40",
Expand Down Expand Up @@ -101,6 +105,8 @@
"@iconify/icons-simple-icons": "^1.2.56",
"@iconify/react": "^4.1.1",
"@jest/globals": "^29.6.4",
"@tanstack/eslint-plugin-query": "^5.58.1",
"@tanstack/react-query-devtools": "^5.56.2",
"@testing-library/dom": "^7.31.2",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
Expand Down
10 changes: 5 additions & 5 deletions pipelines/azure-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
yarn install
displayName: Install assemblyline-ui-frontend

- script: |
set -xv # Echo commands before they are run
npm run tsc
displayName: TypeScript

- script: |
set -xv # Echo commands before they are run
npm run ci-test
Expand All @@ -43,11 +48,6 @@ jobs:
npm run ci-lint
displayName: ESLint

- script: |
set -xv # Echo commands before they are run
npm run tsc
displayName: TypeScript

- task: PublishCodeCoverageResults@2
inputs:
codeCoverageTool: Cobertura
Expand Down
20 changes: 18 additions & 2 deletions src/commons/components/pages/PageFullScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import FullscreenIcon from '@mui/icons-material/Fullscreen';
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
import { IconButton, Tooltip, useTheme } from '@mui/material';
import browser from 'browser-detect';
import useAppBar from 'commons/components/app/hooks/useAppBar';
import useAppBarHeight from 'commons/components/app/hooks/useAppBarHeight';
import useAppLayout from 'commons/components/app/hooks/useAppLayout';
import useFullscreenStatus from 'commons/components/utils/hooks/useFullscreenStatus';
import { memo, useCallback, useRef } from 'react';
import { memo, useCallback, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import PageContent from './PageContent';

Expand All @@ -31,6 +32,8 @@ const PageFullscreen = ({ children, margin = null, mb = 2, ml = 2, mr = 2, mt =

const barWillHide = layout.current !== 'top' && appbar.autoHide;

const isFirefox = useMemo(() => browser().name === 'firefox', []);

try {
[isFullscreen, setIsFullscreen] = useFullscreenStatus(maximizableElement);
} catch (e) {
Expand Down Expand Up @@ -63,7 +66,20 @@ const PageFullscreen = ({ children, margin = null, mb = 2, ml = 2, mr = 2, mt =
paddingTop: theme.spacing(2),
right: theme.spacing(2),
zIndex: theme.zIndex.appBar + 1,
top: barWillHide || isFullscreen ? 0 : appBarHeight
top: barWillHide || isFullscreen ? 0 : appBarHeight,
...(!isFirefox
? null
: !isFullscreen
? {
position: 'fixed',
top: '96px',
right: '32px'
}
: {
position: 'fixed',
top: '32px',
right: '32px'
})
}}
>
{fullscreenSupported ? null : (
Expand Down
17 changes: 10 additions & 7 deletions src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Routes from 'components/routes/routes';
import Tos from 'components/routes/tos';
import setMomentFRLocale from 'helpers/moment-fr-locale';
import { getProvider } from 'helpers/utils';
import { APIProvider } from 'lib/api/APIProvider';
import React, { useEffect, useState } from 'react';
import { BrowserRouter } from 'react-router-dom';

Expand Down Expand Up @@ -102,13 +103,15 @@ export const MyApp: React.FC<any> = () => {
const myUser: CustomAppUserService = useMyUser();
return (
<BrowserRouter basename="/">
<SafeResultsProvider>
<QuotaProvider>
<AppProvider user={myUser} preferences={myPreferences} theme={myTheme} sitemap={mySitemap}>
<MyAppMain />
</AppProvider>
</QuotaProvider>
</SafeResultsProvider>
<APIProvider>
<SafeResultsProvider>
<QuotaProvider>
<AppProvider user={myUser} preferences={myPreferences} theme={myTheme} sitemap={mySitemap}>
<MyAppMain />
</AppProvider>
</QuotaProvider>
</SafeResultsProvider>
</APIProvider>
</BrowserRouter>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/useMyAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const useMyAPI = (): UseMyAPIReturn => {
'Content-Type': contentType,
'X-XSRF-TOKEN': getXSRFCookie()
},
body: (!body ? null : contentType === 'application/json' ? JSON.stringify(body) : body) as BodyInit
body: (body !== null ? (contentType === 'application/json' ? JSON.stringify(body) : body) : null) as BodyInit
};

// Run enter callback
Expand Down
2 changes: 1 addition & 1 deletion src/components/models/base/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type Signature = {
source: string;

/** */
state_change_date?: string | Date;
state_change_date?: string;

/** */
state_change_user?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/admin/service_detail/general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ const ServiceGeneral = ({
isOptionEqualToValue={(option, value) => option.toUpperCase() === value.toUpperCase()}
onChange={(_e, values) => {
setModified(true);
setService(s => ({ ...s, recursion_prevention: values.toSorted() }));
setService(s => ({ ...s, recursion_prevention: [...values].sort() }));
}}
renderInput={params => <TextField size="small" margin="dense" {...params} variant="outlined" />}
renderOption={(props, option, state) => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/admin/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function Services() {
() =>
(serviceFeeds || [])
.reduce((prev: string[], item) => (item?.summary ? [...prev, item.summary] : prev), [])
.toSorted(),
.sort(),
[serviceFeeds]
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const WrappedAlertsContent = () => {
const q = search.get('q');
const fq = search.get('fq');

const values = (!q && !fq.length ? ['*'] : q ? [q] : []).concat(fq);
const values = (!q && !fq.length ? [''] : q ? [q] : []).concat(fq);
const query = values
.map(v => ([' or ', ' and '].some(a => v.toLowerCase().includes(a)) ? `(${v})` : v))
.join(' AND ');
Expand Down
3 changes: 2 additions & 1 deletion src/components/routes/alerts/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export const SORT_OPTIONS: Option[] = [
{ value: 'reporting_ts', label: 'alerted_ts' },
{ value: 'owner', label: 'owner' },
{ value: 'priority', label: 'priority' },
{ value: 'status', label: 'status' }
{ value: 'status', label: 'status' },
{ value: 'al.score', label: 'al.score' }
];

export const TC_OPTIONS: Option[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/alerts/utils/SearchParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class ArrayParam<T extends Params> extends BaseParam<T> {

private append(prev: URLSearchParams, values: string[][]): void {
values
.toSorted((a, b) => a.at(-1).localeCompare(b.at(-1)))
.sort((a, b) => a.at(-1).localeCompare(b.at(-1)))
.map(value => this.fromPrefix(value))
.forEach(v => {
prev.append(this.key, v);
Expand Down
4 changes: 2 additions & 2 deletions src/components/routes/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ const WrappedDispatcherCard = ({ dispatcher, up, down, handleStatusChange, statu
{dispatcher.initialized ? (
<div>
{up.length === 0 && down.length === 0 && <span className={classes.muted}>{t('no_services')}</span>}
{up.length !== 0 && <span>{up.join(' | ')}</span>}
{up.length !== 0 && <span>{up.sort().join(' | ')}</span>}
{up.length !== 0 && down.length !== 0 && <span> :: </span>}
{down.length !== 0 && <span>{down.join(' | ')}</span>}
{down.length !== 0 && <span>{down.sort().join(' | ')}</span>}
</div>
) : (
<div>
Expand Down
Loading