-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1764 from RafaelTaranto/backport/machine-rates
LAM-481 backport: machine rates
- Loading branch information
Showing
9 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const _ = require('lodash/fp') | ||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader') | ||
|
||
exports.up = function (next) { | ||
const newConfig = {} | ||
return loadLatest() | ||
.then(({ config }) => { | ||
if (!_.isNil(config.machineScreens_rates_active)) return | ||
newConfig[`machineScreens_rates_active`] = true | ||
return saveConfig(newConfig) | ||
}) | ||
.then(next) | ||
.catch(err => { | ||
return next(err) | ||
}) | ||
} | ||
|
||
module.exports.down = function (next) { | ||
next() | ||
} |
80 changes: 80 additions & 0 deletions
80
new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useQuery, useMutation } from '@apollo/react-hooks' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
import gql from 'graphql-tag' | ||
import * as R from 'ramda' | ||
import React, { memo } from 'react' | ||
|
||
import { Switch } from 'src/components/inputs' | ||
import { H4, P, Label2 } from 'src/components/typography' | ||
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' | ||
|
||
import { global } from './OperatorInfo.styles' | ||
|
||
const useStyles = makeStyles(global) | ||
|
||
const GET_CONFIG = gql` | ||
query getData { | ||
config | ||
} | ||
` | ||
|
||
const SAVE_CONFIG = gql` | ||
mutation Save($config: JSONObject) { | ||
saveConfig(config: $config) | ||
} | ||
` | ||
|
||
const MachineScreens = memo(({ wizard }) => { | ||
const classes = useStyles() | ||
|
||
const { data } = useQuery(GET_CONFIG) | ||
|
||
const [saveConfig] = useMutation(SAVE_CONFIG, { | ||
refetchQueries: () => ['getData'] | ||
}) | ||
|
||
const machineScreensConfig = | ||
data?.config && fromNamespace(namespaces.MACHINE_SCREENS, data.config) | ||
|
||
const ratesScreenConfig = | ||
data?.config && | ||
R.compose( | ||
fromNamespace('rates'), | ||
fromNamespace(namespaces.MACHINE_SCREENS) | ||
)(data.config) | ||
|
||
if (!machineScreensConfig) return null | ||
|
||
return ( | ||
<> | ||
<div className={classes.header}> | ||
<H4>Rates screen</H4> | ||
</div> | ||
<div className={classes.switchRow}> | ||
<P>Enable rates screen</P> | ||
<div className={classes.switch}> | ||
<Switch | ||
checked={ratesScreenConfig.active} | ||
onChange={event => | ||
saveConfig({ | ||
variables: { | ||
config: R.compose( | ||
toNamespace(namespaces.MACHINE_SCREENS), | ||
toNamespace('rates') | ||
)( | ||
R.merge(ratesScreenConfig, { | ||
active: event.target.checked | ||
}) | ||
) | ||
} | ||
}) | ||
} | ||
/> | ||
<Label2>{ratesScreenConfig.active ? 'Yes' : 'No'}</Label2> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
}) | ||
|
||
export default MachineScreens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters