Skip to content

Commit

Permalink
support for cron-based schedules (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowalski committed Jul 16, 2023
1 parent 3df35e6 commit 672f3a2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/PolicyEditor/EffectiveListValue.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import Form from 'react-bootstrap/Form';
import { getDeepStateProperty } from '../deepstate';
import { EffectiveValueColumn } from "./EffectiveValueColumn";

export function EffectiveListValue(component, policyField) {
const dsp = getDeepStateProperty(component, "resolved.definition." + policyField, undefined);

return <EffectiveValueColumn>
<Form.Group>
<Form.Control
data-testid={'effective-' + policyField}
size="sm"
as="textarea"
rows="5"
value={getDeepStateProperty(component, "resolved.effective." + policyField, undefined)}
readOnly={true} />
<Form.Text data-testid={'definition-' + policyField}>
{component.PolicyDefinitionPoint(dsp)}
</Form.Text>
</Form.Group>
</EffectiveValueColumn>;
}
16 changes: 16 additions & 0 deletions src/PolicyEditor/EffectiveTimesOfDayValue.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import Form from 'react-bootstrap/Form';
import { getDeepStateProperty } from '../deepstate';
import { EffectiveValueColumn } from "./EffectiveValueColumn";
import { TimesOfDayList } from '../forms/TimesOfDayList';

export function EffectiveTimesOfDayValue(component, policyField) {
return <EffectiveValueColumn>
<Form.Group>
{TimesOfDayList(component, "resolved.effective." + policyField)}
<Form.Text data-testid={'definition-' + policyField}>
{component.PolicyDefinitionPoint(getDeepStateProperty(component, "resolved.definition." + policyField, undefined))}
</Form.Text>
</Form.Group>
</EffectiveValueColumn>;
}
12 changes: 11 additions & 1 deletion src/PolicyEditor/UpcomingSnapshotTimes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import moment from 'moment';
import React from 'react';
import { LabelColumn } from './LabelColumn';

export function UpcomingSnapshotTimes(times) {
export function UpcomingSnapshotTimes(resolved) {
if (!resolved) {
return null;
}

if (resolved.schedulingError) {
return <p class="error">{resolved.schedulingError}</p>;
}

const times = resolved.upcomingSnapshotTimes;

if (!times) {
return <LabelColumn name="No upcoming snapshots" />;
}
Expand Down
17 changes: 15 additions & 2 deletions src/PolicyEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { LabelColumn } from './LabelColumn';
import { ValueColumn } from './ValueColumn';
import { WideValueColumn } from './WideValueColumn';
import { EffectiveValue } from './EffectiveValue';
import { EffectiveListValue } from './EffectiveListValue';
import { EffectiveTextAreaValue } from './EffectiveTextAreaValue';
import { EffectiveTimesOfDayValue } from './EffectiveTimesOfDayValue';
import { EffectiveBooleanValue } from './EffectiveBooleanValue';
import { EffectiveValueColumn } from './EffectiveValueColumn';
import { UpcomingSnapshotTimes } from './UpcomingSnapshotTimes';
Expand Down Expand Up @@ -102,6 +104,7 @@ export class PolicyEditor extends Component {
}).then(result => {
this.setState({ resolved: result.data });
}).catch(error => {
this.setState({ resolvedError: error });
});
}
catch (e) {
Expand Down Expand Up @@ -421,7 +424,17 @@ export class PolicyEditor extends Component {
<ValueColumn>
{TimesOfDayList(this, "policy.scheduling.timeOfDay")}
</ValueColumn>
{EffectiveBooleanValue(this, "scheduling.manual")}
{EffectiveTimesOfDayValue(this, "scheduling.timeOfDay")}
</Row>
<Row>
<LabelColumn name="Cron Expressions" help={<>Snapshot schedules using UNIX crontab syntax (one per line):
<br/><br/><pre>minute hour day month weekday #comment</pre>

See <a target="_blank" rel="noreferrer" href="https://github.com/hashicorp/cronexpr#implementation">supported format details</a>.</>} />
<ValueColumn>
{StringList(this, "policy.scheduling.cron")}
</ValueColumn>
{EffectiveListValue(this, "scheduling.cron")}
</Row>
<Row>
<LabelColumn name="Manual Snapshots Only" help="Only create snapshots manually (disables scheduled snapshots)" />
Expand All @@ -435,7 +448,7 @@ export class PolicyEditor extends Component {
<ValueColumn>
</ValueColumn>
<EffectiveValueColumn>
{UpcomingSnapshotTimes(this.state?.resolved?.upcomingSnapshotTimes)}
{UpcomingSnapshotTimes(this.state?.resolved)}
</EffectiveValueColumn>
</Row>
</Accordion.Body>
Expand Down

0 comments on commit 672f3a2

Please sign in to comment.