update ScheduleList api read to single prop

This commit is contained in:
John Mitchell 2020-03-02 09:22:32 -05:00
parent 989ef3538e
commit c1c382a941
6 changed files with 35 additions and 21 deletions

View File

@ -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,

View File

@ -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();
});

View File

@ -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} />
)}
/>
)}

View File

@ -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>
</>

View File

@ -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

View File

@ -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