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
No known key found for this signature in database
GPG Key ID: 0E56ED990CDFCB4F
4 changed files with 36 additions and 13 deletions

View File

@ -25,6 +25,7 @@ function Schedule({
resource,
launchConfig,
surveyConfig,
hasDaysToKeepField,
}) {
const { scheduleId } = useParams();
@ -96,13 +97,6 @@ function Schedule({
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 (
<>
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />}

View File

@ -15,7 +15,14 @@ import mergeExtraVars from '../../../util/prompt/mergeExtraVars';
import getSurveyValues from '../../../util/prompt/getSurveyValues';
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 history = useHistory();
const location = useLocation();
@ -70,13 +77,22 @@ function ScheduleAdd({ i18n, resource, apiModel, launchConfig, surveyConfig }) {
try {
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 {
data: { id: scheduleId },
} = await apiModel.createSchedule(resource.id, {
...submitValues,
rrule: rule.toString().replace(/\n/g, ' '),
});
} = await apiModel.createSchedule(resource.id, requestData);
if (credentials?.length > 0) {
await Promise.all(
added.map(({ id: credentialId }) =>
@ -94,6 +110,7 @@ function ScheduleAdd({ i18n, resource, apiModel, launchConfig, surveyConfig }) {
<Card>
<CardBody>
<ScheduleForm
hasDaysToKeepField={hasDaysToKeepField}
handleCancel={() => history.push(`${pathRoot}schedules`)}
handleSubmit={handleSubmit}
submitError={formSubmitError}

View File

@ -16,10 +16,18 @@ function Schedules({
}) {
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 (
<Switch>
<Route path={`${match.path}/add`}>
<ScheduleAdd
hasDaysToKeepField={hasDaysToKeepField}
apiModel={apiModel}
resource={resource}
launchConfig={launchConfig}
@ -28,6 +36,7 @@ function Schedules({
</Route>
<Route key="details" path={`${match.path}/:scheduleId`}>
<Schedule
hasDaysToKeepField={hasDaysToKeepField}
setBreadcrumb={setBreadcrumb}
resource={resource}
launchConfig={launchConfig}

View File

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