From 7c0bb127999794a197f8423dc53e089c0813263c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 4 Jun 2020 15:00:16 +0200 Subject: [PATCH] fix: modal for variants --- frontend/src/__mocks__/react-modal.js | 12 + .../update-variant-component-test.jsx.snap | 486 ------------------ .../component/feature/variant/add-variant.jsx | 190 ++++--- .../feature/variant/override-config.jsx | 4 +- frontend/webpack.config.js | 1 + 5 files changed, 106 insertions(+), 587 deletions(-) create mode 100644 frontend/src/__mocks__/react-modal.js diff --git a/frontend/src/__mocks__/react-modal.js b/frontend/src/__mocks__/react-modal.js new file mode 100644 index 0000000000..cabed1fb38 --- /dev/null +++ b/frontend/src/__mocks__/react-modal.js @@ -0,0 +1,12 @@ +// __mocks__/react-modal.js +const Modal = require('react-modal'); + +const oldFn = Modal.setAppElement; +Modal.setAppElement = element => { + if (element === '#app') { + // otherwise it will throw aria warnings. + return oldFn(document.createElement('div')); + } + oldFn(element); +}; +module.exports = Modal; diff --git a/frontend/src/component/feature/variant/__tests__/__snapshots__/update-variant-component-test.jsx.snap b/frontend/src/component/feature/variant/__tests__/__snapshots__/update-variant-component-test.jsx.snap index bc610fa8d0..e5f09f8c06 100644 --- a/frontend/src/component/feature/variant/__tests__/__snapshots__/update-variant-component-test.jsx.snap +++ b/frontend/src/component/feature/variant/__tests__/__snapshots__/update-variant-component-test.jsx.snap @@ -151,168 +151,6 @@ exports[`renders correctly with with variants 1`] = ` Add variant

-
- - - -

- -
-
- - Passed to the variant object. -
- Can be anything (json, value, csv) - - } - > -

- - Payload - - -

- - - -
- - -
-
- - - -
- - - Add override - - -
- - - Save - - - Cancel - - -
-
`; @@ -370,168 +208,6 @@ exports[`renders correctly with without variants 1`] = ` Add variant

-
- - - -

- -
-
- - Passed to the variant object. -
- Can be anything (json, value, csv) - - } - > -

- - Payload - - -

- - - -
- - -
-
- - - -
- - - Add override - - -
- - - Save - - - Cancel - - -
-
`; @@ -580,167 +256,5 @@ exports[`renders correctly with without variants and no permissions 1`] = `
-
- - - -

- -
-
- - Passed to the variant object. -
- Can be anything (json, value, csv) - - } - > -

- - Payload - - -

- - - -
- - -
-
- - - -
- - - Add override - - -
- - - Save - - - Cancel - - -
-
`; diff --git a/frontend/src/component/feature/variant/add-variant.jsx b/frontend/src/component/feature/variant/add-variant.jsx index 61653e2d7a..bf63b306c8 100644 --- a/frontend/src/component/feature/variant/add-variant.jsx +++ b/frontend/src/component/feature/variant/add-variant.jsx @@ -1,22 +1,35 @@ import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; -import { - Button, - Textfield, - Dialog, - DialogTitle, - DialogContent, - DialogActions, - Grid, - Cell, - Tooltip, - Icon, -} from 'react-mdl'; +import Modal from 'react-modal'; +import { Button, Textfield, DialogActions, Grid, Cell, Icon } from 'react-mdl'; import MySelect from '../../common/select'; import { trim } from '../form/util'; -import styles from './variant.scss'; import OverrideConfig from './override-config'; +Modal.setAppElement('#app'); + +const customStyles = { + overlay: { + position: 'absolute', + top: 0, + left: 0, + right: 0, + bottom: 0, + backgroundColor: 'rgba(0, 0, 0, 0.25)', + zIndex: 5, + }, + content: { + width: '500px', + maxWidth: '90%', + margin: '0', + top: '50%', + left: '50%', + right: 'auto', + bottom: 'auto', + transform: 'translate(-50%, -50%)', + }, +}; + const payloadOptions = [ { key: 'string', label: 'string' }, { key: 'json', label: 'json' }, @@ -55,6 +68,7 @@ function AddVariant({ showDialog, closeDialog, save, validateName, editVariant, }, [editVariant]); const setName = e => { + e.preventDefault(); setData({ ...data, [e.target.name]: trim(e.target.value), @@ -139,92 +153,70 @@ function AddVariant({ showDialog, closeDialog, save, validateName, editVariant, }; return ( -
- - {title} + +

{title}

- -

{error.general}

- -
-
- - Passed to the variant object.
- Can be anything (json, value, csv) - - } - > -

- Payload - -

-
- - - - - - - - - {overrides.length > 0 ? ( - - Here you can specify which users that
- should get this variant. - - } - > -

- Overrides - -

-
- ) : ( - undefined - )} + +

{error.general}

+ +
+
+

+ Payload + +

+ + + + + + + + + {overrides.length > 0 ? ( +

+ Overrides + +

+ ) : ( + undefined + )} - - - Add override - -
+ + + Add override + -
-
+ + ); } diff --git a/frontend/src/component/feature/variant/override-config.jsx b/frontend/src/component/feature/variant/override-config.jsx index a775f10cf3..40c05b31ed 100644 --- a/frontend/src/component/feature/variant/override-config.jsx +++ b/frontend/src/component/feature/variant/override-config.jsx @@ -35,8 +35,8 @@ function OverrideConfig({ overrides, updateOverrideType, updateOverrideValues, r updateValues={updateValues(i)} /> - - + + )); diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index 274c8dc0a4..791db14ef1 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -122,5 +122,6 @@ module.exports = { }, }, port: process.env.PORT || 3000, + host: '0.0.0.0', }, };