Add data retention field for schedule creation

This commit is contained in:
Jake McDermott
2021-02-23 09:54:06 -05:00
parent 4985fb6ffa
commit 2f56a20484
4 changed files with 36 additions and 13 deletions

View File

@@ -25,6 +25,7 @@ function Schedule({
resource, resource,
launchConfig, launchConfig,
surveyConfig, surveyConfig,
hasDaysToKeepField,
}) { }) {
const { scheduleId } = useParams(); const { scheduleId } = useParams();
@@ -96,13 +97,6 @@ function Schedule({
showCardHeader = false; showCardHeader = false;
} }
// For some management jobs that delete data, we want to provide an additional
// field on the scheduler for configuring the number of days to retain.
const hasDaysToKeepField = [
'cleanup_activitystream',
'cleanup_jobs',
].includes(schedule?.summary_fields?.unified_job_template?.job_type);
return ( return (
<> <>
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />} {showCardHeader && <RoutedTabs tabsArray={tabsArray} />}

View File

@@ -15,7 +15,14 @@ import mergeExtraVars from '../../../util/prompt/mergeExtraVars';
import getSurveyValues from '../../../util/prompt/getSurveyValues'; import getSurveyValues from '../../../util/prompt/getSurveyValues';
import { getAddedAndRemoved } from '../../../util/lists'; import { getAddedAndRemoved } from '../../../util/lists';
function ScheduleAdd({ i18n, resource, apiModel, launchConfig, surveyConfig }) { function ScheduleAdd({
i18n,
resource,
apiModel,
launchConfig,
surveyConfig,
hasDaysToKeepField,
}) {
const [formSubmitError, setFormSubmitError] = useState(null); const [formSubmitError, setFormSubmitError] = useState(null);
const history = useHistory(); const history = useHistory();
const location = useLocation(); const location = useLocation();
@@ -70,13 +77,22 @@ function ScheduleAdd({ i18n, resource, apiModel, launchConfig, surveyConfig }) {
try { try {
const rule = new RRule(buildRuleObj(values, i18n)); const rule = new RRule(buildRuleObj(values, i18n));
const requestData = {
...submitValues,
rrule: rule.toString().replace(/\n/g, ' '),
};
if (Object.keys(values).includes('daysToKeep')) {
if (requestData.extra_data) {
requestData.extra_data.days = values.daysToKeep;
} else {
requestData.extra_data = JSON.stringify({ days: values.daysToKeep });
}
}
const { const {
data: { id: scheduleId }, data: { id: scheduleId },
} = await apiModel.createSchedule(resource.id, { } = await apiModel.createSchedule(resource.id, requestData);
...submitValues,
rrule: rule.toString().replace(/\n/g, ' '),
});
if (credentials?.length > 0) { if (credentials?.length > 0) {
await Promise.all( await Promise.all(
added.map(({ id: credentialId }) => added.map(({ id: credentialId }) =>
@@ -94,6 +110,7 @@ function ScheduleAdd({ i18n, resource, apiModel, launchConfig, surveyConfig }) {
<Card> <Card>
<CardBody> <CardBody>
<ScheduleForm <ScheduleForm
hasDaysToKeepField={hasDaysToKeepField}
handleCancel={() => history.push(`${pathRoot}schedules`)} handleCancel={() => history.push(`${pathRoot}schedules`)}
handleSubmit={handleSubmit} handleSubmit={handleSubmit}
submitError={formSubmitError} submitError={formSubmitError}

View File

@@ -16,10 +16,18 @@ function Schedules({
}) { }) {
const match = useRouteMatch(); const match = useRouteMatch();
// For some management jobs that delete data, we want to provide an additional
// field on the scheduler for configuring the number of days to retain.
const hasDaysToKeepField = [
'cleanup_activitystream',
'cleanup_jobs',
].includes(resource?.job_type);
return ( return (
<Switch> <Switch>
<Route path={`${match.path}/add`}> <Route path={`${match.path}/add`}>
<ScheduleAdd <ScheduleAdd
hasDaysToKeepField={hasDaysToKeepField}
apiModel={apiModel} apiModel={apiModel}
resource={resource} resource={resource}
launchConfig={launchConfig} launchConfig={launchConfig}
@@ -28,6 +36,7 @@ function Schedules({
</Route> </Route>
<Route key="details" path={`${match.path}/:scheduleId`}> <Route key="details" path={`${match.path}/:scheduleId`}>
<Schedule <Schedule
hasDaysToKeepField={hasDaysToKeepField}
setBreadcrumb={setBreadcrumb} setBreadcrumb={setBreadcrumb}
resource={resource} resource={resource}
launchConfig={launchConfig} launchConfig={launchConfig}

View File

@@ -140,11 +140,14 @@ function ManagementJob({ i18n, setBreadcrumb }) {
) : null} ) : null}
<Route path={`${basePath}/:id/schedules`}> <Route path={`${basePath}/:id/schedules`}>
<Schedules <Schedules
unifiedJobTemplate={result} apiModel={SystemJobTemplatesAPI}
resource={result}
createSchedule={createSchedule} createSchedule={createSchedule}
loadSchedules={loadSchedules} loadSchedules={loadSchedules}
loadScheduleOptions={loadScheduleOptions} loadScheduleOptions={loadScheduleOptions}
setBreadcrumb={setBreadcrumb} setBreadcrumb={setBreadcrumb}
launchConfig={{}}
surveyConfig={{}}
/> />
</Route> </Route>
</Switch> </Switch>