mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Updates props being passed to Schedules to more accuratly reflect what they are
This commit is contained in:
@@ -10,6 +10,7 @@ class InventorySources extends LaunchUpdateMixin(
|
|||||||
super(http);
|
super(http);
|
||||||
this.baseUrl = '/api/v2/inventory_sources/';
|
this.baseUrl = '/api/v2/inventory_sources/';
|
||||||
|
|
||||||
|
this.createSchedule = this.createSchedule.bind(this);
|
||||||
this.createSyncStart = this.createSyncStart.bind(this);
|
this.createSyncStart = this.createSyncStart.bind(this);
|
||||||
this.destroyGroups = this.destroyGroups.bind(this);
|
this.destroyGroups = this.destroyGroups.bind(this);
|
||||||
this.destroyHosts = this.destroyHosts.bind(this);
|
this.destroyHosts = this.destroyHosts.bind(this);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class JobTemplates extends SchedulesMixin(
|
|||||||
super(http);
|
super(http);
|
||||||
this.baseUrl = '/api/v2/job_templates/';
|
this.baseUrl = '/api/v2/job_templates/';
|
||||||
|
|
||||||
|
this.createSchedule = this.createSchedule.bind(this);
|
||||||
this.launch = this.launch.bind(this);
|
this.launch = this.launch.bind(this);
|
||||||
this.readLaunch = this.readLaunch.bind(this);
|
this.readLaunch = this.readLaunch.bind(this);
|
||||||
this.associateLabel = this.associateLabel.bind(this);
|
this.associateLabel = this.associateLabel.bind(this);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Projects extends SchedulesMixin(
|
|||||||
this.readPlaybooks = this.readPlaybooks.bind(this);
|
this.readPlaybooks = this.readPlaybooks.bind(this);
|
||||||
this.readSync = this.readSync.bind(this);
|
this.readSync = this.readSync.bind(this);
|
||||||
this.sync = this.sync.bind(this);
|
this.sync = this.sync.bind(this);
|
||||||
|
this.createSchedule = this.createSchedule.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
readAccessList(id, params) {
|
readAccessList(id, params) {
|
||||||
|
|||||||
@@ -14,6 +14,19 @@ class Schedules extends Base {
|
|||||||
return this.http.get(`${this.baseUrl}${resourceId}/credentials/`, params);
|
return this.http.get(`${this.baseUrl}${resourceId}/credentials/`, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
associateCredential(resourceId, credentialId) {
|
||||||
|
return this.http.post(`${this.baseUrl}${resourceId}/credentials/`, {
|
||||||
|
id: credentialId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
disassociateCredential(resourceId, credentialId) {
|
||||||
|
return this.http.post(`${this.baseUrl}${resourceId}/credentials/`, {
|
||||||
|
id: credentialId,
|
||||||
|
disassociate: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
readZoneInfo() {
|
readZoneInfo() {
|
||||||
return this.http.get(`${this.baseUrl}zoneinfo/`);
|
return this.http.get(`${this.baseUrl}zoneinfo/`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class WorkflowJobTemplates extends SchedulesMixin(NotificationsMixin(Base)) {
|
|||||||
constructor(http) {
|
constructor(http) {
|
||||||
super(http);
|
super(http);
|
||||||
this.baseUrl = '/api/v2/workflow_job_templates/';
|
this.baseUrl = '/api/v2/workflow_job_templates/';
|
||||||
|
this.createSchedule = this.createSchedule.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
readWebhookKey(id) {
|
readWebhookKey(id) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useCallback } from 'react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
|
|
||||||
@@ -17,37 +17,39 @@ import ContentLoading from '../ContentLoading';
|
|||||||
import ScheduleDetail from './ScheduleDetail';
|
import ScheduleDetail from './ScheduleDetail';
|
||||||
import ScheduleEdit from './ScheduleEdit';
|
import ScheduleEdit from './ScheduleEdit';
|
||||||
import { SchedulesAPI } from '../../api';
|
import { SchedulesAPI } from '../../api';
|
||||||
|
import useRequest from '../../util/useRequest';
|
||||||
|
|
||||||
function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
|
function Schedule({ i18n, setBreadcrumb, resource }) {
|
||||||
const [schedule, setSchedule] = useState(null);
|
|
||||||
const [contentLoading, setContentLoading] = useState(true);
|
|
||||||
const [contentError, setContentError] = useState(null);
|
|
||||||
const { scheduleId } = useParams();
|
const { scheduleId } = useParams();
|
||||||
const location = useLocation();
|
|
||||||
const { pathname } = location;
|
const { pathname } = useLocation();
|
||||||
|
|
||||||
const pathRoot = pathname.substr(0, pathname.indexOf('schedules'));
|
const pathRoot = pathname.substr(0, pathname.indexOf('schedules'));
|
||||||
|
|
||||||
useEffect(() => {
|
const {
|
||||||
const loadData = async () => {
|
isLoading: contentLoading,
|
||||||
try {
|
error: contentError,
|
||||||
const { data } = await SchedulesAPI.readDetail(scheduleId);
|
request: loadData,
|
||||||
setSchedule(data);
|
result: schedule,
|
||||||
} catch (err) {
|
} = useRequest(
|
||||||
setContentError(err);
|
useCallback(async () => {
|
||||||
} finally {
|
const { data } = await SchedulesAPI.readDetail(scheduleId);
|
||||||
setContentLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}, [scheduleId]),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
loadData();
|
loadData();
|
||||||
}, [location.pathname, scheduleId]);
|
}, [loadData, pathname]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (schedule) {
|
if (schedule) {
|
||||||
setBreadcrumb(unifiedJobTemplate, schedule);
|
setBreadcrumb(resource, schedule);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [schedule, unifiedJobTemplate]);
|
}, [schedule, resource]);
|
||||||
const tabsArray = [
|
const tabsArray = [
|
||||||
{
|
{
|
||||||
name: (
|
name: (
|
||||||
@@ -71,8 +73,8 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
schedule.summary_fields.unified_job_template.id !==
|
schedule?.summary_fields.unified_job_template.id !==
|
||||||
parseInt(unifiedJobTemplate.id, 10)
|
parseInt(resource.id, 10)
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<ContentError>
|
<ContentError>
|
||||||
@@ -89,10 +91,7 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
|
|||||||
|
|
||||||
let showCardHeader = true;
|
let showCardHeader = true;
|
||||||
|
|
||||||
if (
|
if (!pathname.includes('schedules/') || pathname.endsWith('edit')) {
|
||||||
!location.pathname.includes('schedules/') ||
|
|
||||||
location.pathname.endsWith('edit')
|
|
||||||
) {
|
|
||||||
showCardHeader = false;
|
showCardHeader = false;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
@@ -106,7 +105,7 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
|
|||||||
/>
|
/>
|
||||||
{schedule && [
|
{schedule && [
|
||||||
<Route key="edit" path={`${pathRoot}schedules/:id/edit`}>
|
<Route key="edit" path={`${pathRoot}schedules/:id/edit`}>
|
||||||
<ScheduleEdit schedule={schedule} />
|
<ScheduleEdit schedule={schedule} resource={resource} />
|
||||||
</Route>,
|
</Route>,
|
||||||
<Route
|
<Route
|
||||||
key="details"
|
key="details"
|
||||||
@@ -117,7 +116,7 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
|
|||||||
]}
|
]}
|
||||||
<Route key="not-found" path="*">
|
<Route key="not-found" path="*">
|
||||||
<ContentError>
|
<ContentError>
|
||||||
{unifiedJobTemplate && (
|
{resource && (
|
||||||
<Link to={`${pathRoot}details`}>{i18n._(t`View Details`)}</Link>
|
<Link to={`${pathRoot}details`}>{i18n._(t`View Details`)}</Link>
|
||||||
)}
|
)}
|
||||||
</ContentError>
|
</ContentError>
|
||||||
|
|||||||
@@ -93,10 +93,7 @@ describe('<Schedule />', () => {
|
|||||||
<Route
|
<Route
|
||||||
path="/templates/job_template/:id/schedules"
|
path="/templates/job_template/:id/schedules"
|
||||||
component={() => (
|
component={() => (
|
||||||
<Schedule
|
<Schedule setBreadcrumb={() => {}} resource={unifiedJobTemplate} />
|
||||||
setBreadcrumb={() => {}}
|
|
||||||
unifiedJobTemplate={unifiedJobTemplate}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
/>,
|
/>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { CardBody } from '../../Card';
|
|||||||
import buildRuleObj from '../shared/buildRuleObj';
|
import buildRuleObj from '../shared/buildRuleObj';
|
||||||
import ScheduleForm from '../shared/ScheduleForm';
|
import ScheduleForm from '../shared/ScheduleForm';
|
||||||
|
|
||||||
function ScheduleAdd({ i18n, createSchedule }) {
|
function ScheduleAdd({ i18n, resource, apiModel }) {
|
||||||
const [formSubmitError, setFormSubmitError] = useState(null);
|
const [formSubmitError, setFormSubmitError] = useState(null);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@@ -18,11 +18,8 @@ function ScheduleAdd({ i18n, createSchedule }) {
|
|||||||
const handleSubmit = async values => {
|
const handleSubmit = async values => {
|
||||||
try {
|
try {
|
||||||
const rule = new RRule(buildRuleObj(values, i18n));
|
const rule = new RRule(buildRuleObj(values, i18n));
|
||||||
const {
|
|
||||||
data: { id: scheduleId },
|
const { id: scheduleId } = await apiModel.createSchedule(resource.id, {
|
||||||
} = await createSchedule({
|
|
||||||
name: values.name,
|
|
||||||
description: values.description,
|
|
||||||
rrule: rule.toString().replace(/\n/g, ' '),
|
rrule: rule.toString().replace(/\n/g, ' '),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,7 +43,7 @@ function ScheduleAdd({ i18n, createSchedule }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScheduleAdd.propTypes = {
|
ScheduleAdd.propTypes = {
|
||||||
createSchedule: func.isRequired,
|
apiModel: shape({ createSchedule: func.isRequired }).isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
ScheduleAdd.defaultProps = {};
|
ScheduleAdd.defaultProps = {};
|
||||||
|
|||||||
@@ -189,6 +189,14 @@ function ScheduleDetail({ schedule, i18n }) {
|
|||||||
showVerbosityDetail ||
|
showVerbosityDetail ||
|
||||||
showVariablesDetail;
|
showVariablesDetail;
|
||||||
|
|
||||||
|
const VERBOSITY = {
|
||||||
|
0: i18n._(t`0 (Normal)`),
|
||||||
|
1: i18n._(t`1 (Verbose)`),
|
||||||
|
2: i18n._(t`2 (More Verbose)`),
|
||||||
|
3: i18n._(t`3 (Debug)`),
|
||||||
|
4: i18n._(t`4 (Connection Debug)`),
|
||||||
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <ContentLoading />;
|
return <ContentLoading />;
|
||||||
}
|
}
|
||||||
@@ -256,6 +264,12 @@ function ScheduleDetail({ schedule, i18n }) {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{ask_verbosity_on_launch && (
|
||||||
|
<Detail
|
||||||
|
label={i18n._(t`Verbosity`)}
|
||||||
|
value={VERBOSITY[verbosity]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{ask_scm_branch_on_launch && (
|
{ask_scm_branch_on_launch && (
|
||||||
<Detail
|
<Detail
|
||||||
label={i18n._(t`Source Control Branch`)}
|
label={i18n._(t`Source Control Branch`)}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { SchedulesAPI } from '../../../api';
|
|||||||
import buildRuleObj from '../shared/buildRuleObj';
|
import buildRuleObj from '../shared/buildRuleObj';
|
||||||
import ScheduleForm from '../shared/ScheduleForm';
|
import ScheduleForm from '../shared/ScheduleForm';
|
||||||
|
|
||||||
function ScheduleEdit({ i18n, schedule }) {
|
function ScheduleEdit({ i18n, schedule, resource }) {
|
||||||
const [formSubmitError, setFormSubmitError] = useState(null);
|
const [formSubmitError, setFormSubmitError] = useState(null);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|||||||
@@ -6,24 +6,21 @@ import ScheduleAdd from './ScheduleAdd';
|
|||||||
import ScheduleList from './ScheduleList';
|
import ScheduleList from './ScheduleList';
|
||||||
|
|
||||||
function Schedules({
|
function Schedules({
|
||||||
createSchedule,
|
apiModel,
|
||||||
loadScheduleOptions,
|
loadScheduleOptions,
|
||||||
loadSchedules,
|
loadSchedules,
|
||||||
setBreadcrumb,
|
setBreadcrumb,
|
||||||
unifiedJobTemplate,
|
resource,
|
||||||
}) {
|
}) {
|
||||||
const match = useRouteMatch();
|
const match = useRouteMatch();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path={`${match.path}/add`}>
|
<Route path={`${match.path}/add`}>
|
||||||
<ScheduleAdd createSchedule={createSchedule} />
|
<ScheduleAdd apiModel={apiModel} resource={resource} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route key="details" path={`${match.path}/:scheduleId`}>
|
<Route key="details" path={`${match.path}/:scheduleId`}>
|
||||||
<Schedule
|
<Schedule setBreadcrumb={setBreadcrumb} resource={resource} />
|
||||||
unifiedJobTemplate={unifiedJobTemplate}
|
|
||||||
setBreadcrumb={setBreadcrumb}
|
|
||||||
/>
|
|
||||||
</Route>
|
</Route>
|
||||||
<Route key="list" path={`${match.path}`}>
|
<Route key="list" path={`${match.path}`}>
|
||||||
<ScheduleList
|
<ScheduleList
|
||||||
|
|||||||
@@ -69,9 +69,6 @@ function InventorySource({ i18n, inventory, setBreadcrumb, me }) {
|
|||||||
[source]
|
[source]
|
||||||
);
|
);
|
||||||
|
|
||||||
const createSchedule = data =>
|
|
||||||
InventorySourcesAPI.createSchedule(source?.id, data);
|
|
||||||
|
|
||||||
const loadScheduleOptions = useCallback(() => {
|
const loadScheduleOptions = useCallback(() => {
|
||||||
return InventorySourcesAPI.readScheduleOptions(source?.id);
|
return InventorySourcesAPI.readScheduleOptions(source?.id);
|
||||||
}, [source]);
|
}, [source]);
|
||||||
@@ -160,11 +157,11 @@ function InventorySource({ i18n, inventory, setBreadcrumb, me }) {
|
|||||||
path="/inventories/inventory/:id/sources/:sourceId/schedules"
|
path="/inventories/inventory/:id/sources/:sourceId/schedules"
|
||||||
>
|
>
|
||||||
<Schedules
|
<Schedules
|
||||||
createSchedule={createSchedule}
|
apiModel={InventorySourcesAPI}
|
||||||
setBreadcrumb={(unifiedJobTemplate, schedule) =>
|
setBreadcrumb={schedule =>
|
||||||
setBreadcrumb(inventory, source, schedule)
|
setBreadcrumb(inventory, source, schedule)
|
||||||
}
|
}
|
||||||
unifiedJobTemplate={source}
|
resource={source}
|
||||||
loadSchedules={loadSchedules}
|
loadSchedules={loadSchedules}
|
||||||
loadScheduleOptions={loadScheduleOptions}
|
loadScheduleOptions={loadScheduleOptions}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -78,10 +78,6 @@ function Project({ i18n, setBreadcrumb }) {
|
|||||||
}
|
}
|
||||||
}, [project, setBreadcrumb]);
|
}, [project, setBreadcrumb]);
|
||||||
|
|
||||||
function createSchedule(data) {
|
|
||||||
return ProjectsAPI.createSchedule(project.id, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadScheduleOptions = useCallback(() => {
|
const loadScheduleOptions = useCallback(() => {
|
||||||
return ProjectsAPI.readScheduleOptions(project.id);
|
return ProjectsAPI.readScheduleOptions(project.id);
|
||||||
}, [project]);
|
}, [project]);
|
||||||
@@ -188,8 +184,8 @@ function Project({ i18n, setBreadcrumb }) {
|
|||||||
<Route path="/projects/:id/schedules">
|
<Route path="/projects/:id/schedules">
|
||||||
<Schedules
|
<Schedules
|
||||||
setBreadcrumb={setBreadcrumb}
|
setBreadcrumb={setBreadcrumb}
|
||||||
unifiedJobTemplate={project}
|
resource={project}
|
||||||
createSchedule={createSchedule}
|
apiModel={ProjectsAPI}
|
||||||
loadSchedules={loadSchedules}
|
loadSchedules={loadSchedules}
|
||||||
loadScheduleOptions={loadScheduleOptions}
|
loadScheduleOptions={loadScheduleOptions}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -86,10 +86,6 @@ function Template({ i18n, setBreadcrumb }) {
|
|||||||
}
|
}
|
||||||
}, [template, setBreadcrumb]);
|
}, [template, setBreadcrumb]);
|
||||||
|
|
||||||
const createSchedule = data => {
|
|
||||||
return JobTemplatesAPI.createSchedule(template.id, data);
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadScheduleOptions = useCallback(() => {
|
const loadScheduleOptions = useCallback(() => {
|
||||||
return JobTemplatesAPI.readScheduleOptions(templateId);
|
return JobTemplatesAPI.readScheduleOptions(templateId);
|
||||||
}, [templateId]);
|
}, [templateId]);
|
||||||
@@ -203,9 +199,9 @@ function Template({ i18n, setBreadcrumb }) {
|
|||||||
path="/templates/:templateType/:id/schedules"
|
path="/templates/:templateType/:id/schedules"
|
||||||
>
|
>
|
||||||
<Schedules
|
<Schedules
|
||||||
createSchedule={createSchedule}
|
apiModel={JobTemplatesAPI}
|
||||||
setBreadcrumb={setBreadcrumb}
|
setBreadcrumb={setBreadcrumb}
|
||||||
unifiedJobTemplate={template}
|
resource={template}
|
||||||
loadSchedules={loadSchedules}
|
loadSchedules={loadSchedules}
|
||||||
loadScheduleOptions={loadScheduleOptions}
|
loadScheduleOptions={loadScheduleOptions}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -73,10 +73,6 @@ function WorkflowJobTemplate({ i18n, setBreadcrumb }) {
|
|||||||
loadTemplateAndRoles();
|
loadTemplateAndRoles();
|
||||||
}, [loadTemplateAndRoles, location.pathname]);
|
}, [loadTemplateAndRoles, location.pathname]);
|
||||||
|
|
||||||
const createSchedule = data => {
|
|
||||||
return WorkflowJobTemplatesAPI.createSchedule(templateId, data);
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadScheduleOptions = useCallback(() => {
|
const loadScheduleOptions = useCallback(() => {
|
||||||
return WorkflowJobTemplatesAPI.readScheduleOptions(templateId);
|
return WorkflowJobTemplatesAPI.readScheduleOptions(templateId);
|
||||||
}, [templateId]);
|
}, [templateId]);
|
||||||
@@ -206,9 +202,9 @@ function WorkflowJobTemplate({ i18n, setBreadcrumb }) {
|
|||||||
path="/templates/:templateType/:id/schedules"
|
path="/templates/:templateType/:id/schedules"
|
||||||
>
|
>
|
||||||
<Schedules
|
<Schedules
|
||||||
createSchedule={createSchedule}
|
apiModel={WorkflowJobTemplatesAPI}
|
||||||
setBreadcrumb={setBreadcrumb}
|
setBreadcrumb={setBreadcrumb}
|
||||||
unifiedJobTemplate={template}
|
resource={template}
|
||||||
loadSchedules={loadSchedules}
|
loadSchedules={loadSchedules}
|
||||||
loadScheduleOptions={loadScheduleOptions}
|
loadScheduleOptions={loadScheduleOptions}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user