mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-06-15 13:36:35 +02:00
Set modules.
This commit is contained in:
111
src/api/hooks.js
111
src/api/hooks.js
@ -6,8 +6,9 @@
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import {useCallback, useReducer} from "react";
|
||||
import {ForisURLs} from './constants';
|
||||
import { useCallback, useReducer } from "react";
|
||||
|
||||
import { ForisUrls } from "forisUrls";
|
||||
|
||||
|
||||
const POST_HEADERS = {
|
||||
@ -42,29 +43,29 @@ const API_ACTIONS = {
|
||||
|
||||
const APIGetReducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case API_ACTIONS.INIT:
|
||||
return {
|
||||
...state,
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
};
|
||||
case API_ACTIONS.SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
data: action.payload,
|
||||
};
|
||||
case API_ACTIONS.FAILURE:
|
||||
if (action.status === 403) window.location.assign(ForisURLs.login);
|
||||
return {
|
||||
...state,
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
data: action.payload,
|
||||
};
|
||||
default:
|
||||
throw new Error();
|
||||
case API_ACTIONS.INIT:
|
||||
return {
|
||||
...state,
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
};
|
||||
case API_ACTIONS.SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
data: action.payload,
|
||||
};
|
||||
case API_ACTIONS.FAILURE:
|
||||
if (action.status === 403) window.location.assign(ForisUrls.login);
|
||||
return {
|
||||
...state,
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
data: action.payload,
|
||||
};
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
};
|
||||
|
||||
@ -81,12 +82,12 @@ export function useAPIGet(url) {
|
||||
});
|
||||
|
||||
const get = useCallback(async () => {
|
||||
dispatch({type: API_ACTIONS.INIT});
|
||||
dispatch({ type: API_ACTIONS.INIT });
|
||||
try {
|
||||
const result = await axios.get(url, {
|
||||
timeout: TIMEOUT,
|
||||
});
|
||||
dispatch({type: API_ACTIONS.SUCCESS, payload: result.data});
|
||||
dispatch({ type: API_ACTIONS.SUCCESS, payload: result.data });
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: API_ACTIONS.FAILURE,
|
||||
@ -101,32 +102,32 @@ export function useAPIGet(url) {
|
||||
|
||||
const APIPostReducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case API_ACTIONS.INIT:
|
||||
return {
|
||||
...state,
|
||||
isSending: true,
|
||||
isError: false,
|
||||
isSuccess: false,
|
||||
};
|
||||
case API_ACTIONS.SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
isSending: false,
|
||||
isError: false,
|
||||
isSuccess: true,
|
||||
data: action.payload,
|
||||
};
|
||||
case API_ACTIONS.FAILURE:
|
||||
if (action.status === 403) window.location.assign(ForisURLs.login);
|
||||
return {
|
||||
...state,
|
||||
isSending: false,
|
||||
isError: true,
|
||||
isSuccess: false,
|
||||
data: action.payload,
|
||||
};
|
||||
default:
|
||||
throw new Error();
|
||||
case API_ACTIONS.INIT:
|
||||
return {
|
||||
...state,
|
||||
isSending: true,
|
||||
isError: false,
|
||||
isSuccess: false,
|
||||
};
|
||||
case API_ACTIONS.SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
isSending: false,
|
||||
isError: false,
|
||||
isSuccess: true,
|
||||
data: action.payload,
|
||||
};
|
||||
case API_ACTIONS.FAILURE:
|
||||
if (action.status === 403) window.location.assign(ForisUrls.login);
|
||||
return {
|
||||
...state,
|
||||
isSending: false,
|
||||
isError: true,
|
||||
isSuccess: false,
|
||||
data: action.payload,
|
||||
};
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
};
|
||||
|
||||
@ -139,13 +140,13 @@ export function useAPIPost(url) {
|
||||
});
|
||||
|
||||
const post = async (data) => {
|
||||
dispatch({type: API_ACTIONS.INIT});
|
||||
dispatch({ type: API_ACTIONS.INIT });
|
||||
try {
|
||||
const result = await axios.post(url, data, {
|
||||
timeout: TIMEOUT,
|
||||
headers: POST_HEADERS,
|
||||
});
|
||||
dispatch({type: API_ACTIONS.SUCCESS, payload: result.data});
|
||||
dispatch({ type: API_ACTIONS.SUCCESS, payload: result.data });
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: API_ACTIONS.FAILURE,
|
||||
|
@ -1 +0,0 @@
|
||||
export * from "./hooks";
|
@ -22,7 +22,7 @@ Alert.propTypes = {
|
||||
onDismiss: PropTypes.func
|
||||
};
|
||||
|
||||
export default function Alert({type, message, onDismiss, children}) {
|
||||
export function Alert({type, message, onDismiss, children}) {
|
||||
return <div className={`alert alert-dismissible alert-${type}`}>
|
||||
{onDismiss ? <button type="button" className="close" onClick={onDismiss}>×</button> : false}
|
||||
{message}
|
@ -29,7 +29,7 @@ Button.propTypes = {
|
||||
]).isRequired
|
||||
};
|
||||
|
||||
export default function Button({className, loading, forisFormSize, children, ...props}) {
|
||||
export function Button({className, loading, forisFormSize, children, ...props}) {
|
||||
className = className ? 'btn ' + className : 'btn btn-primary ';
|
||||
if (forisFormSize)
|
||||
className += SIZE_CLASS + SIZE_CLASS_SM;
|
@ -7,7 +7,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {useUID} from 'react-uid/dist/es5/index';
|
||||
import {useUID} from 'react-uid';
|
||||
|
||||
import {formFieldsSize} from './constants';
|
||||
|
||||
@ -27,7 +27,7 @@ CheckBox.defaultProps = {
|
||||
disabled: false
|
||||
};
|
||||
|
||||
export default function CheckBox({label, helpText, useDefaultSize, disabled, ...props}) {
|
||||
export function CheckBox({label, helpText, useDefaultSize, disabled, ...props}) {
|
||||
const uid = useUID();
|
||||
return <div className={useDefaultSize ? formFieldsSize : ""} style={{marginBottom: '1rem'}}>
|
||||
<div className='custom-control custom-checkbox' style={{marginBottom: '0'}}>
|
@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
|
||||
import Datetime from 'react-datetime/DateTime';
|
||||
import moment from 'moment/moment';
|
||||
|
||||
import Input from './Input';
|
||||
import {Input} from './Input';
|
||||
|
||||
DataTimeInput.propTypes = {
|
||||
/** Field label. */
|
||||
@ -35,7 +35,7 @@ DataTimeInput.propTypes = {
|
||||
const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD';
|
||||
const DEFAULT_TIME_FORMAT = 'HH:mm:ss';
|
||||
|
||||
export default function DataTimeInput({value, onChange, isValidDate, dateFormat, timeFormat, children, ...props}) {
|
||||
export function DataTimeInput({value, onChange, isValidDate, dateFormat, timeFormat, children, ...props}) {
|
||||
function renderInput(datetimeProps) {
|
||||
return <Input
|
||||
{...props}
|
@ -7,11 +7,10 @@
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Input from './Input';
|
||||
import {Input} from './Input';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const EmailInput = ({...props}) => <Input type="email" {...props}/>;
|
||||
|
||||
export const EmailInput = ({...props}) => <Input type="email" {...props}/>;
|
||||
|
||||
EmailInput.propTypes = {
|
||||
/** Field label. */
|
||||
@ -23,5 +22,3 @@ EmailInput.propTypes = {
|
||||
/** Email value. */
|
||||
value: PropTypes.string,
|
||||
};
|
||||
|
||||
export default EmailInput;
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {useUID} from 'react-uid/dist/es5/index';
|
||||
import {useUID} from 'react-uid';
|
||||
import {formFieldsSize} from './constants';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
@ -23,7 +23,7 @@ Input.propTypes = {
|
||||
}
|
||||
|
||||
/** Base bootstrap input component. */
|
||||
export default function Input({type, label, helpText, error, className, children, ...props}) {
|
||||
export function Input({type, label, helpText, error, className, children, ...props}) {
|
||||
const uid = useUID();
|
||||
const inputClassName = `form-control ${className ? className : ''} ${(error ? 'is-invalid' : '')}`.trim();
|
||||
return <div className={formFieldsSize}>
|
@ -7,7 +7,8 @@
|
||||
|
||||
import React, {useEffect, useRef} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Portal from 'utils/Portal';
|
||||
|
||||
import {Portal} from 'utils/Portal';
|
||||
|
||||
Modal.propTypes = {
|
||||
/** Is modal shown value */
|
@ -7,10 +7,10 @@
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Input from './Input';
|
||||
import {Input} from './Input';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const NumberInput = ({...props}) => <Input type="number" {...props}/>;
|
||||
export const NumberInput = ({...props}) => <Input type="number" {...props}/>;
|
||||
|
||||
NumberInput.propTypes = {
|
||||
/** Field label. */
|
||||
@ -25,5 +25,3 @@ NumberInput.propTypes = {
|
||||
PropTypes.number,
|
||||
]),
|
||||
};
|
||||
|
||||
export default NumberInput;
|
@ -8,7 +8,7 @@
|
||||
import React, {useState} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Input from './Input';
|
||||
import {Input} from './Input';
|
||||
|
||||
PasswordInput.propTypes = {
|
||||
/** Field label. */
|
||||
@ -23,7 +23,7 @@ PasswordInput.propTypes = {
|
||||
withEye: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default function PasswordInput({withEye, ...props}) {
|
||||
export function PasswordInput({withEye, ...props}) {
|
||||
const [isHidden, setHidden] = useState(true);
|
||||
return <Input
|
||||
type={withEye ? isHidden ? 'password' : 'text' : 'password'}
|
@ -7,7 +7,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {useUID} from 'react-uid/dist/es5/index';
|
||||
import {useUID} from 'react-uid';
|
||||
|
||||
import {formFieldsSize} from './constants';
|
||||
|
||||
@ -30,7 +30,7 @@ RadioSet.propTypes = {
|
||||
helpText: PropTypes.string,
|
||||
};
|
||||
|
||||
export default function RadioSet({name, label, choices, value, helpText, ...props}) {
|
||||
export function RadioSet({name, label, choices, value, helpText, ...props}) {
|
||||
const uid = useUID();
|
||||
const radios = choices.map((choice, key) =>
|
||||
<Radio
|
@ -7,7 +7,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {useUID} from 'react-uid/dist/es5/index';
|
||||
import {useUID} from 'react-uid';
|
||||
|
||||
|
||||
Select.propTypes = {
|
||||
@ -24,7 +24,7 @@ Select.propTypes = {
|
||||
helpText: PropTypes.string,
|
||||
};
|
||||
|
||||
export default function Select({label, choices, helpText, ...props}) {
|
||||
export function Select({label, choices, helpText, ...props}) {
|
||||
const uid = useUID();
|
||||
|
||||
const options = Object.keys(choices).map(
|
@ -23,7 +23,7 @@ Spinner.defaultProps = {
|
||||
fullScreen: false,
|
||||
};
|
||||
|
||||
export default function Spinner({fullScreen, children, className, ...props}) {
|
||||
export function Spinner({fullScreen, children, className, ...props}) {
|
||||
if (!fullScreen) {
|
||||
return <div className={'spinner-wrapper ' + (className ? className : '')} {...props}>
|
||||
<SpinnerElement>{children}</SpinnerElement>
|
@ -8,10 +8,10 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Input from './Input';
|
||||
import {Input} from './Input';
|
||||
|
||||
|
||||
const TextInput = ({...props}) => <Input type="text" {...props}/>;
|
||||
export const TextInput = ({...props}) => <Input type="text" {...props}/>;
|
||||
|
||||
|
||||
TextInput.propTypes = {
|
||||
@ -22,5 +22,3 @@ TextInput.propTypes = {
|
||||
/** Help text message. */
|
||||
helpText: PropTypes.string,
|
||||
};
|
||||
|
||||
export default TextInput;
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {render} from 'customTestRender';
|
||||
|
||||
import Button from '../components/Button'
|
||||
import Button from '../Button'
|
||||
|
||||
describe('<Button />', () => {
|
||||
it('Render button correctly', () => {
|
||||
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {render} from 'customTestRender';
|
||||
|
||||
import Checkbox from '../components/Checkbox'
|
||||
import Checkbox from '../Checkbox'
|
||||
|
||||
describe('<Checkbox/>', () => {
|
||||
it('Render checkbox', () => {
|
||||
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {render} from 'customTestRender';
|
||||
|
||||
import NumberInput from '../components/NumberInput';
|
||||
import NumberInput from '../NumberInput';
|
||||
|
||||
|
||||
describe('<NumberInput/>', () => {
|
||||
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {render} from 'customTestRender';
|
||||
|
||||
import PasswordInput from '../components/PasswordInput';
|
||||
import PasswordInput from '../PasswordInput';
|
||||
|
||||
describe('<PasswordInput/>', () => {
|
||||
it('Render password input', () => {
|
||||
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {render} from 'customTestRender';
|
||||
|
||||
import RadioSet from '../components/RadioSet';
|
||||
import RadioSet from '../RadioSet';
|
||||
|
||||
const TEST_CHOICES = [
|
||||
{label: 'label', value: 'value'},
|
||||
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {fireEvent, getByDisplayValue, getByText, render} from 'customTestRender';
|
||||
|
||||
import Select from '../components/Select';
|
||||
import Select from '../Select';
|
||||
|
||||
const TEST_CHOICES = {
|
||||
'1': 'one',
|
||||
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||
|
||||
import {render} from 'customTestRender';
|
||||
|
||||
import TextInput from '../components/TextInput';
|
||||
import TextInput from '../TextInput';
|
||||
|
||||
describe('<TextInput/>', () => {
|
||||
it('Render text input', () => {
|
||||
|
@ -1,31 +0,0 @@
|
||||
import * as Alert from "./components/Alert";
|
||||
import * as Button from "./components/Button";
|
||||
import * as Checkbox from "./components/Checkbox";
|
||||
import * as constants from "./components/constants";
|
||||
import * as DataTimeInput from "./components/DataTimeInput";
|
||||
import * as EmailInput from "./components/EmailInput";
|
||||
import * as Input from "./components/Input";
|
||||
import * as Modal from "./components/Modal";
|
||||
import * as NumberInput from "./components/NumberInput";
|
||||
import * as PasswordInput from "./components/PasswordInput";
|
||||
import * as RadioSet from "./components/RadioSet";
|
||||
import * as Select from "./components/Select";
|
||||
import * as Spinner from "./components/Spinner";
|
||||
import * as TextInput from "./components/TextInput";
|
||||
|
||||
export {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
constants,
|
||||
DataTimeInput,
|
||||
EmailInput,
|
||||
Input,
|
||||
Modal,
|
||||
NumberInput,
|
||||
PasswordInput,
|
||||
RadioSet,
|
||||
Select,
|
||||
Spinner,
|
||||
TextInput,
|
||||
}
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
export const REFORIS_URL_PREFIX = process.env.LIGHTTPD ? "/reforis" : "";
|
||||
|
||||
export const ForisURLs = {
|
@ -9,11 +9,11 @@ import React, {useEffect, useState} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {Prompt} from 'react-router';
|
||||
|
||||
import Spinner from 'bootstrap/components/Spinner';
|
||||
import {useAPIPost} from 'api';
|
||||
import {Spinner} from 'bootstrap/Spinner';
|
||||
import {useAPIPost} from 'api/hooks';
|
||||
|
||||
import {useForisModule, useForm} from '../hooks';
|
||||
import SubmitButton, {STATES as SUBMIT_BUTTON_STATES} from './SubmitButton';
|
||||
import {STATES as SUBMIT_BUTTON_STATES, SubmitButton} from './SubmitButton';
|
||||
import {FailAlert, SuccessAlert} from './alerts';
|
||||
|
||||
ForisForm.propTypes = {
|
||||
@ -57,17 +57,17 @@ ForisForm.defaultProps = {
|
||||
};
|
||||
|
||||
/** Serves as HOC for all foris forms components. */
|
||||
export default function ForisForm({
|
||||
ws,
|
||||
forisConfig,
|
||||
prepData,
|
||||
prepDataToSubmit,
|
||||
postCallback,
|
||||
validator,
|
||||
disabled,
|
||||
onSubmitOverridden,
|
||||
children
|
||||
}) {
|
||||
export function ForisForm({
|
||||
ws,
|
||||
forisConfig,
|
||||
prepData,
|
||||
prepDataToSubmit,
|
||||
postCallback,
|
||||
validator,
|
||||
disabled,
|
||||
onSubmitOverridden,
|
||||
children
|
||||
}) {
|
||||
const [formState, onFormChangeHandler, resetFormData] = useForm(validator, prepData);
|
||||
|
||||
const [forisModuleState] = useForisModule(ws, forisConfig);
|
||||
|
@ -8,7 +8,7 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Button from 'bootstrap/components/Button';
|
||||
import {Button} from 'bootstrap/Button';
|
||||
|
||||
export const STATES = {
|
||||
READY: 1,
|
||||
@ -21,7 +21,7 @@ SubmitButton.propTypes = {
|
||||
state: PropTypes.oneOf(Object.keys(STATES).map(key => STATES[key]))
|
||||
};
|
||||
|
||||
export default function SubmitButton({disabled, state, ...props}) {
|
||||
export function SubmitButton({disabled, state, ...props}) {
|
||||
const disableSubmitButton = disabled || state !== STATES.READY;
|
||||
const loadingSubmitButton = state !== STATES.READY;
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Alert from 'bootstrap/components/Alert';
|
||||
import Portal from 'utils/Portal';
|
||||
import {Alert} from 'bootstrap/Alert';
|
||||
import {Portal} from 'utils/Portal';
|
||||
|
||||
SuccessAlert.propTypes = {
|
||||
onDismiss: PropTypes.func.isRequired,
|
||||
|
@ -9,7 +9,7 @@ import {useCallback, useEffect, useReducer} from 'react';
|
||||
import update from 'immutability-helper';
|
||||
|
||||
import {useAPIGet} from 'api/hooks';
|
||||
import useWSForisModule from 'webSockets/hooks';
|
||||
import {useWSForisModule} from 'webSockets/hooks';
|
||||
|
||||
|
||||
export function useForm(validator, prepData) {
|
||||
|
@ -1,5 +0,0 @@
|
||||
import * as ForisForm from "./components/ForisForm";
|
||||
import * as SubmitButton from "./components/SubmitButton";
|
||||
import * as hooks from "./hooks";
|
||||
|
||||
export {ForisForm, SubmitButton, hooks}
|
61
src/index.js
61
src/index.js
@ -1,16 +1,51 @@
|
||||
import * as api from './api';
|
||||
import * as bootstrap from './bootstrap';
|
||||
import * as form from './form';
|
||||
import * as testUtils from './testUtils';
|
||||
import * as validations from './validations';
|
||||
//API
|
||||
export {useAPIGet, useAPIPost} from "./api/hooks";
|
||||
|
||||
import {Portal} from './utils';
|
||||
// Bootstrap
|
||||
export {Alert} from "bootstrap/Alert";
|
||||
export {Button} from "bootstrap/Button";
|
||||
export {CheckBox} from "bootstrap/Checkbox";
|
||||
export {formFieldsSize} from "bootstrap/constants";
|
||||
export {DataTimeInput} from "bootstrap/DataTimeInput";
|
||||
export {EmailInput} from "bootstrap/EmailInput";
|
||||
export {Input} from "bootstrap/Input";
|
||||
export {Modal, ModalBody, ModalFooter, ModalHeader} from "bootstrap/Modal";
|
||||
export {NumberInput} from "bootstrap/NumberInput";
|
||||
export {PasswordInput} from "bootstrap/PasswordInput";
|
||||
export {RadioSet} from "bootstrap/RadioSet";
|
||||
export {Select} from "bootstrap/Select";
|
||||
export {Spinner, SpinnerElement} from "bootstrap/Spinner";
|
||||
export {TextInput} from "bootstrap/TextInput";
|
||||
|
||||
// Form
|
||||
export {ForisForm} from "form/components/ForisForm";
|
||||
export {SubmitButton, STATES as SUBMIT_BUTTON_STATES} from "form/components/SubmitButton";
|
||||
export {useForisModule, useForm} from "form/hooks";
|
||||
|
||||
// // Test Utils
|
||||
export {render} from "testUtils/customTestRender";
|
||||
export {mockedWS} from "testUtils/mockWS";
|
||||
export {setupGlobals} from "testUtils/setupGlobals";
|
||||
|
||||
|
||||
// WebSockets
|
||||
export {useWSForisModule} from "webSockets/hooks";
|
||||
export {WebSockets} from "webSockets/WebSockets";
|
||||
|
||||
|
||||
// Utils
|
||||
export {Portal} from "utils/Portal";
|
||||
|
||||
// Foris URL
|
||||
export {ForisURLs, REFORIS_URL_PREFIX} from "./forisUrls"
|
||||
|
||||
// Validation
|
||||
export {
|
||||
api,
|
||||
bootstrap,
|
||||
form,
|
||||
testUtils,
|
||||
validations,
|
||||
Portal,
|
||||
}
|
||||
validateIPv4Address,
|
||||
validateIPv6Address,
|
||||
validateIPv6Prefix,
|
||||
validateDomain,
|
||||
validateDUID,
|
||||
validateMAC,
|
||||
validateMultipleEmails,
|
||||
} from "validations"
|
||||
|
@ -1,11 +0,0 @@
|
||||
import * as customTestRender from "./customTestRender";
|
||||
import * as mockWS from "./mockWS";
|
||||
import * as setupGlobals from "./setupGlobals";
|
||||
import * as setupTest from "./setupTest";
|
||||
|
||||
export {
|
||||
customTestRender,
|
||||
mockWS,
|
||||
setupGlobals,
|
||||
setupTest,
|
||||
}
|
@ -6,6 +6,9 @@
|
||||
*/
|
||||
|
||||
// Fake babel (gettext) used for docs
|
||||
global._ = str => str;
|
||||
global.babel = {format: (str) => str};
|
||||
global.ForisTranslations = {};
|
||||
|
||||
export function setupGlobals() {
|
||||
global._ = str => str;
|
||||
global.babel = {format: (str) => str};
|
||||
global.ForisTranslations = {};
|
||||
}
|
||||
|
@ -5,33 +5,28 @@
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
import mockAxios from 'jest-mock-axios';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
export function setUpTest() {
|
||||
const mockAxios = require('jest-mock-axios');
|
||||
const moment = require('moment-timezone');
|
||||
// Setup axios cleanup
|
||||
global.afterEach(() => {
|
||||
mockAxios.reset();
|
||||
});
|
||||
|
||||
// Setup axios cleanup
|
||||
global.afterEach(() => {
|
||||
mockAxios.reset();
|
||||
});
|
||||
|
||||
// Mock babel (gettext)
|
||||
window._ = str => str;
|
||||
window.babel = {format: (str) => str};
|
||||
window.ForisTranslations = {};
|
||||
|
||||
// Mock scrollIntoView
|
||||
window.HTMLElement.prototype.scrollIntoView = () => {
|
||||
};
|
||||
|
||||
jest.doMock('moment', () => {
|
||||
moment.tz.setDefault('UTC');
|
||||
return moment;
|
||||
});
|
||||
|
||||
Date.now = jest.fn(() => new Date(Date.UTC(2019, 1, 1, 12, 13, 14)).valueOf());
|
||||
}
|
||||
// Mock babel (gettext)
|
||||
global._ = str => str;
|
||||
global.babel = {format: (str) => str};
|
||||
global.ForisTranslations = {};
|
||||
|
||||
// Mock scrollIntoView
|
||||
global.HTMLElement.prototype.scrollIntoView = () => {
|
||||
};
|
||||
|
||||
jest.doMock('moment', () => {
|
||||
moment.tz.setDefault('UTC');
|
||||
return moment;
|
||||
});
|
||||
|
||||
Date.now = jest.fn(() => new Date(Date.UTC(2019, 1, 1, 12, 13, 14)).valueOf());
|
||||
|
||||
jest.doMock("utils/vfs_fonts", () => ({}));
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
export default function Portal({containerId, children}) {
|
||||
export function Portal({containerId, children}) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (container)
|
||||
return ReactDOM.createPortal(children, container);
|
||||
|
@ -1,3 +0,0 @@
|
||||
import Portal from './Portal';
|
||||
|
||||
export {Portal}
|
@ -5,9 +5,7 @@
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
/* eslint no-console: "off" */
|
||||
|
||||
import { ForisURLs } from "./constants";
|
||||
import { ForisUrls } from "forisUrls";
|
||||
|
||||
const PROTOCOL = window.location.protocol === "http:" ? "ws" : "wss";
|
||||
|
||||
@ -17,13 +15,13 @@ const URL = process.env.LIGHTTPD
|
||||
|
||||
const WAITING_FOR_CONNECTION_TIMEOUT = 500;
|
||||
|
||||
export default class WebSockets {
|
||||
export class WebSockets {
|
||||
constructor() {
|
||||
this.ws = new WebSocket(URL);
|
||||
this.ws.onerror = (e) => {
|
||||
if (window.location.pathname !== ForisURLs.login) {
|
||||
if (window.location.pathname !== ForisUrls.login) {
|
||||
console.error("WS: Error observed, you aren't logged probably.");
|
||||
window.location.replace(ForisURLs.login);
|
||||
window.location.replace(ForisUrls.login);
|
||||
}
|
||||
console.log(`WS: Error: ${e}`);
|
||||
};
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function useWSForisModule(ws, module, action = "update_settings") {
|
||||
export function useWSForisModule(ws, module, action = "update_settings") {
|
||||
const [data, setData] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
|
Reference in New Issue
Block a user