update existing relatedSearchKey requests to new convention and fix UJT searchKeys

This commit is contained in:
John Mitchell
2020-08-12 12:21:10 -04:00
parent 9c13c07169
commit dd68b6ed73
26 changed files with 267 additions and 232 deletions

View File

@@ -38,7 +38,7 @@ function JobList({ i18n, defaultParams, showTypeColumn = false }) {
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const location = useLocation(); const location = useLocation();
const { const {
result: { results, count, actions, relatedSearchFields }, result: { results, count, relatedSearchableKeys, searchableKeys },
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchJobs, request: fetchJobs,
@@ -53,10 +53,12 @@ function JobList({ i18n, defaultParams, showTypeColumn = false }) {
return { return {
results: response.data.results, results: response.data.results,
count: response.data.count, count: response.data.count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, },
[location] // eslint-disable-line react-hooks/exhaustive-deps [location] // eslint-disable-line react-hooks/exhaustive-deps
@@ -64,8 +66,8 @@ function JobList({ i18n, defaultParams, showTypeColumn = false }) {
{ {
results: [], results: [],
count: 0, count: 0,
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
useEffect(() => { useEffect(() => {
@@ -138,11 +140,6 @@ function JobList({ i18n, defaultParams, showTypeColumn = false }) {
} }
}; };
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>
<Card> <Card>

View File

@@ -52,7 +52,7 @@ function CredentialsStep({ i18n }) {
}, [fetchTypes]); }, [fetchTypes]);
const { const {
result: { credentials, count, actions, relatedSearchFields }, result: { credentials, count, relatedSearchableKeys, searchableKeys },
error: credentialsError, error: credentialsError,
isLoading: isCredentialsLoading, isLoading: isCredentialsLoading,
request: fetchCredentials, request: fetchCredentials,
@@ -72,13 +72,15 @@ function CredentialsStep({ i18n }) {
return { return {
credentials: data.results, credentials: data.results,
count: data.count, count: data.count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [selectedType, history.location.search]), }, [selectedType, history.location.search]),
{ credentials: [], count: 0, actions: {}, relatedSearchFields: [] } { credentials: [], count: 0, relatedSearchableKeys: [], searchableKeys: [] }
); );
useEffect(() => { useEffect(() => {
@@ -104,11 +106,6 @@ function CredentialsStep({ i18n }) {
/> />
); );
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>
{types && types.length > 0 && ( {types && types.length > 0 && (

View File

@@ -27,7 +27,7 @@ function InventoryStep({ i18n }) {
const { const {
isLoading, isLoading,
error, error,
result: { inventories, count, actions, relatedSearchFields }, result: { inventories, count, relatedSearchableKeys, searchableKeys },
request: fetchInventories, request: fetchInventories,
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
@@ -39,17 +39,19 @@ function InventoryStep({ i18n }) {
return { return {
inventories: data.results, inventories: data.results,
count: data.count, count: data.count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [history.location]), }, [history.location]),
{ {
count: 0, count: 0,
inventories: [], inventories: [],
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
@@ -57,11 +59,6 @@ function InventoryStep({ i18n }) {
fetchInventories(); fetchInventories();
}, [fetchInventories]); }, [fetchInventories]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
if (isLoading) { if (isLoading) {
return <ContentLoading />; return <ContentLoading />;
} }

View File

@@ -22,7 +22,7 @@ function ApplicationLookup({ i18n, onChange, value, label }) {
const location = useLocation(); const location = useLocation();
const { const {
error, error,
result: { applications, itemCount, actions, relatedSearchFields }, result: { applications, itemCount, relatedSearchableKeys, searchableKeys },
request: fetchApplications, request: fetchApplications,
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
@@ -40,23 +40,24 @@ function ApplicationLookup({ i18n, onChange, value, label }) {
return { return {
applications: results, applications: results,
itemCount: count, itemCount: count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [location]), }, [location]),
{ applications: [], itemCount: 0, actions: {}, relatedSearchFields: [] } {
applications: [],
itemCount: 0,
relatedSearchableKeys: [],
searchableKeys: [],
}
); );
useEffect(() => { useEffect(() => {
fetchApplications(); fetchApplications();
}, [fetchApplications]); }, [fetchApplications]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<FormGroup fieldId="application" label={label}> <FormGroup fieldId="application" label={label}>
<Lookup <Lookup

View File

@@ -35,7 +35,7 @@ function CredentialLookup({
tooltip, tooltip,
}) { }) {
const { const {
result: { count, credentials, actions, relatedSearchFields }, result: { count, credentials, relatedSearchableKeys, searchableKeys },
error, error,
request: fetchCredentials, request: fetchCredentials,
} = useRequest( } = useRequest(
@@ -64,10 +64,12 @@ function CredentialLookup({
return { return {
count: data.count, count: data.count,
credentials: data.results, credentials: data.results,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [ }, [
credentialTypeId, credentialTypeId,
@@ -78,8 +80,8 @@ function CredentialLookup({
{ {
count: 0, count: 0,
credentials: [], credentials: [],
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
@@ -87,11 +89,6 @@ function CredentialLookup({
fetchCredentials(); fetchCredentials();
}, [fetchCredentials]); }, [fetchCredentials]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
// TODO: replace credential type search with REST-based grabbing of cred types // TODO: replace credential type search with REST-based grabbing of cred types
return ( return (

View File

@@ -30,7 +30,7 @@ function InstanceGroupsLookup(props) {
} = props; } = props;
const { const {
result: { instanceGroups, count, actions, relatedSearchFields }, result: { instanceGroups, count, relatedSearchableKeys, searchableKeys },
request: fetchInstanceGroups, request: fetchInstanceGroups,
error, error,
isLoading, isLoading,
@@ -44,24 +44,26 @@ function InstanceGroupsLookup(props) {
return { return {
instanceGroups: data.results, instanceGroups: data.results,
count: data.count, count: data.count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [history.location]), }, [history.location]),
{ instanceGroups: [], count: 0, actions: {}, relatedSearchFields: [] } {
instanceGroups: [],
count: 0,
relatedSearchableKeys: [],
searchableKeys: [],
}
); );
useEffect(() => { useEffect(() => {
fetchInstanceGroups(); fetchInstanceGroups();
}, [fetchInstanceGroups]); }, [fetchInstanceGroups]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<FormGroup <FormGroup
className={className} className={className}

View File

@@ -19,7 +19,7 @@ const QS_CONFIG = getQSConfig('inventory', {
function InventoryLookup({ value, onChange, onBlur, required, i18n, history }) { function InventoryLookup({ value, onChange, onBlur, required, i18n, history }) {
const { const {
result: { inventories, count, actions, relatedSearchFields }, result: { inventories, count, relatedSearchableKeys, searchableKeys },
request: fetchInventories, request: fetchInventories,
error, error,
isLoading, isLoading,
@@ -33,24 +33,21 @@ function InventoryLookup({ value, onChange, onBlur, required, i18n, history }) {
return { return {
inventories: data.results, inventories: data.results,
count: data.count, count: data.count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [history.location]), }, [history.location]),
{ inventories: [], count: 0, actions: {}, relatedSearchFields: [] } { inventories: [], count: 0, relatedSearchableKeys: [], searchableKeys: [] }
); );
useEffect(() => { useEffect(() => {
fetchInventories(); fetchInventories();
}, [fetchInventories]); }, [fetchInventories]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>
<Lookup <Lookup

View File

@@ -49,7 +49,12 @@ function MultiCredentialsLookup(props) {
}, [fetchTypes]); }, [fetchTypes]);
const { const {
result: { credentials, credentialsCount, actions, relatedSearchFields }, result: {
credentials,
credentialsCount,
relatedSearchableKeys,
searchableKeys,
},
request: fetchCredentials, request: fetchCredentials,
error: credentialsError, error: credentialsError,
isLoading: isCredentialsLoading, isLoading: isCredentialsLoading,
@@ -69,17 +74,19 @@ function MultiCredentialsLookup(props) {
return { return {
credentials: results, credentials: results,
credentialsCount: count, credentialsCount: count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [selectedType, history.location]), }, [selectedType, history.location]),
{ {
credentials: [], credentials: [],
credentialsCount: 0, credentialsCount: 0,
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
@@ -104,11 +111,6 @@ function MultiCredentialsLookup(props) {
const isVault = selectedType?.kind === 'vault'; const isVault = selectedType?.kind === 'vault';
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<Lookup <Lookup
id="multiCredential" id="multiCredential"

View File

@@ -32,7 +32,7 @@ function ProjectLookup({
history, history,
}) { }) {
const { const {
result: { projects, count, actions, relatedSearchFields }, result: { projects, count, relatedSearchableKeys, searchableKeys },
request: fetchProjects, request: fetchProjects,
error, error,
isLoading, isLoading,
@@ -49,17 +49,19 @@ function ProjectLookup({
return { return {
count: data.count, count: data.count,
projects: data.results, projects: data.results,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [history.location.search, autocomplete]), }, [history.location.search, autocomplete]),
{ {
count: 0, count: 0,
projects: [], projects: [],
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
@@ -67,11 +69,6 @@ function ProjectLookup({
fetchProjects(); fetchProjects();
}, [fetchProjects]); }, [fetchProjects]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<FormGroup <FormGroup
fieldId="project" fieldId="project"

View File

@@ -32,7 +32,13 @@ function ScheduleList({
const location = useLocation(); const location = useLocation();
const { const {
result: { schedules, itemCount, actions, relatedSearchFields }, result: {
schedules,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchSchedules, request: fetchSchedules,
@@ -49,16 +55,20 @@ function ScheduleList({
schedules: results, schedules: results,
itemCount: count, itemCount: count,
actions: scheduleActions.data.actions, actions: scheduleActions.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
scheduleActions?.data?.related_search_fields || [] scheduleActions?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
scheduleActions.data.actions?.GET || {}
).filter(key => scheduleActions.data.actions?.GET[key].filterable),
}; };
}, [location, loadSchedules, loadScheduleOptions]), }, [location, loadSchedules, loadScheduleOptions]),
{ {
schedules: [], schedules: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -106,10 +116,6 @@ function ScheduleList({
actions && actions &&
Object.prototype.hasOwnProperty.call(actions, 'POST') && Object.prototype.hasOwnProperty.call(actions, 'POST') &&
!hideAddButton; !hideAddButton;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>

View File

@@ -26,7 +26,7 @@ function ApplicationTokenList({ i18n }) {
const { const {
error, error,
isLoading, isLoading,
result: { tokens, itemCount, actions, relatedSearchFields }, result: { tokens, itemCount, relatedSearchableKeys, searchableKeys },
request: fetchTokens, request: fetchTokens,
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
@@ -52,13 +52,15 @@ function ApplicationTokenList({ i18n }) {
return { return {
tokens: modifiedResults, tokens: modifiedResults,
itemCount: count, itemCount: count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [id, location.search]), }, [id, location.search]),
{ tokens: [], itemCount: 0, actions: {}, relatedSearchFields: [] } { tokens: [], itemCount: 0, relatedSearchableKeys: [], searchableKeys: [] }
); );
useEffect(() => { useEffect(() => {
@@ -91,11 +93,6 @@ function ApplicationTokenList({ i18n }) {
setSelected([]); setSelected([]);
}; };
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>
<PaginatedDataList <PaginatedDataList

View File

@@ -32,7 +32,13 @@ function ApplicationsList({ i18n }) {
isLoading, isLoading,
error, error,
request: fetchApplications, request: fetchApplications,
result: { applications, itemCount, actions, relatedSearchFields }, result: {
applications,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
const params = parseQueryString(QS_CONFIG, location.search); const params = parseQueryString(QS_CONFIG, location.search);
@@ -46,16 +52,20 @@ function ApplicationsList({ i18n }) {
applications: response.data.results, applications: response.data.results,
itemCount: response.data.count, itemCount: response.data.count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [location]), }, [location]),
{ {
applications: [], applications: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -89,10 +99,6 @@ function ApplicationsList({ i18n }) {
}; };
const canAdd = actions && actions.POST; const canAdd = actions && actions.POST;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>

View File

@@ -25,7 +25,7 @@ function CredentialsStep({ i18n }) {
const history = useHistory(); const history = useHistory();
const { const {
result: { credentials, count, actions, relatedSearchFields }, result: { credentials, count, relatedSearchableKeys, searchableKeys },
error: credentialsError, error: credentialsError,
isLoading: isCredentialsLoading, isLoading: isCredentialsLoading,
request: fetchCredentials, request: fetchCredentials,
@@ -39,24 +39,21 @@ function CredentialsStep({ i18n }) {
return { return {
credentials: data.results, credentials: data.results,
count: data.count, count: data.count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [history.location.search]), }, [history.location.search]),
{ credentials: [], count: 0, actions: {}, relatedSearchFields: [] } { credentials: [], count: 0, relatedSearchableKeys: [], searchableKeys: [] }
); );
useEffect(() => { useEffect(() => {
fetchCredentials(); fetchCredentials();
}, [fetchCredentials]); }, [fetchCredentials]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
if (credentialsError) { if (credentialsError) {
return <ContentError error={credentialsError} />; return <ContentError error={credentialsError} />;
} }

View File

@@ -33,7 +33,13 @@ function HostGroupsList({ i18n, host }) {
const invId = host.summary_fields.inventory.id; const invId = host.summary_fields.inventory.id;
const { const {
result: { groups, itemCount, actions, relatedSearchFields }, result: {
groups,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchGroups, request: fetchGroups,
@@ -55,16 +61,20 @@ function HostGroupsList({ i18n, host }) {
groups: results, groups: results,
itemCount: count, itemCount: count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [hostId, search]), }, [hostId, search]),
{ {
groups: [], groups: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -128,10 +138,6 @@ function HostGroupsList({ i18n, host }) {
const canAdd = const canAdd =
actions && Object.prototype.hasOwnProperty.call(actions, 'POST'); actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>

View File

@@ -29,7 +29,7 @@ function HostList({ i18n }) {
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const { const {
result: { hosts, count, actions, relatedSearchFields }, result: { hosts, count, actions, relatedSearchableKeys, searchableKeys },
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchHosts, request: fetchHosts,
@@ -44,16 +44,20 @@ function HostList({ i18n }) {
hosts: results[0].data.results, hosts: results[0].data.results,
count: results[0].data.count, count: results[0].data.count,
actions: results[1].data.actions, actions: results[1].data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
results[1]?.data?.related_search_fields || [] results[1]?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(results[1].data.actions?.GET || {}).filter(
key => results[1].data.actions?.GET[key].filterable
),
}; };
}, [location]), }, [location]),
{ {
hosts: [], hosts: [],
count: 0, count: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -97,10 +101,6 @@ function HostList({ i18n }) {
const canAdd = const canAdd =
actions && Object.prototype.hasOwnProperty.call(actions, 'POST'); actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<PageSection> <PageSection>

View File

@@ -32,7 +32,13 @@ function InventoryGroupHostList({ i18n }) {
const history = useHistory(); const history = useHistory();
const { const {
result: { hosts, hostCount, actions, relatedSearchFields }, result: {
hosts,
hostCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchHosts, request: fetchHosts,
@@ -48,16 +54,20 @@ function InventoryGroupHostList({ i18n }) {
hosts: response.data.results, hosts: response.data.results,
hostCount: response.data.count, hostCount: response.data.count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [groupId, inventoryId, location.search]), }, [groupId, inventoryId, location.search]),
{ {
hosts: [], hosts: [],
hostCount: 0, hostCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -127,10 +137,6 @@ function InventoryGroupHostList({ i18n }) {
const canAdd = const canAdd =
actions && Object.prototype.hasOwnProperty.call(actions, 'POST'); actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
const addFormUrl = `/inventories/inventory/${inventoryId}/groups/${groupId}/nested_hosts/add`; const addFormUrl = `/inventories/inventory/${inventoryId}/groups/${groupId}/nested_hosts/add`;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>

View File

@@ -31,7 +31,13 @@ function InventoryHostGroupsList({ i18n }) {
const { search } = useLocation(); const { search } = useLocation();
const { const {
result: { groups, itemCount, actions, relatedSearchFields }, result: {
groups,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchGroups, request: fetchGroups,
@@ -53,16 +59,20 @@ function InventoryHostGroupsList({ i18n }) {
groups: results, groups: results,
itemCount: count, itemCount: count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [hostId, search]), // eslint-disable-line react-hooks/exhaustive-deps }, [hostId, search]), // eslint-disable-line react-hooks/exhaustive-deps
{ {
groups: [], groups: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -126,10 +136,6 @@ function InventoryHostGroupsList({ i18n }) {
const canAdd = const canAdd =
actions && Object.prototype.hasOwnProperty.call(actions, 'POST'); actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>

View File

@@ -29,7 +29,13 @@ function InventoryList({ i18n }) {
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const { const {
result: { results, itemCount, actions, relatedSearchFields }, result: {
results,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchInventories, request: fetchInventories,
@@ -44,16 +50,20 @@ function InventoryList({ i18n }) {
results: response.data.results, results: response.data.results,
itemCount: response.data.count, itemCount: response.data.count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [location]), }, [location]),
{ {
results: [], results: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -97,10 +107,6 @@ function InventoryList({ i18n }) {
const hasContentLoading = isDeleteLoading || isLoading; const hasContentLoading = isDeleteLoading || isLoading;
const canAdd = actions && actions.POST; const canAdd = actions && actions.POST;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
const handleSelectAll = isSelected => { const handleSelectAll = isSelected => {
setSelected(isSelected ? [...inventories] : []); setSelected(isSelected ? [...inventories] : []);

View File

@@ -31,7 +31,13 @@ function OrganizationsList({ i18n }) {
const addUrl = `${match.url}/add`; const addUrl = `${match.url}/add`;
const { const {
result: { organizations, organizationCount, actions, relatedSearchFields }, result: {
organizations,
organizationCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading: isOrgsLoading, isLoading: isOrgsLoading,
request: fetchOrganizations, request: fetchOrganizations,
@@ -46,16 +52,20 @@ function OrganizationsList({ i18n }) {
organizations: orgs.data.results, organizations: orgs.data.results,
organizationCount: orgs.data.count, organizationCount: orgs.data.count,
actions: orgActions.data.actions, actions: orgActions.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
orgActions?.data?.related_search_fields || [] orgActions?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(orgActions.data.actions?.GET || {}).filter(
key => orgActions.data.actions?.GET[key].filterable
),
}; };
}, [location]), }, [location]),
{ {
organizations: [], organizations: [],
organizationCount: 0, organizationCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -90,10 +100,6 @@ function OrganizationsList({ i18n }) {
const hasContentLoading = isDeleteLoading || isOrgsLoading; const hasContentLoading = isDeleteLoading || isOrgsLoading;
const canAdd = actions && actions.POST; const canAdd = actions && actions.POST;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
const handleSelectAll = isSelected => { const handleSelectAll = isSelected => {
setSelected(isSelected ? [...organizations] : []); setSelected(isSelected ? [...organizations] : []);

View File

@@ -30,7 +30,13 @@ function ProjectList({ i18n }) {
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const { const {
result: { results, itemCount, actions, relatedSearchFields }, result: {
results,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchProjects, request: fetchProjects,
@@ -45,16 +51,20 @@ function ProjectList({ i18n }) {
results: response.data.results, results: response.data.results,
itemCount: response.data.count, itemCount: response.data.count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [location]), }, [location]),
{ {
results: [], results: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -89,10 +99,6 @@ function ProjectList({ i18n }) {
const hasContentLoading = isDeleteLoading || isLoading; const hasContentLoading = isDeleteLoading || isLoading;
const canAdd = actions && actions.POST; const canAdd = actions && actions.POST;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
const handleSelectAll = isSelected => { const handleSelectAll = isSelected => {
setSelected(isSelected ? [...projects] : []); setSelected(isSelected ? [...projects] : []);

View File

@@ -29,7 +29,13 @@ function TeamList({ i18n }) {
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const { const {
result: { teams, itemCount, actions, relatedSearchFields }, result: {
teams,
itemCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchTeams, request: fetchTeams,
@@ -44,16 +50,20 @@ function TeamList({ i18n }) {
teams: response.data.results, teams: response.data.results,
itemCount: response.data.count, itemCount: response.data.count,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [location]), }, [location]),
{ {
teams: [], teams: [],
itemCount: 0, itemCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -85,10 +95,6 @@ function TeamList({ i18n }) {
const hasContentLoading = isDeleteLoading || isLoading; const hasContentLoading = isDeleteLoading || isLoading;
const canAdd = actions && actions.POST; const canAdd = actions && actions.POST;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
const handleSelectAll = isSelected => { const handleSelectAll = isSelected => {
setSelected(isSelected ? [...teams] : []); setSelected(isSelected ? [...teams] : []);

View File

@@ -37,7 +37,13 @@ function TeamRolesList({ i18n, me, team }) {
isLoading, isLoading,
request: fetchRoles, request: fetchRoles,
contentError, contentError,
result: { roleCount, roles, isAdminOfOrg, actions, relatedSearchFields }, result: {
roleCount,
roles,
isAdminOfOrg,
relatedSearchableKeys,
searchableKeys,
},
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
const params = parseQueryString(QS_CONFIG, search); const params = parseQueryString(QS_CONFIG, search);
@@ -58,18 +64,20 @@ function TeamRolesList({ i18n, me, team }) {
roleCount: count, roleCount: count,
roles: results, roles: results,
isAdminOfOrg: orgAdminCount > 0, isAdminOfOrg: orgAdminCount > 0,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [me.id, team.id, team.organization, search]), }, [me.id, team.id, team.organization, search]),
{ {
roles: [], roles: [],
roleCount: 0, roleCount: 0,
isAdminOfOrg: false, isAdminOfOrg: false,
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
@@ -98,11 +106,6 @@ function TeamRolesList({ i18n, me, team }) {
); );
const canAdd = team?.summary_fields?.user_capabilities?.edit || isAdminOfOrg; const canAdd = team?.summary_fields?.user_capabilities?.edit || isAdminOfOrg;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
const detailUrl = role => { const detailUrl = role => {
const { resource_id, resource_type } = role.summary_fields; const { resource_id, resource_type } = role.summary_fields;

View File

@@ -36,7 +36,14 @@ function TemplateList({ i18n }) {
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const { const {
result: { results, count, jtActions, wfjtActions, relatedSearchFields }, result: {
results,
count,
jtActions,
wfjtActions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchTemplates, request: fetchTemplates,
@@ -47,20 +54,19 @@ function TemplateList({ i18n }) {
UnifiedJobTemplatesAPI.read(params), UnifiedJobTemplatesAPI.read(params),
JobTemplatesAPI.readOptions(), JobTemplatesAPI.readOptions(),
WorkflowJobTemplatesAPI.readOptions(), WorkflowJobTemplatesAPI.readOptions(),
UnifiedJobTemplatesAPI.readOptions(),
]); ]);
return { return {
results: responses[0].data.results, results: responses[0].data.results,
count: responses[0].data.count, count: responses[0].data.count,
jtActions: responses[1].data.actions, jtActions: responses[1].data.actions,
wfjtActions: responses[2].data.actions, wfjtActions: responses[2].data.actions,
relatedSearchFields: [ relatedSearchableKeys: (
...(responses[1]?.data?.related_search_fields || []).map(val => responses[3]?.data?.related_search_fields || []
val.slice(0, -8) ).map(val => val.slice(0, -8)),
), searchableKeys: Object.keys(
...(responses[2]?.data?.related_search_fields || []).map(val => responses[3].data.actions?.GET || {}
val.slice(0, -8) ).filter(key => responses[3].data.actions?.GET[key].filterable),
),
],
}; };
}, [location]), }, [location]),
{ {
@@ -68,7 +74,8 @@ function TemplateList({ i18n }) {
count: 0, count: 0,
jtActions: {}, jtActions: {},
wfjtActions: {}, wfjtActions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -128,17 +135,6 @@ function TemplateList({ i18n }) {
const canAddWFJT = const canAddWFJT =
wfjtActions && Object.prototype.hasOwnProperty.call(wfjtActions, 'POST'); wfjtActions && Object.prototype.hasOwnProperty.call(wfjtActions, 'POST');
// spreading Set() returns only unique keys // spreading Set() returns only unique keys
const relatedSearchableKeys = [...new Set(relatedSearchFields)] || [];
const searchableKeys = [
...new Set([
...Object.keys(jtActions?.GET || {}).filter(
key => jtActions.GET[key].filterable
),
...Object.keys(wfjtActions?.GET || {}).filter(
key => wfjtActions.GET[key].filterable
),
]),
];
const addButtonOptions = []; const addButtonOptions = [];
if (canAddJT) { if (canAddJT) {

View File

@@ -38,7 +38,13 @@ function UserAccessList({ i18n, user }) {
isLoading, isLoading,
request: fetchRoles, request: fetchRoles,
error, error,
result: { roleCount, roles, actions, relatedSearchFields }, result: {
roleCount,
roles,
actions,
relatedSearchableKeys,
searchableKeys,
},
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
const params = parseQueryString(QS_CONFIG, search); const params = parseQueryString(QS_CONFIG, search);
@@ -55,16 +61,20 @@ function UserAccessList({ i18n, user }) {
roleCount: count, roleCount: count,
roles: results, roles: results,
actions: actionsResponse.data.actions, actions: actionsResponse.data.actions,
relatedSearchFields: ( relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [user.id, search]), }, [user.id, search]),
{ {
roles: [], roles: [],
roleCount: 0, roleCount: 0,
actions: {}, actions: {},
relatedSearchFields: [], relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -92,11 +102,6 @@ function UserAccessList({ i18n, user }) {
user?.summary_fields?.user_capabilities?.edit || user?.summary_fields?.user_capabilities?.edit ||
(actions && Object.prototype.hasOwnProperty.call(actions, 'POST')); (actions && Object.prototype.hasOwnProperty.call(actions, 'POST'));
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
const saveRoles = () => { const saveRoles = () => {
setIsWizardOpen(false); setIsWizardOpen(false);
fetchRoles(); fetchRoles();

View File

@@ -20,7 +20,7 @@ function UserTeamList({ i18n }) {
const { id: userId } = useParams(); const { id: userId } = useParams();
const { const {
result: { teams, count, actions, relatedSearchFields }, result: { teams, count, relatedSearchableKeys, searchableKeys },
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchOrgs, request: fetchOrgs,
@@ -39,17 +39,19 @@ function UserTeamList({ i18n }) {
return { return {
teams: results, teams: results,
count: teamCount, count: teamCount,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [userId, location.search]), }, [userId, location.search]),
{ {
teams: [], teams: [],
count: 0, count: 0,
actions: {}, relatedSearchableKeys: [],
relatedSearchFields: [], searchableKeys: [],
} }
); );
@@ -57,11 +59,6 @@ function UserTeamList({ i18n }) {
fetchOrgs(); fetchOrgs();
}, [fetchOrgs]); }, [fetchOrgs]);
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<PaginatedDataList <PaginatedDataList
items={teams} items={teams}

View File

@@ -28,7 +28,7 @@ function UserTokenList({ i18n }) {
error, error,
isLoading, isLoading,
request: fetchTokens, request: fetchTokens,
result: { tokens, itemCount, actions, relatedSearchFields }, result: { tokens, itemCount, relatedSearchableKeys, searchableKeys },
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
const params = parseQueryString(QS_CONFIG, location.search); const params = parseQueryString(QS_CONFIG, location.search);
@@ -53,13 +53,15 @@ function UserTokenList({ i18n }) {
return { return {
tokens: modifiedResults, tokens: modifiedResults,
itemCount: count, itemCount: count,
actions: actionsResponse.data.actions, relatedSearchableKeys: (
relatedSearchFields: (
actionsResponse?.data?.related_search_fields || [] actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)), ).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
}; };
}, [id, location.search]), }, [id, location.search]),
{ tokens: [], itemCount: 0, actions: {}, relatedSearchFields: [] } { tokens: [], itemCount: 0, relatedSearchableKeys: [], searchableKeys: [] }
); );
useEffect(() => { useEffect(() => {
@@ -93,10 +95,7 @@ function UserTokenList({ i18n }) {
}; };
const canAdd = true; const canAdd = true;
const relatedSearchableKeys = relatedSearchFields || [];
const searchableKeys = Object.keys(actions?.GET || {}).filter(
key => actions.GET[key].filterable
);
return ( return (
<> <>
<PaginatedDataList <PaginatedDataList