Adds searchable keys and related keys

This commit is contained in:
Alex Corey
2020-12-14 14:41:03 -05:00
parent 7e74f823f4
commit 1dbadca78e
3 changed files with 36 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import React, { useCallback, useEffect } from 'react'; import React, { useCallback, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { import {
arrayOf, arrayOf,
bool, bool,
@@ -8,7 +9,6 @@ import {
string, string,
oneOfType, oneOfType,
} from 'prop-types'; } from 'prop-types';
import { withRouter } 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 { FormGroup } from '@patternfly/react-core'; import { FormGroup } from '@patternfly/react-core';
@@ -39,13 +39,13 @@ function CredentialLookup({
credentialTypeKind, credentialTypeKind,
credentialTypeNamespace, credentialTypeNamespace,
value, value,
history,
i18n, i18n,
tooltip, tooltip,
isDisabled, isDisabled,
autoPopulate, autoPopulate,
multiple, multiple,
}) { }) {
const history = useHistory();
const autoPopulateLookup = useAutoPopulateLookup(onChange); const autoPopulateLookup = useAutoPopulateLookup(onChange);
const { const {
result: { count, credentials, relatedSearchableKeys, searchableKeys }, result: { count, credentials, relatedSearchableKeys, searchableKeys },
@@ -72,22 +72,28 @@ function CredentialLookup({
...typeNamespaceParams, ...typeNamespaceParams,
}) })
), ),
CredentialsAPI.readOptions, CredentialsAPI.readOptions(),
]); ]);
if (autoPopulate) { if (autoPopulate) {
autoPopulateLookup(data.results); autoPopulateLookup(data.results);
} }
const searchKeys = Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable);
const item = searchKeys.indexOf('type');
if (item) {
searchKeys[item] = 'credential_type__kind';
}
return { return {
count: data.count, count: data.count,
credentials: data.results, credentials: data.results,
relatedSearchableKeys: ( 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( searchableKeys: searchKeys,
actionsResponse.data?.actions?.GET || {}
).filter(key => actionsResponse.data?.actions?.GET[key]?.filterable),
}; };
}, [ }, [
autoPopulate, autoPopulate,
@@ -222,4 +228,4 @@ CredentialLookup.defaultProps = {
}; };
export { CredentialLookup as _CredentialLookup }; export { CredentialLookup as _CredentialLookup };
export default withI18n()(withRouter(CredentialLookup)); export default withI18n()(CredentialLookup);

View File

@@ -26,7 +26,13 @@ function CredentialList({ i18n }) {
const location = useLocation(); const location = useLocation();
const { const {
result: { credentials, credentialCount, actions }, result: {
credentials,
credentialCount,
actions,
relatedSearchableKeys,
searchableKeys,
},
error: contentError, error: contentError,
isLoading, isLoading,
request: fetchCredentials, request: fetchCredentials,
@@ -37,16 +43,29 @@ function CredentialList({ i18n }) {
CredentialsAPI.read(params), CredentialsAPI.read(params),
CredentialsAPI.readOptions(), CredentialsAPI.readOptions(),
]); ]);
const searchKeys = Object.keys(
credActions.data.actions?.GET || {}
).filter(key => credActions.data.actions?.GET[key].filterable);
const item = searchKeys.indexOf('type');
if (item) {
searchKeys[item] = 'credential_type__kind';
}
return { return {
credentials: creds.data.results, credentials: creds.data.results,
credentialCount: creds.data.count, credentialCount: creds.data.count,
actions: credActions.data.actions, actions: credActions.data.actions,
relatedSearchableKeys: (
credActions?.data?.related_search_fields || []
).map(val => val.slice(0, -8)),
searchableKeys: searchKeys,
}; };
}, [location]), }, [location]),
{ {
credentials: [], credentials: [],
credentialCount: 0, credentialCount: 0,
actions: {}, actions: {},
relatedSearchableKeys: [],
searchableKeys: [],
} }
); );
@@ -102,6 +121,8 @@ function CredentialList({ i18n }) {
itemCount={credentialCount} itemCount={credentialCount}
qsConfig={QS_CONFIG} qsConfig={QS_CONFIG}
onRowClick={handleSelect} onRowClick={handleSelect}
toolbarSearchableKeys={searchableKeys}
toolbarRelatedSearchableKeys={relatedSearchableKeys}
toolbarSearchColumns={[ toolbarSearchColumns={[
{ {
name: i18n._(t`Name`), name: i18n._(t`Name`),

View File

@@ -123,7 +123,7 @@ describe('<ContainerGroupEdit/>', () => {
}); });
test('called InstanceGroupsAPI.readOptions', async () => { test('called InstanceGroupsAPI.readOptions', async () => {
expect(InstanceGroupsAPI.readOptions).toHaveBeenCalledTimes(1); expect(InstanceGroupsAPI.readOptions).toHaveBeenCalled();
}); });
test('handleCancel returns the user to container group detail', async () => { test('handleCancel returns the user to container group detail', async () => {