Web console: Fix missing include future flag for byPeriod rules (#8859)

* Add missing button for include future, and handle logic for default true case

* Remove duplicate go to tasks button

* Fix lgtm issue

* Revert changes on old console

* Made changes based on PR comments
This commit is contained in:
Evan Ren 2019-11-12 20:34:30 -08:00 committed by Vadim Ogievetsky
parent a066cc5648
commit 8cb213aa9f
4 changed files with 50 additions and 15 deletions

View File

@ -30,4 +30,11 @@
flex: 1; flex: 1;
} }
} }
.by-period {
display: flex;
.bp3-input-group {
padding-right: 15px;
}
}
} }

View File

@ -25,6 +25,7 @@ import {
HTMLSelect, HTMLSelect,
InputGroup, InputGroup,
NumericInput, NumericInput,
Switch,
TagInput, TagInput,
} from '@blueprintjs/core'; } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons'; import { IconNames } from '@blueprintjs/icons';
@ -139,7 +140,6 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
function renderColocatedDataSources() { function renderColocatedDataSources() {
const { rule, onChange } = props; const { rule, onChange } = props;
return ( return (
<FormGroup label="Colocated datasources:"> <FormGroup label="Colocated datasources:">
<TagInput <TagInput
@ -150,7 +150,6 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
</FormGroup> </FormGroup>
); );
} }
return ( return (
<div className="rule-editor"> <div className="rule-editor">
<div className="title"> <div className="title">
@ -193,13 +192,30 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
<option value="ByInterval">by interval</option> <option value="ByInterval">by interval</option>
</HTMLSelect> </HTMLSelect>
{ruleTimeType === 'ByPeriod' && ( {ruleTimeType === 'ByPeriod' && (
<InputGroup <div className={`by-period`}>
value={rule.period || ''} <InputGroup
onChange={(e: any) => value={rule.period || ''}
onChange(RuleUtil.changePeriod(rule, e.target.value as any)) onChange={(e: any) =>
} onChange(RuleUtil.changePeriod(rule, e.target.value as any))
placeholder="P1D" }
/> placeholder="P1D"
/>
<Switch
large
checked={rule.includeFuture !== undefined ? rule.includeFuture : true}
label={`Include future`}
onChange={() => {
onChange(
RuleUtil.changeIncludeFuture(
rule,
rule.includeFuture !== undefined
? (!rule.includeFuture as boolean)
: false,
),
);
}}
/>
</div>
)} )}
{ruleTimeType === 'ByInterval' && ( {ruleTimeType === 'ByInterval' && (
<InputGroup <InputGroup

View File

@ -29,6 +29,7 @@ export interface Rule {
| 'broadcastByPeriod'; | 'broadcastByPeriod';
interval?: string; interval?: string;
period?: string; period?: string;
includeFuture?: boolean;
tieredReplicants?: Record<string, number>; tieredReplicants?: Record<string, number>;
colocatedDataSources?: string[]; colocatedDataSources?: string[];
} }
@ -37,11 +38,23 @@ export type LoadType = 'load' | 'drop' | 'broadcast';
export type TimeType = 'Forever' | 'ByInterval' | 'ByPeriod'; export type TimeType = 'Forever' | 'ByInterval' | 'ByPeriod';
export class RuleUtil { export class RuleUtil {
static shouldIncludeFuture(rule: Rule): boolean {
if (rule.includeFuture !== false) {
return (
rule.type === 'loadByPeriod' ||
rule.type === 'dropByPeriod' ||
rule.type === 'broadcastByPeriod'
);
}
return false;
}
static ruleToString(rule: Rule): string { static ruleToString(rule: Rule): string {
return ( return (
rule.type + rule.type +
(rule.period ? `(${rule.period})` : '') + (rule.period ? `(${rule.period})` : '') +
(rule.interval ? `(${rule.interval})` : '') (rule.interval ? `(${rule.interval})` : '') +
(RuleUtil.shouldIncludeFuture(rule) ? `(includeFuture)` : '')
); );
} }
@ -75,6 +88,10 @@ export class RuleUtil {
return Object.assign({}, rule, { period }); return Object.assign({}, rule, { period });
} }
static changeIncludeFuture(rule: Rule, includeFuture: boolean): Rule {
return Object.assign({}, rule, { includeFuture });
}
static changeInterval(rule: Rule, interval: string): Rule { static changeInterval(rule: Rule, interval: string): Rule {
return Object.assign({}, rule, { interval }); return Object.assign({}, rule, { interval });
} }

View File

@ -642,11 +642,6 @@ GROUP BY 1`;
]; ];
} else { } else {
return goToActions.concat([ return goToActions.concat([
{
icon: IconNames.GANTT_CHART,
title: 'Go to tasks',
onAction: () => goToTask(datasource),
},
{ {
icon: IconNames.AUTOMATIC_UPDATES, icon: IconNames.AUTOMATIC_UPDATES,
title: 'Edit retention rules', title: 'Edit retention rules',