Skip to content

Commit d2d2f49

Browse files
committed
Updates select components in awx to use framework async select. Removes unused form. Adds missing resource icon to some form selects.
1 parent 9db4b1f commit d2d2f49

File tree

15 files changed

+127
-445
lines changed

15 files changed

+127
-445
lines changed

framework/PageForm/Inputs/PageFormAsyncSingleSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type PageFormAsyncSingleSelectProps<
3939
| 'onBrowse'
4040
| 'queryLabel'
4141
| 'writeInOption'
42+
| 'icon'
4243
> &
4344
Pick<
4445
PageFormGroupProps,

frontend/awx/access/roles/AddRolesForm.tsx

Lines changed: 0 additions & 222 deletions
This file was deleted.
Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { useCallback } from 'react';
2-
import { FieldPath, FieldPathValue, FieldValues, Path } from 'react-hook-form';
1+
import { FieldPath, FieldValues } from 'react-hook-form';
32
import { useTranslation } from 'react-i18next';
4-
import { PageFormAsyncSelect } from '../../../../../framework/PageForm/Inputs/PageFormAsyncSelect';
5-
import { requestGet } from '../../../../common/crud/Data';
6-
import { AwxItemsResponse } from '../../../common/AwxItemsResponse';
73
import { awxAPI } from '../../../common/api/awx-utils';
84
import { SystemJobTemplate } from '../../../interfaces/SystemJobTemplate';
9-
import { useSelectManagementJobs } from '../hooks/useSelectManagementJobs';
5+
import { PageFormSingleSelectAwxResource } from '../../../common/PageFormSingleSelectAwxResource';
6+
import { useManagementJobColumns } from '../hooks/useManagementJobColumns';
7+
import { useManagementJobFilters } from '../hooks/useManagementJobFilters';
108

119
export function PageFormManagementJobsSelect<
1210
TFieldValues extends FieldValues = FieldValues,
@@ -18,36 +16,21 @@ export function PageFormManagementJobsSelect<
1816
templateId?: number;
1917
}) {
2018
const { t } = useTranslation();
21-
const openSelectDialog = useSelectManagementJobs();
22-
const query = useCallback(async () => {
23-
const response = await requestGet<AwxItemsResponse<SystemJobTemplate>>(
24-
awxAPI`/system_job_templates/`
25-
);
26-
27-
return Promise.resolve({
28-
total: response.count,
29-
values: response.results as FieldPathValue<TFieldValues, Path<TFieldValues>>[],
30-
});
31-
}, []);
19+
const tableColumns = useManagementJobColumns();
20+
const filters = useManagementJobFilters();
3221

3322
return (
34-
<PageFormAsyncSelect<TFieldValues>
23+
<PageFormSingleSelectAwxResource<SystemJobTemplate, TFieldValues, TFieldName>
3524
name={props.name}
25+
tableColumns={tableColumns}
26+
toolbarFilters={filters}
3627
id="management-job-template-select"
3728
label={t('Management job template')}
38-
query={query}
39-
valueToString={(value) => {
40-
if (value && typeof value === 'string') {
41-
return value;
42-
}
43-
return (value as SystemJobTemplate)?.name ?? '';
44-
}}
4529
placeholder={t('Select a management job template')}
46-
loadingPlaceholder={t('Loading management job templates...')}
47-
loadingErrorText={t('Error loading management job templates')}
30+
queryPlaceholder={t('Loading management job templates...')}
31+
queryErrorText={t('Error loading management job templates')}
4832
isRequired={props.isRequired}
49-
limit={200}
50-
openSelectDialog={openSelectDialog}
33+
url={awxAPI`/system_job_templates/`}
5134
/>
5235
);
5336
}

frontend/awx/common/PageFormSingleSelectAwxResource.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { AsyncQueryLabel } from '../../common/AsyncQueryLabel';
99
import { requestGet } from '../../common/crud/Data';
1010
import { AwxItemsResponse } from './AwxItemsResponse';
1111
import { QueryParams, useAwxView } from './useAwxView';
12+
import { ExclamationTriangleIcon } from '@patternfly/react-icons';
13+
import { Icon, Tooltip } from '@patternfly/react-core';
1214

1315
export function PageFormSingleSelectAwxResource<
1416
Resource extends { id: number; name: string; description?: string | null | undefined },
@@ -22,6 +24,7 @@ export function PageFormSingleSelectAwxResource<
2224
isRequired?: boolean;
2325
isDisabled?: string;
2426
url: string;
27+
missingResource?: (resource: Resource) => string;
2528
toolbarFilters?: IToolbarFilter[];
2629
tableColumns: ITableColumn<Resource>[];
2730
defaultSelection?: Value[];
@@ -34,7 +37,7 @@ export function PageFormSingleSelectAwxResource<
3437
queryParams?: QueryParams;
3538
}) {
3639
const id = useID(props);
37-
40+
const { missingResource } = props;
3841
const queryOptions = useCallback<PageAsyncSelectOptionsFn<PathValue<FormData, Name>>>(
3942
async (options) => {
4043
try {
@@ -65,11 +68,21 @@ export function PageFormSingleSelectAwxResource<
6568
return {
6669
remaining: response.count - response.results.length,
6770
options:
68-
response.results?.map((resource) => ({
69-
label: resource.name,
70-
value: resource.id as PathValue<FormData, Name>,
71-
description: resource.description,
72-
})) ?? [],
71+
response.results?.map((resource) => {
72+
const content = missingResource && missingResource(resource);
73+
return {
74+
label: resource.name,
75+
value: resource.id as PathValue<FormData, Name>,
76+
description: resource.description,
77+
icon: content ? (
78+
<Tooltip content={missingResource(resource)} position="right">
79+
<Icon status="danger">
80+
<ExclamationTriangleIcon />
81+
</Icon>
82+
</Tooltip>
83+
) : undefined,
84+
};
85+
}) ?? [],
7386
next: response.results[response.results.length - 1]?.name,
7487
};
7588
} catch (error) {
@@ -80,7 +93,7 @@ export function PageFormSingleSelectAwxResource<
8093
};
8194
}
8295
},
83-
[props.url, props.queryParams]
96+
[missingResource, props.queryParams, props.url]
8497
);
8598

8699
const [_, setDialog] = usePageDialog();

0 commit comments

Comments
 (0)