From 7975f6405440935b178ca4e205ab518b7ae062a2 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Tue, 19 Jan 2021 16:46:23 +0100 Subject: [PATCH] F #3951: Add settings section (#671) --- src/fireedge/src/client/actions/general.js | 11 ++ .../src/client/apps/provision/theme.js | 17 ++- .../client/components/Cards/DatastoreCard.js | 5 +- .../src/client/components/Cards/HostCard.js | 4 +- .../client/components/Cards/NetworkCard.js | 7 - .../components/Cards/ProvisionTemplateCard.js | 13 +- .../components/Cards/SelectCard/index.js | 10 +- .../components/Cards/SelectCard/styles.js | 52 +++---- .../src/client/components/Cards/WavesCard.js | 79 +++++----- .../src/client/components/DebugLog/message.js | 8 +- .../components/Dialogs/DialogConfirmation.js | 25 +++- .../components/HOC/InternalLayout/styles.js | 2 +- .../src/client/components/HOC/Translate.js | 3 +- .../src/client/components/Header/index.js | 5 +- .../src/client/components/Header/styles.js | 7 +- .../client/components/Sidebar/SidebarLink.js | 3 +- .../src/client/components/Sidebar/index.js | 2 +- .../src/client/components/Sidebar/styles.js | 16 ++- .../src/client/components/Status/Chip.js | 30 ++-- .../Typography/TypographyWithPoint.js | 6 +- .../Widgets/TotalProviders/index.js | 1 - .../src/client/constants/translates.js | 3 + .../src/client/containers/Settings/index.js | 136 +++++++++++++++++- .../client/containers/TestApi/ResponseForm.js | 17 +-- .../src/client/containers/TestApi/index.js | 5 +- src/fireedge/src/client/hooks/useAuth.js | 20 ++- src/fireedge/src/client/hooks/useGeneral.js | 16 ++- .../src/client/providers/muiProvider.js | 21 +-- src/fireedge/src/client/reducers/general.js | 5 +- src/fireedge/src/client/router/provision.js | 18 +-- src/fireedge/src/client/services/one/user.js | 11 ++ .../server/utils/constants/commands/user.js | 36 ++--- 32 files changed, 405 insertions(+), 189 deletions(-) diff --git a/src/fireedge/src/client/actions/general.js b/src/fireedge/src/client/actions/general.js index cd23921ff0..10fc7aa67d 100644 --- a/src/fireedge/src/client/actions/general.js +++ b/src/fireedge/src/client/actions/general.js @@ -1,4 +1,5 @@ const CHANGE_ZONE = 'CHANGE_ZONE' +const CHANGE_THEME_TYPE = 'CHANGE_THEME_TYPE' const CHANGE_LOADING = 'CHANGE_LOADING' const TOGGLE_MENU = 'TOGGLE_MENU' const FIX_MENU = 'FIX_MENU' @@ -9,6 +10,7 @@ const REMOVE_SNACKBAR = 'REMOVE_SNACKBAR' const Actions = { CHANGE_ZONE, + CHANGE_THEME_TYPE, CHANGE_LOADING, TOGGLE_MENU, FIX_MENU, @@ -23,6 +25,15 @@ module.exports = { type: CHANGE_ZONE, payload: { zone } }), + updateTheme: (dispatch, getState) => { + const current = getState() + const currentTheme = current.Authenticated?.theme + const userTheme = current.Authenticated?.user?.TEMPLATE?.FIREEDGE?.THEME ?? 'dark' + + if (['dark', 'light'].includes(userTheme) && currentTheme !== userTheme) { + dispatch(({ type: CHANGE_THEME_TYPE, payload: { theme: userTheme } })) + } + }, changeLoading: isLoading => ({ type: CHANGE_LOADING, payload: { isLoading } diff --git a/src/fireedge/src/client/apps/provision/theme.js b/src/fireedge/src/client/apps/provision/theme.js index 0ebc73e76b..37c785876b 100644 --- a/src/fireedge/src/client/apps/provision/theme.js +++ b/src/fireedge/src/client/apps/provision/theme.js @@ -1,10 +1,15 @@ -export default { +export default (mode = 'dark') => ({ palette: { - type: 'dark', - common: { black: '#000000', white: '#ffffff' }, + type: mode, + common: { + black: '#000000', + white: '#ffffff' + }, background: { - paper: '#2a2d3d', - default: '#222431' + paper: mode === 'dark' ? '#2e3440' : '#ffffff', + // PREV paper: mode === 'dark' ? '#2a2d3d' : '#eceff4', + default: mode === 'dark' ? '#242933' : '#f2f4f8' + // PREV default: mode === 'dark' ? '#222431' : '#d8dee9' }, primary: { light: '#2a2d3d', @@ -28,4 +33,4 @@ export default { main: '#7b7c7e' } } -} +}) diff --git a/src/fireedge/src/client/components/Cards/DatastoreCard.js b/src/fireedge/src/client/components/Cards/DatastoreCard.js index b1f06d25bd..2bd4aaa1d8 100644 --- a/src/fireedge/src/client/components/Cards/DatastoreCard.js +++ b/src/fireedge/src/client/components/Cards/DatastoreCard.js @@ -8,10 +8,10 @@ import SelectCard from 'client/components/Cards/SelectCard' import { StatusBadge, StatusChip } from 'client/components/Status' import Datastore from 'client/constants/datastore' -const useStyles = makeStyles(theme => ({ - card: { backgroundColor: theme.palette.primary.main }, +const useStyles = makeStyles(() => ({ title: { display: 'flex', gap: '0.5rem' } })) + const DatastoreCard = memo( ({ value, isSelected, handleClick, actions }) => { const classes = useStyles() @@ -23,7 +23,6 @@ const DatastoreCard = memo( return ( diff --git a/src/fireedge/src/client/components/Cards/HostCard.js b/src/fireedge/src/client/components/Cards/HostCard.js index e02e49f27d..60a1ce702e 100644 --- a/src/fireedge/src/client/components/Cards/HostCard.js +++ b/src/fireedge/src/client/components/Cards/HostCard.js @@ -8,8 +8,7 @@ import SelectCard from 'client/components/Cards/SelectCard' import { StatusBadge, StatusChip } from 'client/components/Status' import Host from 'client/constants/host' -const useStyles = makeStyles(theme => ({ - card: { backgroundColor: theme.palette.primary.main }, +const useStyles = makeStyles(() => ({ title: { display: 'flex', gap: '0.5rem' } })) @@ -24,7 +23,6 @@ const HostCard = memo( return ( diff --git a/src/fireedge/src/client/components/Cards/NetworkCard.js b/src/fireedge/src/client/components/Cards/NetworkCard.js index 6df213e6ef..30e0aee192 100644 --- a/src/fireedge/src/client/components/Cards/NetworkCard.js +++ b/src/fireedge/src/client/components/Cards/NetworkCard.js @@ -1,23 +1,16 @@ import React, { memo } from 'react' import PropTypes from 'prop-types' -import { makeStyles } from '@material-ui/core' import NetworkIcon from '@material-ui/icons/AccountTree' import SelectCard from 'client/components/Cards/SelectCard' -const useStyles = makeStyles(theme => ({ - card: { backgroundColor: theme.palette.primary.main } -})) - const NetworkCard = memo( ({ value, isSelected, handleClick, actions }) => { const { ID, NAME } = value - const classes = useStyles() return ( } title={NAME} subheader={`#${ID}`} diff --git a/src/fireedge/src/client/components/Cards/ProvisionTemplateCard.js b/src/fireedge/src/client/components/Cards/ProvisionTemplateCard.js index 1ccd8f9b72..3f884e5aec 100644 --- a/src/fireedge/src/client/components/Cards/ProvisionTemplateCard.js +++ b/src/fireedge/src/client/components/Cards/ProvisionTemplateCard.js @@ -5,7 +5,11 @@ import ProvidersIcon from '@material-ui/icons/Public' import SelectCard from 'client/components/Cards/SelectCard' import { isExternalURL } from 'client/utils' -import { PROVIDER_IMAGES_URL, PROVISION_IMAGES_URL } from 'client/constants' +import { + PROVIDER_IMAGES_URL, + PROVISION_IMAGES_URL, + DEFAULT_IMAGE +} from 'client/constants' const ProvisionTemplateCard = React.memo( ({ value, isProvider, isSelected, handleClick }) => { @@ -13,6 +17,10 @@ const ProvisionTemplateCard = React.memo( const { image } = isProvider ? plain : value const IMAGES_URL = isProvider ? PROVIDER_IMAGES_URL : PROVISION_IMAGES_URL + const onError = evt => { + evt.target.src = evt.target.src === DEFAULT_IMAGE ? DEFAULT_IMAGE : '' + } + const imgSource = React.useMemo(() => isExternalURL(image) ? image : `${IMAGES_URL}/${image}` , [image]) @@ -27,7 +35,8 @@ const ProvisionTemplateCard = React.memo( mediaProps={image && { component: 'img', image: imgSource, - draggable: false + draggable: false, + onError }} /> ) diff --git a/src/fireedge/src/client/components/Cards/SelectCard/index.js b/src/fireedge/src/client/components/Cards/SelectCard/index.js index 4e867fc6f2..d7a18f227b 100644 --- a/src/fireedge/src/client/components/Cards/SelectCard/index.js +++ b/src/fireedge/src/client/components/Cards/SelectCard/index.js @@ -28,7 +28,7 @@ const SelectCard = memo(({ observerOff, children }) => { - const classes = selectCardStyles(stylesProps) + const classes = selectCardStyles({ ...stylesProps, isSelected }) const { isNearScreen, fromRef } = useNearScreen({ distance: '100px' }) @@ -40,8 +40,7 @@ const SelectCard = memo(({ {observerOff || isNearScreen ? ( @@ -50,10 +49,7 @@ const SelectCard = memo(({ - + {children} } diff --git a/src/fireedge/src/client/components/Cards/SelectCard/styles.js b/src/fireedge/src/client/components/Cards/SelectCard/styles.js index 82f7f38a99..0a0e61488d 100644 --- a/src/fireedge/src/client/components/Cards/SelectCard/styles.js +++ b/src/fireedge/src/client/components/Cards/SelectCard/styles.js @@ -1,47 +1,49 @@ import { makeStyles } from '@material-ui/core' export default makeStyles(theme => ({ - root: { + root: ({ isSelected }) => ({ height: '100%', - '& $actionArea, & $mediaActionArea, & $media': { - transition: theme.transitions.create( - ['filter', 'background-color'], - { duration: '0.2s' } - ) - } - }, - selected: { - color: theme.palette.secondary.contrastText, - backgroundColor: theme.palette.secondary.main, - '& .badge': { - color: theme.palette.secondary.main, - backgroundColor: theme.palette.secondary.contrastText + transition: theme.transitions.create( + ['background-color', 'box-shadow'], { duration: '0.2s' } + ), + '&:hover': { + boxShadow: theme.shadows['5'] }, - '& $subheader': { color: 'inherit' } - }, + ...(isSelected && { + color: theme.palette.secondary.contrastText, + backgroundColor: theme.palette.secondary.main, + '& .badge': { + color: theme.palette.secondary.main, + backgroundColor: theme.palette.secondary.contrastText + }, + '& $subheader': { color: 'inherit' } + }) + }), actionArea: { height: '100%', - minHeight: ({ minHeight = 140 }) => minHeight, - '& $media': { filter: 'contrast(0) brightness(2)' } + minHeight: ({ minHeight = 140 }) => minHeight }, mediaActionArea: { display: 'flex', height: ({ mediaHeight = 140 }) => mediaHeight, - '& $media': { filter: 'contrast(0) brightness(2)' }, '&:hover': { - backgroundColor: theme.palette.primary.contrastText, + backgroundColor: theme.palette.secondary.contrastText, '& $media': { filter: 'none' } } }, - media: {}, + media: { + transition: theme.transitions.create('filter', { duration: '0.2s' }), + filter: ({ isSelected }) => (theme.palette.type === 'dark' || isSelected) + ? 'contrast(0) brightness(2)' + : 'contrast(0) brightness(0.8)' + }, headerRoot: { alignItems: 'end' }, headerContent: { overflow: 'auto' }, headerAvatar: { display: 'flex', - color: theme.palette.primary.contrastText - }, - header: { - color: theme.palette.primary.contrastText + color: ({ isSelected }) => isSelected + ? theme.palette.secondary.contrastText + : theme.palette.text.primary }, subheader: { overflow: 'hidden', diff --git a/src/fireedge/src/client/components/Cards/WavesCard.js b/src/fireedge/src/client/components/Cards/WavesCard.js index 4609ee8ea7..b95c154798 100644 --- a/src/fireedge/src/client/components/Cards/WavesCard.js +++ b/src/fireedge/src/client/components/Cards/WavesCard.js @@ -2,46 +2,51 @@ import * as React from 'react' import PropTypes from 'prop-types' import clsx from 'clsx' -import { Paper, Typography, makeStyles, lighten } from '@material-ui/core' +import { Paper, Typography, makeStyles, lighten, darken } from '@material-ui/core' import { addOpacityToColor } from 'client/utils' -const useStyles = makeStyles(theme => ({ - root: { - padding: '2em', - position: 'relative', - overflow: 'hidden', - backgroundColor: ({ bgColor }) => bgColor - }, - icon: { - position: 'absolute', - top: 0, - right: 0, - fontSize: '10em', - fill: addOpacityToColor(theme.palette.common.white, 0.2) - }, - wave: { - display: 'block', - position: 'absolute', - opacity: 0.4, - top: '-5%', - left: '50%', - width: 220, - height: 220, - borderRadius: '43%' - }, - wave1: { - backgroundColor: ({ bgColor }) => lighten(bgColor, 0.4), - animation: '$drift 7s infinite linear' - }, - wave2: { - backgroundColor: ({ bgColor }) => lighten(bgColor, 0.6), - animation: '$drift 5s infinite linear' - }, - '@keyframes drift': { - from: { transform: 'rotate(0deg)' }, - to: { transform: 'rotate(360deg)' } +const useStyles = makeStyles(theme => { + const getBackgroundColor = theme.palette.type === 'dark' ? darken : lighten + const getContrastBackgroundColor = theme.palette.type === 'light' ? darken : lighten + + return { + root: { + padding: '2em', + position: 'relative', + overflow: 'hidden', + backgroundColor: ({ bgColor }) => getBackgroundColor(bgColor, 0.3) + }, + icon: { + position: 'absolute', + top: 0, + right: 0, + fontSize: '10em', + fill: addOpacityToColor(theme.palette.common.white, 0.2) + }, + wave: { + display: 'block', + position: 'absolute', + opacity: 0.4, + top: '-5%', + left: '50%', + width: 220, + height: 220, + borderRadius: '43%' + }, + wave1: { + backgroundColor: ({ bgColor }) => getContrastBackgroundColor(bgColor, 0.3), + animation: '$drift 7s infinite linear' + }, + wave2: { + backgroundColor: ({ bgColor }) => getContrastBackgroundColor(bgColor, 0.5), + animation: '$drift 5s infinite linear' + }, + '@keyframes drift': { + from: { transform: 'rotate(0deg)' }, + to: { transform: 'rotate(360deg)' } + } } -})) +}) const WavesCard = React.memo(({ text, value, bgColor, icon: Icon }) => { const classes = useStyles({ bgColor }) diff --git a/src/fireedge/src/client/components/DebugLog/message.js b/src/fireedge/src/client/components/DebugLog/message.js index f1495da479..93966128c1 100644 --- a/src/fireedge/src/client/components/DebugLog/message.js +++ b/src/fireedge/src/client/components/DebugLog/message.js @@ -19,6 +19,7 @@ const useStyles = makeStyles(theme => ({ padding: '0.5em 0', cursor: ({ isMoreThanMaxChars }) => isMoreThanMaxChars ? 'pointer' : 'default', fontFamily: 'monospace', + color: '#fafafa', '&:hover': { background: '#333537' } @@ -30,9 +31,6 @@ const useStyles = makeStyles(theme => ({ time: { minWidth: '220px' }, - message: { - color: '#fafafa' - }, [DEBUG_LEVEL.ERROR]: { borderLeft: `0.3em solid ${theme.palette.error.light}` }, [DEBUG_LEVEL.WARN]: { borderLeft: `0.3em solid ${theme.palette.warning.light}` }, [DEBUG_LEVEL.INFO]: { borderLeft: `0.3em solid ${theme.palette.info.light}` }, @@ -62,9 +60,9 @@ const Message = memo(({ timestamp, severity, message }) => {
{timestamp}
{(isCollapsed && isMoreThanMaxChars) ? ( -
{`${message?.slice(0, MAX_CHARS)}…`}
+
{`${message?.slice(0, MAX_CHARS)}…`}
) : ( -
+
)}
) diff --git a/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js b/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js index 1b24b20c3a..491a0cbe02 100644 --- a/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js +++ b/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js @@ -8,13 +8,26 @@ import { DialogTitle, DialogContent, DialogActions, - Typography + Typography, + makeStyles } from '@material-ui/core' import SubmitButton from 'client/components/FormControl/SubmitButton' import { Tr } from 'client/components/HOC' import { T } from 'client/constants' +const useStyles = makeStyles(theme => ({ + root: { + backgroundColor: theme.palette.background.default, + width: '80%', + height: '80%', + [theme.breakpoints.only('xs')]: { + width: '100%', + height: '100%' + } + } +})) + const DialogConfirmation = memo( ({ open, @@ -28,6 +41,7 @@ const DialogConfirmation = memo( handleEntering, children }) => { + const classes = useStyles() const isMobile = useMediaQuery(theme => theme.breakpoints.only('xs')) return ( @@ -37,12 +51,9 @@ const DialogConfirmation = memo( open={open} onClose={handleCancel} maxWidth='lg' - scroll="paper" - PaperProps={{ - style: { - height: isMobile ? '100%' : '80%', - width: isMobile ? '100%' : '80%' - } + scroll='paper' + classes={{ + paper: classes.root }} > diff --git a/src/fireedge/src/client/components/HOC/InternalLayout/styles.js b/src/fireedge/src/client/components/HOC/InternalLayout/styles.js index 314affcc60..118ea5fc19 100644 --- a/src/fireedge/src/client/components/HOC/InternalLayout/styles.js +++ b/src/fireedge/src/client/components/HOC/InternalLayout/styles.js @@ -34,7 +34,7 @@ export default makeStyles(theme => ({ } }, scrollable: { - backgroundColor: theme.palette.primary.main, + backgroundColor: theme.palette.background.default, paddingTop: theme.spacing(2), paddingBottom: theme.spacing(2), height: '100%', diff --git a/src/fireedge/src/client/components/HOC/Translate.js b/src/fireedge/src/client/components/HOC/Translate.js index 9388cb40d4..b7e5f602e8 100644 --- a/src/fireedge/src/client/components/HOC/Translate.js +++ b/src/fireedge/src/client/components/HOC/Translate.js @@ -103,7 +103,7 @@ const Tr = (str = '') => { return translate(key, valuesTr) } -const SelectTranslate = () => { +const SelectTranslate = props => { const context = useContext(TranslateContext) const languages = Array.isArray(root?.langs) ? root?.langs : [] @@ -120,6 +120,7 @@ const SelectTranslate = () => { fullWidth onChange={e => handleChange(e, context.changeLang)} defaultValue={context.lang} + {...props} > {languages.map(({ key, value }) => (