mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 06:29:31 -02:30
Merge pull request #7745 from mabashian/convert-WFJTList-useRequest
Converts WorkflowJobTemplatesList to use useRequest in preparation for advanced search Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useEffect, useCallback } from 'react';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { func, shape } from 'prop-types';
|
import { func, shape } from 'prop-types';
|
||||||
import { WorkflowJobTemplatesAPI } from '../../../../../../api';
|
import { WorkflowJobTemplatesAPI } from '../../../../../../api';
|
||||||
import { getQSConfig, parseQueryString } from '../../../../../../util/qs';
|
import { getQSConfig, parseQueryString } from '../../../../../../util/qs';
|
||||||
|
import useRequest from '../../../../../../util/useRequest';
|
||||||
import PaginatedDataList from '../../../../../../components/PaginatedDataList';
|
import PaginatedDataList from '../../../../../../components/PaginatedDataList';
|
||||||
import DataListToolbar from '../../../../../../components/DataListToolbar';
|
import DataListToolbar from '../../../../../../components/DataListToolbar';
|
||||||
import CheckboxListItem from '../../../../../../components/CheckboxListItem';
|
import CheckboxListItem from '../../../../../../components/CheckboxListItem';
|
||||||
@@ -20,32 +21,33 @@ function WorkflowJobTemplatesList({
|
|||||||
nodeResource,
|
nodeResource,
|
||||||
onUpdateNodeResource,
|
onUpdateNodeResource,
|
||||||
}) {
|
}) {
|
||||||
const [count, setCount] = useState(0);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [workflowJobTemplates, setWorkflowJobTemplates] = useState([]);
|
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
const {
|
||||||
(async () => {
|
result: { workflowJobTemplates, count },
|
||||||
setIsLoading(true);
|
error,
|
||||||
setWorkflowJobTemplates([]);
|
isLoading,
|
||||||
setCount(0);
|
request: fetchWorkflowJobTemplates,
|
||||||
|
} = useRequest(
|
||||||
|
useCallback(async () => {
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
const params = parseQueryString(QS_CONFIG, location.search);
|
||||||
try {
|
const results = await WorkflowJobTemplatesAPI.read(params, {
|
||||||
const { data } = await WorkflowJobTemplatesAPI.read(params, {
|
role_level: 'execute_role',
|
||||||
role_level: 'execute_role',
|
});
|
||||||
});
|
return {
|
||||||
setWorkflowJobTemplates(data.results);
|
workflowJobTemplates: results.data.results,
|
||||||
setCount(data.count);
|
count: results.data.count,
|
||||||
} catch (err) {
|
};
|
||||||
setError(err);
|
}, [location]),
|
||||||
} finally {
|
{
|
||||||
setIsLoading(false);
|
workflowJobTemplates: [],
|
||||||
}
|
count: 0,
|
||||||
})();
|
}
|
||||||
}, [location]);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchWorkflowJobTemplates();
|
||||||
|
}, [fetchWorkflowJobTemplates]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PaginatedDataList
|
<PaginatedDataList
|
||||||
@@ -76,19 +78,19 @@ function WorkflowJobTemplatesList({
|
|||||||
isDefault: true,
|
isDefault: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Organization (Name)`),
|
name: i18n._(t`Organization (name)`),
|
||||||
key: 'organization__name',
|
key: 'organization__name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Inventory (Name)`),
|
name: i18n._(t`Inventory (name)`),
|
||||||
key: 'inventory__name',
|
key: 'inventory__name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Created By (Username)`),
|
name: i18n._(t`Created by (username)`),
|
||||||
key: 'created_by__username',
|
key: 'created_by__username',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Modified By (Username)`),
|
name: i18n._(t`Modified by (username)`),
|
||||||
key: 'modified_by__username',
|
key: 'modified_by__username',
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|||||||
Reference in New Issue
Block a user