1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 06:51:10 +03:00

Merge pull request #7221 from AlexSCorey/6589-InventorySourceSchedules

Adds Inventory Sources Schedules

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-06-10 15:01:54 +00:00 committed by GitHub
commit 753b8c287c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 29 deletions

View File

@ -1,8 +1,11 @@
import Base from '../Base';
import NotificationsMixin from '../mixins/Notifications.mixin';
import LaunchUpdateMixin from '../mixins/LaunchUpdate.mixin';
import SchedulesMixin from '../mixins/Schedules.mixin';
class InventorySources extends LaunchUpdateMixin(NotificationsMixin(Base)) {
class InventorySources extends LaunchUpdateMixin(
NotificationsMixin(SchedulesMixin(Base))
) {
constructor(http) {
super(http);
this.baseUrl = '/api/v2/inventory_sources/';

View File

@ -35,7 +35,6 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
try {
const { data } = await SchedulesAPI.readDetail(scheduleId);
setSchedule(data);
setBreadcrumb(unifiedJobTemplate, data);
} catch (err) {
setContentError(err);
} finally {
@ -44,8 +43,14 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
};
loadData();
}, [location.pathname, scheduleId, unifiedJobTemplate, setBreadcrumb]);
}, [location.pathname, scheduleId]);
useEffect(() => {
if (schedule) {
setBreadcrumb(unifiedJobTemplate, schedule);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [schedule, unifiedJobTemplate]);
const tabsArray = [
{
name: (

View File

@ -43,7 +43,7 @@ function ScheduleListItem({ i18n, isSelected, onSelect, schedule }) {
switch (schedule.summary_fields.unified_job_template.unified_job_type) {
case 'inventory_update':
scheduleBaseUrl = `/inventories/${schedule.summary_fields.inventory.id}/sources/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
scheduleBaseUrl = `/inventories/inventory/${schedule.summary_fields.inventory.id}/sources/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
break;
case 'job':
scheduleBaseUrl = `/templates/job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
@ -98,6 +98,8 @@ function ScheduleListItem({ i18n, isSelected, onSelect, schedule }) {
</DetailList>
)}
</DataListCell>,
]}
/>
<DataListAction
aria-label="actions"
aria-labelledby={labelId}
@ -120,9 +122,7 @@ function ScheduleListItem({ i18n, isSelected, onSelect, schedule }) {
) : (
''
)}
</DataListAction>,
]}
/>
</DataListAction>
</DataListItemRow>
</DataListItem>
);

View File

@ -27,7 +27,7 @@ class Inventories extends Component {
};
}
setBreadCrumbConfig = (inventory, nested) => {
setBreadCrumbConfig = (inventory, nested, schedule) => {
const { i18n } = this.props;
if (!inventory) {
return;
@ -80,6 +80,11 @@ class Inventories extends Component {
[`${inventorySourcesPath}/${nested?.id}`]: `${nested?.name}`,
[`${inventorySourcesPath}/${nested?.id}/details`]: i18n._(t`Details`),
[`${inventorySourcesPath}/${nested?.id}/edit`]: i18n._(t`Edit details`),
[`${inventorySourcesPath}/${nested?.id}/schedules`]: i18n._(t`Schedules`),
[`${inventorySourcesPath}/${nested?.id}/schedules/${schedule?.id}`]: `${schedule?.name}`,
[`${inventorySourcesPath}/${nested?.id}/schedules/${schedule?.id}/details`]: i18n._(
t`Schedule Details`
),
};
this.setState({ breadcrumbConfig });
};

View File

@ -19,6 +19,7 @@ import {
OrganizationsAPI,
} from '../../../api';
import { TabbedCardHeader } from '../../../components/Card';
import { Schedules } from '../../../components/Schedule';
import CardCloseButton from '../../../components/CardCloseButton';
import ContentError from '../../../components/ContentError';
import ContentLoading from '../../../components/ContentLoading';
@ -64,6 +65,15 @@ function InventorySource({ i18n, inventory, setBreadcrumb, me }) {
}
}, [inventory, source, setBreadcrumb]);
const loadSchedules = params =>
InventorySourcesAPI.readSchedules(source?.id, params);
const createSchedule = data =>
InventorySourcesAPI.createSchedule(source?.id, data);
const loadScheduleOptions = () =>
InventorySourcesAPI.readScheduleOptions(source?.id);
const tabsArray = [
{
name: (
@ -104,7 +114,9 @@ function InventorySource({ i18n, inventory, setBreadcrumb, me }) {
return (
<>
{['edit'].some(name => location.pathname.includes(name)) ? null : (
{['edit', 'schedules/'].some(name =>
location.pathname.includes(name)
) ? null : (
<TabbedCardHeader>
<RoutedTabs tabsArray={tabsArray} />
<CardActions>
@ -144,6 +156,20 @@ function InventorySource({ i18n, inventory, setBreadcrumb, me }) {
apiModel={InventorySourcesAPI}
/>
</Route>
<Route
key="schedules"
path="/inventories/inventory/:id/sources/:sourceId/schedules"
>
<Schedules
createSchedule={createSchedule}
setBreadcrumb={(unifiedJobTemplate, schedule) =>
setBreadcrumb(inventory, source, schedule)
}
unifiedJobTemplate={source}
loadSchedules={loadSchedules}
loadScheduleOptions={loadScheduleOptions}
/>
</Route>
<Route key="not-found" path="*">
<ContentError isNotFound>
<Link to={`${match.url}/details`}>