1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-26 00:21:36 +01:00

Merge branch 'dev' into 'master'

Dev

See merge request turris/reforis/foris-js!43
This commit is contained in:
Bogdan Bodnar 2019-11-20 10:22:05 +00:00
commit 21bbfb6d2e
10 changed files with 63 additions and 31 deletions

4
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "foris", "name": "foris",
"version": "1.3.1", "version": "1.3.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -6269,6 +6269,7 @@
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/immutability-helper/-/immutability-helper-3.0.1.tgz", "resolved": "https://registry.npmjs.org/immutability-helper/-/immutability-helper-3.0.1.tgz",
"integrity": "sha512-U92ROQQt7XkIwrdqCByUI118TQM1hXdKnRQpvKeA0HRyGSnJipu9IWHe4UD8zCN00O8UnQjQzPCgZ1CC3yBzHA==", "integrity": "sha512-U92ROQQt7XkIwrdqCByUI118TQM1hXdKnRQpvKeA0HRyGSnJipu9IWHe4UD8zCN00O8UnQjQzPCgZ1CC3yBzHA==",
"dev": true,
"requires": { "requires": {
"invariant": "^2.2.4" "invariant": "^2.2.4"
} }
@ -6402,6 +6403,7 @@
"version": "2.2.4", "version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
"integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==",
"dev": true,
"requires": { "requires": {
"loose-envify": "^1.0.0" "loose-envify": "^1.0.0"
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "foris", "name": "foris",
"version": "1.3.1", "version": "1.3.2",
"description": "Set of components and utils for Foris and its plugins.", "description": "Set of components and utils for Foris and its plugins.",
"author": "CZ.NIC, z.s.p.o.", "author": "CZ.NIC, z.s.p.o.",
"repository": { "repository": {
@ -15,7 +15,6 @@
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"axios": "^0.19.0", "axios": "^0.19.0",
"immutability-helper": "^3.0.0",
"jest-transform-css": "^2.0.0", "jest-transform-css": "^2.0.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"moment-timezone": "^0.5.25", "moment-timezone": "^0.5.25",
@ -25,8 +24,9 @@
"react-uid": "^2.2.0" "react-uid": "^2.2.0"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^16.9.0", "immutability-helper": "3.0.1",
"react-dom": "^16.9.0" "react": "16.9.0",
"react-dom": "16.9.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.4.4", "@babel/cli": "^7.4.4",
@ -49,12 +49,13 @@
"eslint": "^6.1.0", "eslint": "^6.1.0",
"eslint-config-reforis": "^1.0.0", "eslint-config-reforis": "^1.0.0",
"file-loader": "^4.2.0", "file-loader": "^4.2.0",
"immutability-helper": "3.0.1",
"jest": "^24.8.0", "jest": "^24.8.0",
"jest-mock-axios": "^3.0.0", "jest-mock-axios": "^3.0.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"moment-timezone": "^0.5.25", "moment-timezone": "^0.5.25",
"react": "^16.9.0", "react": "16.9.0",
"react-dom": "^16.9.0", "react-dom": "16.9.0",
"react-styleguidist": "^9.1.16", "react-styleguidist": "^9.1.16",
"snapshot-diff": "^0.5.1", "snapshot-diff": "^0.5.1",
"style-loader": "^1.0.0", "style-loader": "^1.0.0",

View File

@ -11,8 +11,6 @@ import PropTypes from "prop-types";
import { Alert, ALERT_TYPES } from "bootstrap/Alert"; import { Alert, ALERT_TYPES } from "bootstrap/Alert";
import { Portal } from "utils/Portal"; import { Portal } from "utils/Portal";
const AlertContext = React.createContext();
AlertContextProvider.propTypes = { AlertContextProvider.propTypes = {
children: PropTypes.oneOfType([ children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node), PropTypes.arrayOf(PropTypes.node),
@ -21,6 +19,7 @@ AlertContextProvider.propTypes = {
}; };
function AlertContextProvider({ children }) { function AlertContextProvider({ children }) {
const { AlertContext } = window;
const [alert, setAlert] = useState(null); const [alert, setAlert] = useState(null);
const setAlertWrapper = useCallback((message, type = ALERT_TYPES.DANGER) => { const setAlertWrapper = useCallback((message, type = ALERT_TYPES.DANGER) => {
@ -46,7 +45,8 @@ function AlertContextProvider({ children }) {
} }
function useAlert() { function useAlert() {
const { AlertContext } = window;
return useContext(AlertContext); return useContext(AlertContext);
} }
export { AlertContext, AlertContextProvider, useAlert }; export { AlertContextProvider, useAlert };

View File

@ -5,7 +5,9 @@
* See /LICENSE for more information. * See /LICENSE for more information.
*/ */
import { useCallback, useReducer } from "react"; import {
useCallback, useEffect, useReducer, useState,
} from "react";
import { ForisURLs } from "forisUrls"; import { ForisURLs } from "forisUrls";
import { import {
@ -90,3 +92,23 @@ const useAPIDelete = createAPIHook("DELETE");
export { export {
useAPIGet, useAPIPost, useAPIPatch, useAPIPut, useAPIDelete, useAPIGet, useAPIPost, useAPIPatch, useAPIPut, useAPIDelete,
}; };
export function useAPIPolling(endpoint, delay = 1000, until) { // delay ms
const [state, setState] = useState({ state: API_STATE.INIT });
const [getResponse, get] = useAPIGet(endpoint);
useEffect(() => {
if (getResponse.state !== API_STATE.INIT) {
setState(getResponse);
}
}, [getResponse]);
useEffect(() => {
if (until) {
const interval = setInterval(get, delay);
return () => clearInterval(interval);
}
}, [until, delay, get]);
return [state];
}

View File

@ -42,8 +42,10 @@ export function CheckBox({
{...props} {...props}
/> />
<label className="custom-control-label" htmlFor={uid}>{label}</label> <label className="custom-control-label" htmlFor={uid}>
{helpText && <small className="form-text text-muted">{helpText}</small>} {label}
{helpText && <small className="form-text text-muted">{helpText}</small>}
</label>
</div> </div>
</div> </div>
); );

View File

@ -24,18 +24,18 @@ Spinner.defaultProps = {
}; };
export function Spinner({ export function Spinner({
fullScreen, children, className, ...props fullScreen, children, className,
}) { }) {
if (!fullScreen) { if (!fullScreen) {
return ( return (
<div className={`spinner-wrapper ${className || "my-3 text-center"}`} {...props}> <div className={`spinner-wrapper ${className || "my-3 text-center"}`}>
<SpinnerElement>{children}</SpinnerElement> <SpinnerElement>{children}</SpinnerElement>
</div> </div>
); );
} }
return ( return (
<div className="spinner-fs-wrapper" {...props}> <div className="spinner-fs-wrapper">
<div className="spinner-fs-background"> <div className="spinner-fs-background">
<SpinnerElement>{children}</SpinnerElement> <SpinnerElement>{children}</SpinnerElement>
</div> </div>

View File

@ -18,12 +18,12 @@ exports[`<Checkbox/> Render checkbox 1`] = `
for="1" for="1"
> >
Test label Test label
<small
class="form-text text-muted"
>
Some help text
</small>
</label> </label>
<small
class="form-text text-muted"
>
Some help text
</small>
</div> </div>
</div> </div>
`; `;
@ -45,12 +45,12 @@ exports[`<Checkbox/> Render uncheked checkbox 1`] = `
for="1" for="1"
> >
Test label Test label
<small
class="form-text text-muted"
>
Some help text
</small>
</label> </label>
<small
class="form-text text-muted"
>
Some help text
</small>
</div> </div>
</div> </div>
`; `;

View File

@ -7,7 +7,12 @@
// API // API
export { export {
useAPIGet, useAPIPost, useAPIPatch, useAPIPut, useAPIDelete, useAPIGet,
useAPIPost,
useAPIPatch,
useAPIPut,
useAPIDelete,
useAPIPolling,
} from "api/hooks"; } from "api/hooks";
export { API_STATE } from "api/utils"; export { API_STATE } from "api/utils";
@ -70,4 +75,4 @@ export {
} from "validations"; } from "validations";
// Alert context // Alert context
export { AlertContext, AlertContextProvider, useAlert } from "alertContext/AlertContext"; export { AlertContextProvider, useAlert } from "alertContext/AlertContext";

View File

@ -7,11 +7,11 @@
import React from "react"; import React from "react";
import { AlertContext } from "../alertContext/AlertContext";
const mockSetAlert = jest.fn(); const mockSetAlert = jest.fn();
const mockDismissAlert = jest.fn(); const mockDismissAlert = jest.fn();
window.AlertContext = React.createContext();
function AlertContextMock({ children }) { function AlertContextMock({ children }) {
return ( return (
<AlertContext.Provider value={[mockSetAlert, mockDismissAlert]}> <AlertContext.Provider value={[mockSetAlert, mockDismissAlert]}>

View File

@ -14,7 +14,7 @@ import { ErrorMessage } from "./ErrorMessage";
function withEither(conditionalFn, Either) { function withEither(conditionalFn, Either) {
return (Component) => (props) => { return (Component) => (props) => {
if (conditionalFn(props)) { if (conditionalFn(props)) {
return <Either />; return <Either {...props} />;
} }
return <Component {...props} />; return <Component {...props} />;
}; };