-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of https://github.com/OpenEnergyDashboard/OED
- Loading branch information
Showing
19 changed files
with
700 additions
and
310 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,59 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as moment from 'moment'; | ||
import * as React from 'react'; | ||
import { Button, ButtonGroup, Dropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap'; | ||
import { graphSlice, selectComparePeriod, selectSortingOrder } from '../redux/slices/graphSlice'; | ||
import { Input } from 'reactstrap'; | ||
import { useAppDispatch, useAppSelector } from '../redux/reduxHooks'; | ||
import { ComparePeriod, SortingOrder } from '../utils/calculateCompare'; | ||
import { graphSlice, selectSortingOrder } from '../redux/slices/graphSlice'; | ||
import { SortingOrder } from '../utils/calculateCompare'; | ||
import translate from '../utils/translate'; | ||
import TooltipMarkerComponent from './TooltipMarkerComponent'; | ||
import IntervalControlsComponent from './IntervalControlsComponent'; | ||
|
||
/** | ||
* @returns controls for the compare page | ||
* @returns controls for compare page. | ||
*/ | ||
export default function CompareControlsComponent() { | ||
const dispatch = useAppDispatch(); | ||
const comparePeriod = useAppSelector(selectComparePeriod); | ||
|
||
// This is the current sorting order for graphic | ||
const compareSortingOrder = useAppSelector(selectSortingOrder); | ||
const [compareSortingDropdownOpen, setCompareSortingDropdownOpen] = React.useState<boolean>(false); | ||
const handleCompareButton = (comparePeriod: ComparePeriod) => { | ||
dispatch(graphSlice.actions.updateComparePeriod({ comparePeriod, currentTime: moment() })); | ||
}; | ||
const handleSortingButton = (sortingOrder: SortingOrder) => { | ||
|
||
// Updates sorting order when the sort order menu is used. | ||
const handleSortingChange = (value: string) => { | ||
const sortingOrder = value as unknown as SortingOrder; | ||
dispatch(graphSlice.actions.changeCompareSortingOrder(sortingOrder)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<ButtonGroup | ||
style={zIndexFix} | ||
> | ||
<Button | ||
outline={comparePeriod !== ComparePeriod.Day} | ||
active={comparePeriod === ComparePeriod.Day} | ||
onClick={() => handleCompareButton(ComparePeriod.Day)} | ||
{<IntervalControlsComponent key='interval' />} | ||
<div style={divTopBottomPadding}> | ||
<p style={labelStyle}> | ||
{translate('sort')}: | ||
<TooltipMarkerComponent page='home' helpTextId='help.home.compare.sort.tip' /> | ||
</p> | ||
<Input | ||
type="select" | ||
value={compareSortingOrder?.toString()} | ||
onChange={e => handleSortingChange(e.target.value)} | ||
> | ||
{translate('day')} | ||
</Button> | ||
<Button | ||
outline={comparePeriod !== ComparePeriod.Week} | ||
active={comparePeriod === ComparePeriod.Week} | ||
onClick={() => handleCompareButton(ComparePeriod.Week)} | ||
> | ||
{translate('week')} | ||
</Button> | ||
<Button | ||
outline={comparePeriod !== ComparePeriod.FourWeeks} | ||
active={comparePeriod === ComparePeriod.FourWeeks} | ||
onClick={() => handleCompareButton(ComparePeriod.FourWeeks)} | ||
> | ||
{translate('4.weeks')} | ||
</Button> | ||
</ButtonGroup> | ||
<TooltipMarkerComponent page='home' helpTextId='help.home.compare.interval.tip' /> | ||
<Dropdown isOpen={compareSortingDropdownOpen} toggle={() => setCompareSortingDropdownOpen(current => !current)}> | ||
<DropdownToggle caret> | ||
{translate('sort')} | ||
</DropdownToggle> | ||
<TooltipMarkerComponent page='home' helpTextId='help.home.compare.sort.tip' /> | ||
<DropdownMenu> | ||
<DropdownItem | ||
active={compareSortingOrder === SortingOrder.Alphabetical} | ||
onClick={() => handleSortingButton(SortingOrder.Alphabetical)} | ||
> | ||
{translate('alphabetically')} | ||
</DropdownItem> | ||
<DropdownItem | ||
active={compareSortingOrder === SortingOrder.Ascending} | ||
onClick={() => handleSortingButton(SortingOrder.Ascending)} | ||
> | ||
{translate('ascending')} | ||
</DropdownItem> | ||
<DropdownItem | ||
active={compareSortingOrder === SortingOrder.Descending} | ||
onClick={() => handleSortingButton(SortingOrder.Descending)} | ||
> | ||
{translate('descending')} | ||
</DropdownItem> | ||
</DropdownMenu> | ||
</Dropdown> | ||
</div> | ||
<option value={SortingOrder.Alphabetical.toString()}>{translate('alphabetically')}</option> | ||
<option value={SortingOrder.Ascending.toString()}>{translate('ascending')}</option> | ||
<option value={SortingOrder.Descending.toString()}>{translate('descending')}</option> | ||
</Input> | ||
</div> | ||
</div > | ||
); | ||
} | ||
|
||
const zIndexFix: React.CSSProperties = { | ||
zIndex: 0 | ||
}; | ||
const divTopBottomPadding: React.CSSProperties = { | ||
paddingTop: '0px', | ||
paddingBottom: '15px' | ||
}; | ||
|
||
const labelStyle: React.CSSProperties = { | ||
fontWeight: 'bold', | ||
margin: 0 | ||
}; |
Oops, something went wrong.