Skip to content

Commit

Permalink
Use limits in Split menu
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed Jun 7, 2021
1 parent 7c33eaf commit 83ba348
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/client/components/split-menu/limit-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import * as React from "react";
import { DEFAULT_LIMITS } from "../../../common/limit/limit";
import { Unary } from "../../../common/utils/functional/functional";
import { STRINGS } from "../../config/constants";
import { Dropdown } from "../dropdown/dropdown";
Expand All @@ -24,22 +23,24 @@ function formatLimit(limit: number): string {
return limit === null ? "None" : String(limit);
}

function calculateLimits(includeNone: boolean) {
if (!includeNone) return DEFAULT_LIMITS;
return [...DEFAULT_LIMITS, null];
// TODO: Review again when fixing time split menu in #756
function calculateLimits(limits: number[], includeNone: boolean) {
if (!includeNone) return limits;
return [...limits, null];
}

export interface LimitDropdownProps {
limit: number;
selectedLimit: number;
limits: number[];
includeNone: boolean;
onLimitSelect: Unary<number, void>;
}

export const LimitDropdown: React.SFC<LimitDropdownProps> = ({ onLimitSelect, limit, includeNone }) => {
export const LimitDropdown: React.SFC<LimitDropdownProps> = ({ onLimitSelect, limits, selectedLimit, includeNone }) => {
return <Dropdown<number | string>
label={STRINGS.limit}
items={calculateLimits(includeNone)}
selectedItem={limit}
items={calculateLimits(limits, includeNone)}
selectedItem={selectedLimit}
renderItem={formatLimit}
onSelect={onLimitSelect}
/>;
Expand Down
5 changes: 3 additions & 2 deletions src/client/components/split-menu/split-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ export class SplitMenu extends React.Component<SplitMenuProps, SplitMenuState> {
{this.renderSortDropdown()}
<LimitDropdown
onLimitSelect={this.saveLimit}
limit={limit}
includeNone={isContinuous(dimension)} />
selectedLimit={limit}
includeNone={isContinuous(dimension)}
limits={dimension.limits}/>
<div className="button-bar">
<Button className="ok" type="primary" disabled={!this.validate()} onClick={this.onOkClick} title={STRINGS.ok} />
<Button type="secondary" onClick={this.onCancelClick} title={STRINGS.cancel} />
Expand Down

0 comments on commit 83ba348

Please sign in to comment.