From cea73254271ed5fbc6444ee970d95fa7c5713f82 Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Mon, 9 Dec 2019 11:51:50 +0100 Subject: [PATCH 1/4] Fixed link to git repository --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d2ca0d5..a42ed67 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "CZ.NIC, z.s.p.o.", "repository": { "type": "git", - "url": "https://gitlab.labs.nic.cz/turris/reforis/forisjs.git" + "url": "https://gitlab.labs.nic.cz/turris/reforis/foris-js.git" }, "keywords": [ "foris", From 90509f2a23d7c662315b0f3a9c2dbbfb97edd7f8 Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Mon, 16 Dec 2019 13:44:58 +0100 Subject: [PATCH 2/4] Detect clicks outside element with a hook --- package-lock.json | 2 +- package.json | 2 +- src/bootstrap/Modal.js | 14 +++----------- src/form/__tests__/hooks.test.js | 4 ++-- src/index.js | 1 + src/utils/hooks.js | 16 ++++++++++++++++ 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 12c5734..a7ee68f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a42ed67..1219e81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "2.0.0", + "version": "2.1.0", "description": "Set of components and utils for Foris and its plugins.", "author": "CZ.NIC, z.s.p.o.", "repository": { diff --git a/src/bootstrap/Modal.js b/src/bootstrap/Modal.js index a212c1f..9e9dbe7 100644 --- a/src/bootstrap/Modal.js +++ b/src/bootstrap/Modal.js @@ -5,10 +5,11 @@ * See /LICENSE for more information. */ -import React, { useEffect, useRef } from "react"; +import React, { useRef } from "react"; import PropTypes from "prop-types"; import { Portal } from "utils/Portal"; +import { useClickOutside } from "utils/hooks"; Modal.propTypes = { /** Is modal shown value */ @@ -26,16 +27,7 @@ Modal.propTypes = { export function Modal({ shown, setShown, children }) { const dialogRef = useRef(); - useEffect(() => { - function handleClickOutsideDialog(e) { - if (!dialogRef.current.contains(e.target)) setShown(false); - } - - document.addEventListener("mousedown", handleClickOutsideDialog); - return () => { - document.removeEventListener("mousedown", handleClickOutsideDialog); - }; - }, [setShown]); + useClickOutside(dialogRef, () => setShown(false)); return ( diff --git a/src/form/__tests__/hooks.test.js b/src/form/__tests__/hooks.test.js index 0063e27..52516ac 100644 --- a/src/form/__tests__/hooks.test.js +++ b/src/form/__tests__/hooks.test.js @@ -10,6 +10,7 @@ import React from 'react'; import { act, fireEvent, render, waitForElement } from 'customTestRender'; import mockAxios from 'jest-mock-axios'; import { ForisForm } from "../components/ForisForm"; +import { WebSockets } from "webSockets/WebSockets"; // It's possible to unittest each hooks via react-hooks-testing-library. @@ -30,7 +31,6 @@ describe('useForm hook.', () => { let mockValidator; let mockPrepData; let mockPrepDataToSubmit; - let mockWebSockets; let input; let form; const Child = jest.fn(props => ); @@ -41,7 +41,7 @@ describe('useForm hook.', () => { mockValidator = jest.fn(data => data.field === 'invalidValue' ? {field: 'Error'} : {}); const {getByTestId, container} = render( { + document.addEventListener("mousedown", handleClickOutside); + return () => { + document.removeEventListener("mousedown", handleClickOutside); + }; + }); +} From 6d5cb6a951d6a9f7ea8d4cce8b49c5211991c10c Mon Sep 17 00:00:00 2001 From: Bogdan Bodnar Date: Tue, 17 Dec 2019 14:04:06 +0100 Subject: [PATCH 3/4] Export . --- src/bootstrap/RadioSet.js | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/RadioSet.js b/src/bootstrap/RadioSet.js index 63af8f0..41f85de 100644 --- a/src/bootstrap/RadioSet.js +++ b/src/bootstrap/RadioSet.js @@ -65,7 +65,7 @@ Radio.propTypes = { helpText: PropTypes.string, }; -function Radio({ +export function Radio({ label, id, helpText, ...props }) { return ( diff --git a/src/index.js b/src/index.js index 149a74b..645ca1d 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ export { FileInput } from "bootstrap/FileInput"; export { Input } from "bootstrap/Input"; export { NumberInput } from "bootstrap/NumberInput"; export { PasswordInput } from "bootstrap/PasswordInput"; -export { RadioSet } from "bootstrap/RadioSet"; +export { Radio, RadioSet } from "bootstrap/RadioSet"; export { Select } from "bootstrap/Select"; export { TextInput } from "bootstrap/TextInput"; export { formFieldsSize } from "bootstrap/constants"; From 3d290114fa0ca21e873318227bc2ae9a5c6c64b6 Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Tue, 17 Dec 2019 17:45:55 +0100 Subject: [PATCH 4/4] Changed levels of WS logs --- src/webSockets/WebSockets.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/webSockets/WebSockets.js b/src/webSockets/WebSockets.js index c01407f..6548334 100644 --- a/src/webSockets/WebSockets.js +++ b/src/webSockets/WebSockets.js @@ -25,18 +25,18 @@ export class WebSockets { console.error("WS: Error observed, you aren't logged probably."); window.location.replace(ForisURLs.login); } - console.log(`WS: Error: ${e}`); + console.error(`WS: Error: ${e}`); }; this.ws.onmessage = (e) => { - console.log(`WS: Received Message: ${e.data}`); + console.debug(`WS: Received Message: ${e.data}`); const data = JSON.parse(e.data); this.dispatch(data); }; this.ws.onopen = () => { - console.log("WS: Connection open."); + console.debug("WS: Connection open."); }; this.ws.onclose = () => { - console.log("WS: Connection closed."); + console.debug("WS: Connection closed."); }; // callbacks[module][action] @@ -111,7 +111,7 @@ export class WebSockets { chain = this.callbacks[json.module][json.action]; } catch (error) { if (error instanceof TypeError) { - console.log(`Callback for this message wasn't found:${error.data}`); + console.warn(`Callback for this message wasn't found:${error.data}`); } else throw error; }