mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #9284 from prometheus/update-react-and-ts
Update React 16->17, TypeScript, and some other node deps
This commit is contained in:
commit
ffe8c7e268
|
@ -25,6 +25,8 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"plugins": ["prettier"],
|
"plugins": [
|
||||||
|
"prettier"
|
||||||
|
],
|
||||||
"ignorePatterns": ["src/vendor/**"]
|
"ignorePatterns": ["src/vendor/**"]
|
||||||
}
|
}
|
||||||
|
|
2986
web/ui/react-app/package-lock.json
generated
2986
web/ui/react-app/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -27,22 +27,20 @@
|
||||||
"i": "^0.3.6",
|
"i": "^0.3.6",
|
||||||
"jquery": "^3.5.1",
|
"jquery": "^3.5.1",
|
||||||
"jquery.flot.tooltip": "^0.9.0",
|
"jquery.flot.tooltip": "^0.9.0",
|
||||||
"jsdom": "^16.4.0",
|
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"moment-timezone": "^0.5.23",
|
"moment-timezone": "^0.5.23",
|
||||||
"popper.js": "^1.14.3",
|
"popper.js": "^1.14.3",
|
||||||
"react": "^16.7.0",
|
"react": "^17.0.2",
|
||||||
"react-copy-to-clipboard": "^5.0.1",
|
"react-copy-to-clipboard": "^5.0.4",
|
||||||
"react-dom": "^16.7.0",
|
"react-dom": "^17.0.2",
|
||||||
"react-resize-detector": "^5.0.7",
|
"react-resize-detector": "^6.7.6",
|
||||||
"react-router-dom": "^5.2.1",
|
"react-router-dom": "^5.2.1",
|
||||||
"react-test-renderer": "^16.9.0",
|
"react-test-renderer": "^17.0.2",
|
||||||
"reactstrap": "^8.9.0",
|
"reactstrap": "^8.9.0",
|
||||||
"sanitize-html": "^2.3.3",
|
"sanitize-html": "^2.3.3",
|
||||||
"sass": "1.39.0",
|
"sass": "1.39.0",
|
||||||
"tempusdominus-bootstrap-4": "^5.1.2",
|
"tempusdominus-bootstrap-4": "^5.1.2",
|
||||||
"tempusdominus-core": "^5.0.3",
|
"tempusdominus-core": "^5.0.3"
|
||||||
"use-media": "^1.4.0"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
@ -65,33 +63,31 @@
|
||||||
"not op_mini all"
|
"not op_mini all"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/react-hooks": "^3.1.1",
|
"@testing-library/react-hooks": "^7.0.1",
|
||||||
"@types/enzyme": "^3.10.3",
|
"@types/enzyme": "^3.10.9",
|
||||||
"@types/enzyme-adapter-react-16": "^1.0.5",
|
"@types/flot": "0.0.31",
|
||||||
"@types/flot": "0.0.32",
|
"@types/jest": "^27.0.1",
|
||||||
"@types/jest": "^27.0.0",
|
|
||||||
"@types/jquery": "^3.5.1",
|
"@types/jquery": "^3.5.1",
|
||||||
"@types/moment-timezone": "^0.5.10",
|
"@types/node": "^16.7.6",
|
||||||
"@types/node": "^12.11.1",
|
"@types/react": "^17.0.19",
|
||||||
"@types/react": "^16.8.2",
|
"@types/react-copy-to-clipboard": "^5.0.1",
|
||||||
"@types/react-copy-to-clipboard": "^5.0.0",
|
"@types/react-dom": "^17.0.9",
|
||||||
"@types/react-dom": "^16.8.0",
|
|
||||||
"@types/react-resize-detector": "^5.0.0",
|
"@types/react-resize-detector": "^5.0.0",
|
||||||
"@types/react-router-dom": "^5.1.8",
|
"@types/react-router-dom": "^5.1.8",
|
||||||
"@types/reactstrap": "^8.7.2",
|
|
||||||
"@types/sanitize-html": "^1.20.2",
|
"@types/sanitize-html": "^1.20.2",
|
||||||
"@types/sinon": "^9.0.4",
|
"@types/sinon": "^10.0.2",
|
||||||
"enzyme": "^3.10.0",
|
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
|
||||||
"enzyme-adapter-react-16": "^1.15.1",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-to-json": "^3.4.3",
|
"enzyme-to-json": "^3.6.2",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-config-react-app": "^6.0.0",
|
"eslint-config-react-app": "^6.0.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
|
"jest-canvas-mock": "^2.3.1",
|
||||||
"jest-fetch-mock": "^3.0.3",
|
"jest-fetch-mock": "^3.0.3",
|
||||||
"mutationobserver-shim": "^0.3.7",
|
"mutationobserver-shim": "^0.3.7",
|
||||||
"prettier": "^2.3.2",
|
"prettier": "^2.3.2",
|
||||||
"react-scripts": "4.0.3",
|
"react-scripts": "4.0.3",
|
||||||
"sinon": "^9.0.3",
|
"sinon": "^11.1.2",
|
||||||
"typescript": "^4.4.2"
|
"typescript": "^4.4.2"
|
||||||
},
|
},
|
||||||
"proxy": "http://localhost:9090",
|
"proxy": "http://localhost:9090",
|
||||||
|
|
|
@ -3,7 +3,6 @@ import Navigation from './Navbar';
|
||||||
import { Container } from 'reactstrap';
|
import { Container } from 'reactstrap';
|
||||||
|
|
||||||
import { BrowserRouter as Router, Redirect, Switch, Route } from 'react-router-dom';
|
import { BrowserRouter as Router, Redirect, Switch, Route } from 'react-router-dom';
|
||||||
import useMedia from 'use-media';
|
|
||||||
import {
|
import {
|
||||||
AlertsPage,
|
AlertsPage,
|
||||||
ConfigPage,
|
ConfigPage,
|
||||||
|
@ -19,6 +18,7 @@ import { PathPrefixContext } from './contexts/PathPrefixContext';
|
||||||
import { ThemeContext, themeName, themeSetting } from './contexts/ThemeContext';
|
import { ThemeContext, themeName, themeSetting } from './contexts/ThemeContext';
|
||||||
import { Theme, themeLocalStorageKey } from './Theme';
|
import { Theme, themeLocalStorageKey } from './Theme';
|
||||||
import { useLocalStorage } from './hooks/useLocalStorage';
|
import { useLocalStorage } from './hooks/useLocalStorage';
|
||||||
|
import useMedia from './hooks/useMedia';
|
||||||
|
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
consolesLink: string | null;
|
consolesLink: string | null;
|
||||||
|
|
17
web/ui/react-app/src/hooks/useMedia.ts
Normal file
17
web/ui/react-app/src/hooks/useMedia.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
// A hook to determine whether a CSS media query finds any matches.
|
||||||
|
const useMedia = (query: string): boolean => {
|
||||||
|
const mediaQuery = window.matchMedia(query);
|
||||||
|
const [matches, setMatches] = useState(mediaQuery.matches);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = () => setMatches(mediaQuery.matches);
|
||||||
|
mediaQuery.addEventListener('change', handler);
|
||||||
|
return () => mediaQuery.removeEventListener('change', handler);
|
||||||
|
}, [mediaQuery]);
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useMedia;
|
|
@ -9,6 +9,20 @@ describe('Graph', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb: any) => cb());
|
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb: any) => cb());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Source: https://github.com/maslianok/react-resize-detector#testing-with-enzyme-and-jest
|
||||||
|
beforeEach(() => {
|
||||||
|
window.ResizeObserver = jest.fn().mockImplementation(() => ({
|
||||||
|
observe: jest.fn(),
|
||||||
|
unobserve: jest.fn(),
|
||||||
|
disconnect: jest.fn(),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
window.ResizeObserver = ResizeObserver;
|
||||||
|
});
|
||||||
|
|
||||||
describe('data is returned', () => {
|
describe('data is returned', () => {
|
||||||
const props: any = {
|
const props: any = {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
|
|
|
@ -213,7 +213,7 @@ class Panel extends Component<PanelProps, PanelState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setOptions(opts: Record<string, unknown>): void {
|
setOptions(opts: Partial<PanelOptions>): void {
|
||||||
const newOpts = { ...this.props.options, ...opts };
|
const newOpts = { ...this.props.options, ...opts };
|
||||||
this.props.onOptionsChanged(newOpts);
|
this.props.onOptionsChanged(newOpts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,31 @@
|
||||||
import { configure } from 'enzyme';
|
import { configure } from 'enzyme';
|
||||||
import Adapter from 'enzyme-adapter-react-16';
|
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
||||||
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
||||||
import 'mutationobserver-shim'; // Needed for CodeMirror.
|
import 'mutationobserver-shim'; // Needed for CodeMirror.
|
||||||
import './globals';
|
import './globals';
|
||||||
|
import 'jest-canvas-mock';
|
||||||
|
|
||||||
configure({ adapter: new Adapter() });
|
configure({ adapter: new Adapter() });
|
||||||
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
|
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
|
||||||
customGlobal.fetch = require('jest-fetch-mock');
|
customGlobal.fetch = require('jest-fetch-mock');
|
||||||
customGlobal.fetchMock = customGlobal.fetch;
|
customGlobal.fetchMock = customGlobal.fetch;
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/39830580/jest-test-fails-typeerror-window-matchmedia-is-not-a-function
|
||||||
|
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
||||||
|
Object.defineProperty(window, 'matchMedia', {
|
||||||
|
writable: true,
|
||||||
|
value: jest.fn().mockImplementation((query) => ({
|
||||||
|
matches: false,
|
||||||
|
media: query,
|
||||||
|
onchange: null,
|
||||||
|
addListener: jest.fn(), // Deprecated
|
||||||
|
removeListener: jest.fn(), // Deprecated
|
||||||
|
addEventListener: jest.fn(),
|
||||||
|
removeEventListener: jest.fn(),
|
||||||
|
dispatchEvent: jest.fn(),
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
// CodeMirror in the expression input requires this DOM API. When we upgrade react-scripts
|
// CodeMirror in the expression input requires this DOM API. When we upgrade react-scripts
|
||||||
// and the associated Jest deps, hopefully this won't be needed anymore.
|
// and the associated Jest deps, hopefully this won't be needed anymore.
|
||||||
document.getSelection = function () {
|
document.getSelection = function () {
|
||||||
|
|
Loading…
Reference in a new issue