Skip to content

Commit

Permalink
EarningChart: Earnings Per Machine Switch - added (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitto-moz authored Jun 14, 2024
1 parent acb7670 commit f18d98d
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefaultTheme as GardenTheme } from '@saladtechnologies/garden-components'
import { DefaultTheme as GardenTheme, Switch } from '@saladtechnologies/garden-components'
import classnames from 'classnames'
import { uniq } from 'lodash'
import moment from 'moment'
Expand All @@ -25,6 +25,12 @@ const styles = (theme: SaladTheme) => ({
removeContainerPadding: {
paddingTop: 0,
},
chartHeader: {
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'flex-end',
flexDirection: 'row',
},
segmentsContainer: {
'&>label:first-child': {
borderRadius: '2px 0px 0px 2px',
Expand Down Expand Up @@ -92,6 +98,9 @@ const styles = (theme: SaladTheme) => ({
tickMobile: {
display: 'block',
},
earningPerMachineSwitchWrapper: {
marginLeft: 32,
},
'@media screen and (min-width: 1025px)': {
tickDesktop: {
display: 'block',
Expand Down Expand Up @@ -286,13 +295,15 @@ interface State {
selectedLeftToRight?: boolean
selectedRangeIndexes: number[]
showEarningsRange?: boolean
isEarningsPerMachineEnabled: boolean
}

class _EarningChart extends Component<Props, State> {
constructor(props: Props) {
super(props)
this.state = {
selectedRangeIndexes: [],
isEarningsPerMachineEnabled: false,
}
}

Expand Down Expand Up @@ -323,6 +334,10 @@ class _EarningChart extends Component<Props, State> {
return true
}

if (this.state.isEarningsPerMachineEnabled !== nextState.isEarningsPerMachineEnabled) {
return true
}

return false
}

Expand Down Expand Up @@ -426,6 +441,12 @@ class _EarningChart extends Component<Props, State> {

getTimeValue = (earningWindow: EarningWindow) => moment(earningWindow.timestamp).valueOf()

handleEarningsPerMachineClick = () => {
this.setState((prevState) => ({
isEarningsPerMachineEnabled: !prevState.isEarningsPerMachineEnabled,
}))
}

public override render(): ReactNode {
const { daysShowing, classes, earningHistory, viewLast24Hours, viewLast7Days, viewLast30Days } = this.props
const { hoverIndex, showEarningsRange, earningsRangeSum, rangeCenterCoordinate, selectedRangeIndexes } = this.state
Expand All @@ -447,8 +468,18 @@ class _EarningChart extends Component<Props, State> {
>
<P>No data to display</P>
</div>
<div className={classes.segmentsContainer}>
<Segments options={segmentOptions} />
<div className={classes.chartHeader}>
<div className={classes.segmentsContainer}>
<Segments options={segmentOptions} />
</div>
<div className={classes.earningPerMachineSwitchWrapper}>
<Switch
label="Earnings Per Machine"
checked={this.state.isEarningsPerMachineEnabled}
onChange={this.handleEarningsPerMachineClick}
variant="light"
/>
</div>
</div>
{earningHistory && (
<>
Expand Down

0 comments on commit f18d98d

Please sign in to comment.