Skip to content

Commit

Permalink
fix(recurring-job) Modify the interaction mode for force creating sna…
Browse files Browse the repository at this point in the history
…pshots and backups

Signed-off-by: Siye Wang <siye@rancher.com>
  • Loading branch information
smallteeths authored and David Ko committed Mar 30, 2023
1 parent ea6768d commit 3ddbe5d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 36 deletions.
56 changes: 38 additions & 18 deletions src/routes/recurringJob/CreateRecurringJob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Icon, Button, Select, InputNumber, Tooltip } from 'antd'
import { Form, Input, Icon, Button, Select, Checkbox, InputNumber, Tooltip } from 'antd'
import { ModalBlur, ReactCron } from '../../components'

const Option = Select.Option
Expand Down Expand Up @@ -64,6 +64,14 @@ const modal = ({
const data = {
...getFieldsValue(),
}
if (data.fourceCreate) {
if (data.task === 'snapshot') {
data.task = 'snapshot-force-create'
}
if (data.task === 'backup') {
data.task = 'backup-force-create'
}
}
if (data.groups) {
data.groups = data.groups.filter((group) => {
return group
Expand Down Expand Up @@ -158,6 +166,9 @@ const modal = ({
})
}
}
const showForceCreateCheckbox = () => {
return getFieldValue('task') === 'backup' || getFieldValue('task') === 'snapshot'
}

// init params
getFieldDecorator('keys', { initialValue: isEdit && item.groups && item.groups.length > 0 ? item.groups.map((group, index) => { return { initialValue: group, index } }) : [{ index: 0, initialValue: '' }] })
Expand Down Expand Up @@ -268,23 +279,32 @@ const modal = ({
],
})(<Input disabled={isEdit || addForVolume} style={{ width: '80%' }} />)}
</FormItem>
<FormItem label="Task" hasFeedback {...formItemLayout}>
{getFieldDecorator('task', {
initialValue: isEdit ? item.task : 'snapshot',
rules: [
{
required: true,
},
],
})(<Select disabled={isEdit} style={{ width: '80%' }} onChange={onChangeTask}>
<Option value="backup">Backup</Option>
<Option value="backup-force-create">Backup Force Create</Option>
<Option value="snapshot">Snapshot</Option>
<Option value="snapshot-force-create">Snapshot Force Create</Option>
<Option value="snapshot-delete">Snapshot Delete</Option>
<Option value="snapshot-cleanup">Snapshot Cleanup</Option>
</Select>)}
</FormItem>
<div style={{ display: 'flex' }}>
<FormItem label="Task" style={{ flex: 1 }} hasFeedback labelCol={{ span: showForceCreateCheckbox() ? 7 : 4 }} wrapperCol={{ span: 17 }}>
{getFieldDecorator('task', {
initialValue: isEdit ? item.task : 'snapshot',
rules: [
{
required: true,
},
],
})(<Select disabled={isEdit} style={{ width: '80%' }} onChange={onChangeTask}>
<Option value="backup">Backup</Option>
<Option value="snapshot">Snapshot</Option>
<Option value="snapshot-delete">Snapshot Delete</Option>
<Option value="snapshot-cleanup">Snapshot Cleanup</Option>
</Select>)}
</FormItem>
{showForceCreateCheckbox() && <Tooltip
placement="topLeft"
title={`Create ${getFieldValue('task') === 'backup' ? 'backups' : 'snapshots'} periodically, even if expired ${getFieldValue('task') === 'backup' ? 'backups' : 'snapshots'} cannot be cleaned up.`}>
<FormItem label="Force Create" style={{ width: 325 }} labelCol={{ span: 8 }} wrapperCol={{ span: 4 }}>
{getFieldDecorator('fourceCreate', {
initialValue: false,
})(<Checkbox></Checkbox>)}
</FormItem>
</Tooltip>}
</div>
<FormItem label="Retain" hasFeedback {...formItemLayout}>
{getFieldDecorator('retain', {
initialValue: isEdit ? item.retain : 1,
Expand Down
56 changes: 38 additions & 18 deletions src/routes/volume/detail/CreateRecurringJob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Icon, Button, Select, InputNumber, Tabs, Tooltip } from 'antd'
import { Form, Input, Icon, Button, Select, Checkbox, InputNumber, Tabs, Tooltip } from 'antd'
import { ModalBlur, ReactCron } from '../../../components'

const Option = Select.Option
Expand Down Expand Up @@ -67,6 +67,14 @@ const modal = ({
const data = {
...getFieldsValue(),
}
if (data.fourceCreate) {
if (data.task === 'snapshot') {
data.task = 'snapshot-force-create'
}
if (data.task === 'backup') {
data.task = 'backup-force-create'
}
}
if (data.groups) {
data.groups = data.groups.filter((group) => {
return group
Expand Down Expand Up @@ -164,6 +172,9 @@ const modal = ({
})
}
}
const showForceCreateCheckbox = () => {
return getFieldValue('task') === 'backup' || getFieldValue('task') === 'snapshot'
}

// init params
getFieldDecorator('keys', { initialValue: isEdit && item.groups && item.groups.length > 0 ? item.groups.map((group, index) => { return { initialValue: group, index } }) : [{ index: 0, initialValue: '' }] })
Expand Down Expand Up @@ -289,23 +300,32 @@ const modal = ({
],
})(<Input disabled={isEdit || addForVolume} style={{ width: '80%' }} />)}
</FormItem>
<FormItem label="Task" hasFeedback {...formItemLayout}>
{getFieldDecorator('task', {
initialValue: isEdit ? item.task : 'snapshot',
rules: [
{
required: true,
},
],
})(<Select disabled={isEdit} style={{ width: '80%' }} onChange={onChangeTask}>
<Option value="backup">Backup</Option>
<Option value="backup-force-create">Backup Force Create</Option>
<Option value="snapshot">Snapshot</Option>
<Option value="snapshot-force-create">Snapshot Force Create</Option>
<Option value="snapshot-delete">Snapshot Delete</Option>
<Option value="snapshot-cleanup">Snapshot Cleanup</Option>
</Select>)}
</FormItem>
<div style={{ display: 'flex' }}>
<FormItem label="Task" hasFeedback style={{ flex: 1 }} labelCol={{ span: showForceCreateCheckbox() ? 7 : 4 }} wrapperCol={{ span: 17 }}>
{getFieldDecorator('task', {
initialValue: isEdit ? item.task : 'snapshot',
rules: [
{
required: true,
},
],
})(<Select disabled={isEdit} style={{ width: '80%' }} onChange={onChangeTask}>
<Option value="backup">Backup</Option>
<Option value="snapshot">Snapshot</Option>
<Option value="snapshot-delete">Snapshot Delete</Option>
<Option value="snapshot-cleanup">Snapshot Cleanup</Option>
</Select>)}
</FormItem>
{showForceCreateCheckbox() && <Tooltip
placement="topLeft"
title={`Create ${getFieldValue('task') === 'backup' ? 'backups' : 'snapshots'} periodically, even if expired ${getFieldValue('task') === 'backup' ? 'backups' : 'snapshots'} cannot be cleaned up.`}>
<FormItem label="Force Create" style={{ width: 325 }} labelCol={{ span: 8 }} wrapperCol={{ span: 4 }}>
{getFieldDecorator('fourceCreate', {
initialValue: false,
})(<Checkbox></Checkbox>)}
</FormItem>
</Tooltip>}
</div>
<FormItem label="Retain" hasFeedback {...formItemLayout}>
{getFieldDecorator('retain', {
initialValue: isEdit ? item.retain : 1,
Expand Down

0 comments on commit 3ddbe5d

Please sign in to comment.