Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for cron-based schedules #175

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading