Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter EE also by Organization for JT #9777

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions awx/ui_next/src/components/Lookup/ExecutionEnvironmentLookup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,21 @@ function ExecutionEnvironmentLookup({
const globallyAvailableParams = globallyAvailable
? { or__organization__isnull: 'True' }
: {};
const organizationIdParams =
organizationId || project?.organization
? { or__organization__id: organizationId }
const organizationIdParams = organizationId
? { or__organization__id: organizationId }
: {};
const projectIdParams =
projectId && project?.organization
? {
or__organization__id: project.organization,
}
: {};
const [{ data }, actionsResponse] = await Promise.all([
ExecutionEnvironmentsAPI.read(
mergeParams(params, {
...globallyAvailableParams,
...organizationIdParams,
...projectIdParams,
})
),
ExecutionEnvironmentsAPI.readOptions(),
Expand All @@ -98,7 +104,7 @@ function ExecutionEnvironmentLookup({
actionsResponse.data.actions?.GET || {}
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
};
}, [location, globallyAvailable, organizationId, project]),
}, [location, globallyAvailable, organizationId, projectId, project]),
{
executionEnvironments: [],
count: 0,
Expand Down Expand Up @@ -174,7 +180,7 @@ function ExecutionEnvironmentLookup({
label={renderLabel(isGlobalDefaultEnvironment, isDefaultEnvironment)}
labelIcon={popoverContent && <Popover content={popoverContent} />}
>
{tooltip ? (
{tooltip && isDisabled ? (
<Tooltip content={tooltip}>{renderLookup()}</Tooltip>
) : (
renderLookup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ describe('ExecutionEnvironmentLookup', () => {
ExecutionEnvironmentsAPI.read.mockResolvedValue(
mockedExecutionEnvironments
);
ProjectsAPI.read.mockResolvedValue({
data: {
count: 1,
results: [
{
id: 1,
name: 'Fuz',
},
],
},
});
ProjectsAPI.readDetail.mockResolvedValue({ data: { organization: 39 } });
});

afterEach(() => {
Expand Down Expand Up @@ -97,4 +87,45 @@ describe('ExecutionEnvironmentLookup', () => {
wrapper.find('FormGroup[label="Execution Environment"]').length
).toBe(1);
});

test('should call api with organization id', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentLookup
value={executionEnvironment}
onChange={() => {}}
organizationId={1}
globallyAvailable
/>
);
});
expect(ExecutionEnvironmentsAPI.read).toHaveBeenCalledWith({
or__organization__id: 1,
or__organization__isnull: 'True',
order_by: 'name',
page: 1,
page_size: 5,
});
});

test('should call api with organization id from the related project', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentLookup
value={executionEnvironment}
onChange={() => {}}
projectId={12}
globallyAvailable
/>
);
});
expect(ProjectsAPI.readDetail).toHaveBeenCalledWith(12);
expect(ExecutionEnvironmentsAPI.read).toHaveBeenCalledWith({
or__organization__id: 39,
or__organization__isnull: 'True',
order_by: 'name',
page: 1,
page_size: 5,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function JobTemplateForm({
t`Select a project before editing the execution environment.`
)}
globallyAvailable
isDisabled={!projectField.value}
isDisabled={!projectField.value?.id}
projectId={projectField.value?.id}
/>

Expand Down