mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 12:41:19 -03:30
update ScheduleList api read to single prop
This commit is contained in:
parent
989ef3538e
commit
c1c382a941
@ -20,7 +20,7 @@ const QS_CONFIG = getQSConfig('schedule', {
|
||||
order_by: 'unified_job_template__polymorphic_ctype__model',
|
||||
});
|
||||
|
||||
function ScheduleList({ i18n, apiModel, resource }) {
|
||||
function ScheduleList({ i18n, loadSchedules }) {
|
||||
const [selected, setSelected] = useState([]);
|
||||
|
||||
const location = useLocation();
|
||||
@ -33,17 +33,12 @@ function ScheduleList({ i18n, apiModel, resource }) {
|
||||
} = useRequest(
|
||||
useCallback(async () => {
|
||||
const params = parseQueryString(QS_CONFIG, location.search);
|
||||
const response = apiModel
|
||||
? apiModel.readScheduleList(resource.id, params)
|
||||
: SchedulesAPI.read(params);
|
||||
const response = loadSchedules(params);
|
||||
const {
|
||||
data: { count, results },
|
||||
} = await response;
|
||||
return {
|
||||
itemCount: count,
|
||||
schedules: results,
|
||||
};
|
||||
}, [location, apiModel, resource]),
|
||||
return { itemCount: count, schedules: results };
|
||||
}, [location, loadSchedules]),
|
||||
{
|
||||
schedules: [],
|
||||
itemCount: 0,
|
||||
|
||||
@ -22,8 +22,11 @@ describe('ScheduleList', () => {
|
||||
describe('read call successful', () => {
|
||||
beforeAll(async () => {
|
||||
SchedulesAPI.read.mockResolvedValue({ data: mockSchedules });
|
||||
const loadSchedules = params => SchedulesAPI.read(params);
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(<ScheduleList />);
|
||||
wrapper = mountWithContexts(
|
||||
<ScheduleList loadSchedules={loadSchedules} />
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
});
|
||||
|
||||
@ -30,6 +30,7 @@ class Project extends Component {
|
||||
};
|
||||
this.loadProject = this.loadProject.bind(this);
|
||||
this.loadProjectAndRoles = this.loadProjectAndRoles.bind(this);
|
||||
this.loadSchedules = this.loadSchedules.bind(this);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
@ -103,6 +104,11 @@ class Project extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
loadSchedules(params) {
|
||||
const { project } = this.state;
|
||||
return ProjectsAPI.readScheduleList(project.id, params);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { location, match, me, i18n } = this.props;
|
||||
|
||||
@ -235,7 +241,7 @@ class Project extends Component {
|
||||
<Route
|
||||
path="/projects/:id/schedules"
|
||||
render={() => (
|
||||
<ScheduleList resource={project} apiModel={ProjectsAPI} />
|
||||
<ScheduleList loadSchedules={this.loadSchedules} />
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -5,8 +5,13 @@ import { t } from '@lingui/macro';
|
||||
|
||||
import Breadcrumbs from '@components/Breadcrumbs';
|
||||
import ScheduleList from '@components/ScheduleList';
|
||||
import { SchedulesAPI } from '@api';
|
||||
|
||||
function Schedules({ i18n }) {
|
||||
const loadSchedules = params => {
|
||||
return SchedulesAPI.read(params);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Breadcrumbs
|
||||
@ -16,7 +21,7 @@ function Schedules({ i18n }) {
|
||||
/>
|
||||
<Switch>
|
||||
<Route path="/schedules">
|
||||
<ScheduleList />
|
||||
<ScheduleList loadSchedules={loadSchedules} />
|
||||
</Route>
|
||||
</Switch>
|
||||
</>
|
||||
|
||||
@ -28,6 +28,7 @@ class Template extends Component {
|
||||
};
|
||||
this.loadTemplate = this.loadTemplate.bind(this);
|
||||
this.loadTemplateAndRoles = this.loadTemplateAndRoles.bind(this);
|
||||
this.loadSchedules = this.loadSchedules.bind(this);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
@ -82,6 +83,11 @@ class Template extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
loadSchedules(params) {
|
||||
const { template } = this.state;
|
||||
return JobTemplatesAPI.readScheduleList(template.id, params);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { i18n, location, match, me } = this.props;
|
||||
const {
|
||||
@ -221,9 +227,7 @@ class Template extends Component {
|
||||
{template && (
|
||||
<Route
|
||||
path="/templates/:templateType/:id/schedules"
|
||||
render={() => (
|
||||
<ScheduleList resource={template} apiModel={JobTemplatesAPI} />
|
||||
)}
|
||||
render={() => <ScheduleList loadSchedules={this.loadSchedules} />}
|
||||
/>
|
||||
)}
|
||||
<Route
|
||||
|
||||
@ -25,6 +25,7 @@ class WorkflowJobTemplate extends Component {
|
||||
template: null,
|
||||
};
|
||||
this.loadTemplate = this.loadTemplate.bind(this);
|
||||
this.loadSchedules = this.loadSchedules.bind(this);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
@ -71,6 +72,11 @@ class WorkflowJobTemplate extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
loadSchedules(params) {
|
||||
const { template } = this.state;
|
||||
return WorkflowJobTemplatesAPI.readScheduleList(template.id, params);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { i18n, location, match } = this.props;
|
||||
const {
|
||||
@ -173,12 +179,7 @@ class WorkflowJobTemplate extends Component {
|
||||
{template && (
|
||||
<Route
|
||||
path="/templates/:templateType/:id/schedules"
|
||||
render={() => (
|
||||
<ScheduleList
|
||||
resource={template}
|
||||
apiModel={WorkflowJobTemplatesAPI}
|
||||
/>
|
||||
)}
|
||||
render={() => <ScheduleList loadSchedules={this.loadSchedules} />}
|
||||
/>
|
||||
)}
|
||||
<Route
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user