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 Base from '../Base';
import NotificationsMixin from '../mixins/Notifications.mixin'; import NotificationsMixin from '../mixins/Notifications.mixin';
import LaunchUpdateMixin from '../mixins/LaunchUpdate.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) { constructor(http) {
super(http); super(http);
this.baseUrl = '/api/v2/inventory_sources/'; this.baseUrl = '/api/v2/inventory_sources/';

View File

@ -35,7 +35,6 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
try { try {
const { data } = await SchedulesAPI.readDetail(scheduleId); const { data } = await SchedulesAPI.readDetail(scheduleId);
setSchedule(data); setSchedule(data);
setBreadcrumb(unifiedJobTemplate, data);
} catch (err) { } catch (err) {
setContentError(err); setContentError(err);
} finally { } finally {
@ -44,8 +43,14 @@ function Schedule({ i18n, setBreadcrumb, unifiedJobTemplate }) {
}; };
loadData(); 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 = [ const tabsArray = [
{ {
name: ( name: (

View File

@ -43,7 +43,7 @@ function ScheduleListItem({ i18n, isSelected, onSelect, schedule }) {
switch (schedule.summary_fields.unified_job_template.unified_job_type) { switch (schedule.summary_fields.unified_job_template.unified_job_type) {
case 'inventory_update': 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; break;
case 'job': case 'job':
scheduleBaseUrl = `/templates/job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`; scheduleBaseUrl = `/templates/job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
@ -98,31 +98,31 @@ function ScheduleListItem({ i18n, isSelected, onSelect, schedule }) {
</DetailList> </DetailList>
)} )}
</DataListCell>, </DataListCell>,
<DataListAction
aria-label="actions"
aria-labelledby={labelId}
id={labelId}
key="actions"
>
<ScheduleToggle schedule={schedule} />
{schedule.summary_fields.user_capabilities.edit ? (
<Tooltip content={i18n._(t`Edit Schedule`)} position="top">
<Button
aria-label={i18n._(t`Edit Schedule`)}
css="grid-column: 2"
variant="plain"
component={Link}
to={`${scheduleBaseUrl}/edit`}
>
<PencilAltIcon />
</Button>
</Tooltip>
) : (
''
)}
</DataListAction>,
]} ]}
/> />
<DataListAction
aria-label="actions"
aria-labelledby={labelId}
id={labelId}
key="actions"
>
<ScheduleToggle schedule={schedule} />
{schedule.summary_fields.user_capabilities.edit ? (
<Tooltip content={i18n._(t`Edit Schedule`)} position="top">
<Button
aria-label={i18n._(t`Edit Schedule`)}
css="grid-column: 2"
variant="plain"
component={Link}
to={`${scheduleBaseUrl}/edit`}
>
<PencilAltIcon />
</Button>
</Tooltip>
) : (
''
)}
</DataListAction>
</DataListItemRow> </DataListItemRow>
</DataListItem> </DataListItem>
); );

View File

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

View File

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