Skip to content

Commit

Permalink
adds advanced search functionality and lists correct EEs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSCorey committed Apr 29, 2021
1 parent e6bde23 commit 1d44245
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 16,407 deletions.
14 changes: 11 additions & 3 deletions awx/ui_next/src/components/AdHocCommands/AdHocCommands.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,29 @@ function AdHocCommands({ adHocItems, i18n, hasListItems, onLaunchLoading }) {
}, [isKebabified, isWizardOpen, onKebabModalChange]);

const {
result: { moduleOptions, credentialTypeId, isAdHocDisabled },
result: {
moduleOptions,
credentialTypeId,
isAdHocDisabled,
organizationId,
},
request: fetchData,
error: fetchError,
} = useRequest(
useCallback(async () => {
const [options, cred] = await Promise.all([
const [options, { data }, cred] = await Promise.all([
InventoriesAPI.readAdHocOptions(id),
InventoriesAPI.readDetail(id),
CredentialTypesAPI.read({ namespace: 'ssh' }),
]);
return {
moduleOptions: options.data.actions.GET.module_name.choices,
credentialTypeId: cred.data.results[0].id,
isAdHocDisabled: !options.data.actions.POST,
organizationId: data.organization,
};
}, [id]),
{ moduleOptions: [], isAdHocDisabled: true }
{ moduleOptions: [], isAdHocDisabled: true, organizationId: null }
);
useEffect(() => {
fetchData();
Expand Down Expand Up @@ -141,6 +148,7 @@ function AdHocCommands({ adHocItems, i18n, hasListItems, onLaunchLoading }) {
{isWizardOpen && (
<AdHocCommandsWizard
adHocItems={adHocItems}
organizationId={organizationId}
moduleOptions={moduleOptions}
verbosityOptions={verbosityOptions}
credentialTypeId={credentialTypeId}
Expand Down
14 changes: 14 additions & 0 deletions awx/ui_next/src/components/AdHocCommands/AdHocCommands.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('<AdHocCommands />', () => {
},
},
});
InventoriesAPI.readDetail.mockResolvedValue({ data: { organization: 1 } });
CredentialTypesAPI.read.mockResolvedValue({
data: { results: [{ id: 1 }] },
});
Expand Down Expand Up @@ -135,6 +136,10 @@ describe('<AdHocCommands />', () => {

test('should submit properly', async () => {
InventoriesAPI.launchAdHocCommands.mockResolvedValue({ data: { id: 1 } });
InventoriesAPI.readDetail.mockResolvedValue({
data: { organization: 1 },
});

CredentialsAPI.read.mockResolvedValue({
data: {
results: credentials,
Expand All @@ -150,6 +155,9 @@ describe('<AdHocCommands />', () => {
count: 2,
},
});
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue({
data: { actions: { GET: {} } },
});
await act(async () => {
wrapper = mountWithContexts(
<AdHocCommands
Expand Down Expand Up @@ -275,6 +283,9 @@ describe('<AdHocCommands />', () => {
},
},
});
InventoriesAPI.readDetail.mockResolvedValue({
data: { organization: 1 },
});
CredentialTypesAPI.read.mockResolvedValue({
data: {
results: [
Expand Down Expand Up @@ -307,6 +318,9 @@ describe('<AdHocCommands />', () => {
count: 2,
},
});
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue({
data: { actions: { GET: {} } },
});
await act(async () => {
wrapper = mountWithContexts(
<AdHocCommands
Expand Down
31 changes: 18 additions & 13 deletions awx/ui_next/src/components/AdHocCommands/AdHocCommandsWizard.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { withI18n } from '@lingui/react';

import { t } from '@lingui/macro';
import { ExclamationCircleIcon as PFExclamationCircleIcon } from '@patternfly/react-icons';
import { Tooltip } from '@patternfly/react-core';
Expand All @@ -24,11 +24,11 @@ const ExclamationCircleIcon = styled(PFExclamationCircleIcon)`

function AdHocCommandsWizard({
onLaunch,
i18n,
moduleOptions,
verbosityOptions,
onCloseWizard,
credentialTypeId,
organizationId,
}) {
const [currentStepId, setCurrentStepId] = useState(1);
const [enableLaunch, setEnableLaunch] = useState(false);
Expand Down Expand Up @@ -58,17 +58,17 @@ function AdHocCommandsWizard({
key: 1,
name: hasDetailsStepError ? (
<AlertText>
{i18n._(t`Details`)}
{t`Details`}
<Tooltip
position="right"
content={i18n._(t`This step contains errors`)}
content={t`This step contains errors`}
trigger="click mouseenter focus"
>
<ExclamationCircleIcon />
</Tooltip>
</AlertText>
) : (
i18n._(t`Details`)
t`Details`
),
component: (
<AdHocDetailsStep
Expand All @@ -77,28 +77,33 @@ function AdHocCommandsWizard({
/>
),
enableNext: enabledNextOnDetailsStep(),
nextButtonText: i18n._(t`Next`),
nextButtonText: t`Next`,
},
{
id: 2,
key: 2,
name: t`Execution Environment`,
component: <AdHocExecutionEnvironmentStep />,
component: (
<AdHocExecutionEnvironmentStep organizationId={organizationId} />
),
// Removed this line when https://github.com/patternfly/patternfly-react/issues/5729 is fixed
stepNavItemProps: { style: { 'white-space': 'nowrap' } },
enableNext: true,
nextButtonText: t`Next`,
canJumpTo: currentStepId >= 2,
},
{
id: 3,
key: 3,
name: i18n._(t`Machine credential`),
name: t`Machine credential`,
component: (
<AdHocCredentialStep
credentialTypeId={credentialTypeId}
onEnableLaunch={() => setEnableLaunch(true)}
/>
),
enableNext: enableLaunch && Object.values(errors).length === 0,
nextButtonText: i18n._(t`Launch`),
nextButtonText: t`Launch`,
canJumpTo: currentStepId >= 2,
},
];
Expand All @@ -115,10 +120,10 @@ function AdHocCommandsWizard({
onLaunch(values);
}}
steps={steps}
title={i18n._(t`Run command`)}
title={t`Run command`}
nextButtonText={currentStep.nextButtonText || undefined}
backButtonText={i18n._(t`Back`)}
cancelButtonText={i18n._(t`Cancel`)}
backButtonText={t`Back`}
cancelButtonText={t`Cancel`}
/>
);
}
Expand Down Expand Up @@ -149,4 +154,4 @@ FormikApp.propTypes = {
onCloseWizard: PropTypes.func.isRequired,
credentialTypeId: PropTypes.number.isRequired,
};
export default withI18n()(FormikApp);
export default FormikApp;
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('<AdHocCommandsWizard/>', () => {
verbosityOptions={verbosityOptions}
onCloseWizard={() => {}}
credentialTypeId={1}
organizationId={1}
/>
);
});
Expand Down Expand Up @@ -108,6 +109,9 @@ describe('<AdHocCommandsWizard/>', () => {
count: 2,
},
});
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue({
data: { actions: { GET: {} } },
});
CredentialsAPI.read.mockResolvedValue({
data: {
results: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ describe('<AdHocExecutionEnvironmentStep />', () => {
count: 2,
},
});
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue({
data: { actions: { GET: {} } },
});
await act(async () => {
wrapper = mountWithContexts(
<Formik>
<AdHocExecutionEnvironmentStep />
<AdHocExecutionEnvironmentStep organizationId={1} />
</Formik>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { Form, FormGroup } from '@patternfly/react-core';
import { ExecutionEnvironmentsAPI } from '../../api';
import Popover from '../Popover';

import { parseQueryString, getQSConfig } from '../../util/qs';
import { parseQueryString, getQSConfig, mergeParams } from '../../util/qs';
import useRequest from '../../util/useRequest';
import ContentError from '../ContentError';
import ContentLoading from '../ContentLoading';
import OptionsList from '../OptionsList';

const QS_CONFIG = getQSConfig('execution_environemts', {
const QS_CONFIG = getQSConfig('execution_environments', {
page: 1,
page_size: 5,
order_by: 'name',
});
function AdHocExecutionEnvironmentStep() {
function AdHocExecutionEnvironmentStep({ organizationId }) {
const history = useHistory();
const [executionEnvironmentField, , executionEnvironmentHelpers] = useField(
'execution_environment'
Expand All @@ -26,21 +26,51 @@ function AdHocExecutionEnvironmentStep() {
error,
isLoading,
request: fetchExecutionEnvironments,
result: { executionEnvironments, executionEnvironmentsCount },
result: {
executionEnvironments,
executionEnvironmentsCount,
relatedSearchableKeys,
searchableKeys,
},
} = useRequest(
useCallback(async () => {
const params = parseQueryString(QS_CONFIG, history.location.search);
const globallyAvailableParams = { or__organization__isnull: 'True' };
const organizationIdParams = organizationId
? { or__organization__id: organizationId }
: {};

const {
data: { results, count },
} = await ExecutionEnvironmentsAPI.read(params);

const [
{
data: { results, count },
},
actionsResponse,
] = await Promise.all([
ExecutionEnvironmentsAPI.read(
mergeParams(params, {
...globallyAvailableParams,
...organizationIdParams,
})
),
ExecutionEnvironmentsAPI.readOptions(),
]);
return {
executionEnvironments: results,
executionEnvironmentsCount: count,
relatedSearchableKeys: (
actionsResponse?.data?.related_search_fields || []
).map(val => val.slice(0, -8)),
searchableKeys: Object.keys(
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
};
}, [history.location.search]),
{ executionEnvironments: [], executionEnvironmentsCount: 0 }
}, [history.location.search, organizationId]),
{
executionEnvironments: [],
executionEnvironmentsCount: 0,
relatedSearchableKeys: [],
searchableKeys: [],
}
);

useEffect(() => {
Expand All @@ -62,11 +92,12 @@ function AdHocExecutionEnvironmentStep() {
aria-label={t`Execution Environments`}
labelIcon={
<Popover
content={t`Select the Execution Environment you want this command to run inside`}
content={t`Select the Execution Environment you want this command to run inside.`}
/>
}
>
<OptionsList
isLoading={isLoading}
value={executionEnvironmentField.value || []}
options={executionEnvironments}
optionCount={executionEnvironmentsCount}
Expand All @@ -75,7 +106,7 @@ function AdHocExecutionEnvironmentStep() {
searchColumns={[
{
name: t`Name`,
key: 'name',
key: 'name__icontains',
isDefault: true,
},
{
Expand All @@ -94,6 +125,8 @@ function AdHocExecutionEnvironmentStep() {
},
]}
name="execution_environment"
searchableKeys={searchableKeys}
relatedSearchableKeys={relatedSearchableKeys}
selectItem={value => {
executionEnvironmentHelpers.setValue([value]);
}}
Expand Down
Loading

0 comments on commit 1d44245

Please sign in to comment.