Skip to content

Commit 9d6972c

Browse files
authored
Merge pull request ansible#11459 from marshmalien/5456-insights-system-settings
Update label and display of "Last gathered entries..." setting
2 parents 5fdfd41 + 0566a0f commit 9d6972c

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

awx/main/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@
687687
register(
688688
'AUTOMATION_ANALYTICS_LAST_ENTRIES',
689689
field_class=fields.CharField,
690-
label=_('Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.'),
690+
label=_('Last gathered entries from the data collection service of Insights for Ansible Automation Platform'),
691691
default='',
692692
allow_blank=True,
693693
category=_('System'),

awx/ui/src/screens/Setting/MiscSystem/MiscSystemDetail/MiscSystemDetail.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { t } from '@lingui/macro';
55
import { Button } from '@patternfly/react-core';
66
import { CaretLeftIcon } from '@patternfly/react-icons';
77
import { CardBody, CardActionsRow } from 'components/Card';
8+
import CodeDetail from 'components/DetailList/CodeDetail';
89
import ContentError from 'components/ContentError';
910
import ContentLoading from 'components/ContentLoading';
1011
import { DetailList } from 'components/DetailList';
@@ -14,7 +15,11 @@ import useRequest from 'hooks/useRequest';
1415
import { useConfig } from 'contexts/Config';
1516
import { useSettings } from 'contexts/Settings';
1617
import { SettingDetail } from '../../shared';
17-
import { sortNestedDetails, pluck } from '../../shared/settingUtils';
18+
import {
19+
formatJson,
20+
pluck,
21+
sortNestedDetails,
22+
} from '../../shared/settingUtils';
1823

1924
function MiscSystemDetail() {
2025
const { me } = useConfig();
@@ -62,7 +67,12 @@ function MiscSystemDetail() {
6267
const mergedData = {};
6368
Object.keys(systemData).forEach((key) => {
6469
mergedData[key] = options[key];
65-
mergedData[key].value = systemData[key];
70+
71+
if (key === 'AUTOMATION_ANALYTICS_LAST_ENTRIES') {
72+
mergedData[key].value = formatJson(systemData[key]) ?? '';
73+
} else {
74+
mergedData[key].value = systemData[key];
75+
}
6676
});
6777
return sortNestedDetails(mergedData);
6878
}, [options]),
@@ -91,6 +101,11 @@ function MiscSystemDetail() {
91101
},
92102
];
93103

104+
// Display this detail in a code editor for readability
105+
if (options?.AUTOMATION_ANALYTICS_LAST_ENTRIES) {
106+
options.AUTOMATION_ANALYTICS_LAST_ENTRIES.type = 'nested object';
107+
}
108+
94109
return (
95110
<>
96111
<RoutedTabs tabsArray={tabsArray} />
@@ -99,17 +114,36 @@ function MiscSystemDetail() {
99114
{!isLoading && error && <ContentError error={error} />}
100115
{!isLoading && system && (
101116
<DetailList>
102-
{system.map(([key, detail]) => (
103-
<SettingDetail
104-
key={key}
105-
id={key}
106-
helpText={detail?.help_text}
107-
label={detail?.label}
108-
type={detail?.type}
109-
unit={detail?.unit}
110-
value={detail?.value}
111-
/>
112-
))}
117+
{system.map(([key, detail]) => {
118+
if (key === 'AUTOMATION_ANALYTICS_LAST_ENTRIES') {
119+
return (
120+
<CodeDetail
121+
key={key}
122+
dataCy={key}
123+
helpText={detail?.help_text}
124+
label={detail?.label}
125+
mode="javascript"
126+
rows={4}
127+
value={
128+
detail?.value
129+
? JSON.stringify(detail.value, undefined, 2)
130+
: ''
131+
}
132+
/>
133+
);
134+
}
135+
return (
136+
<SettingDetail
137+
key={key}
138+
id={key}
139+
helpText={detail?.help_text}
140+
label={detail?.label}
141+
type={detail?.type}
142+
unit={detail?.unit}
143+
value={detail?.value}
144+
/>
145+
);
146+
})}
113147
</DetailList>
114148
)}
115149
{me?.is_superuser && (

awx/ui/src/screens/Setting/MiscSystem/MiscSystemDetail/MiscSystemDetail.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('<MiscSystemDetail />', () => {
4040
CUSTOM_VENV_PATHS: [],
4141
INSIGHTS_TRACKING_STATE: false,
4242
AUTOMATION_ANALYTICS_LAST_GATHER: null,
43-
AUTOMATION_ANALYTICS_LAST_ENTRIES: 'foo',
43+
AUTOMATION_ANALYTICS_LAST_ENTRIES:
44+
'{"foo": "2021-11-24R06:35:15.179Z"}',
4445
AUTOMATION_ANALYTICS_GATHER_INTERVAL: 14400,
4546
},
4647
});
@@ -80,11 +81,6 @@ describe('<MiscSystemDetail />', () => {
8081
'Unique identifier for an installation',
8182
'db39b9ec-0c6e-4554-987d-42aw9c732ed8'
8283
);
83-
assertDetail(
84-
wrapper,
85-
'Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.',
86-
'foo'
87-
);
8884
assertDetail(wrapper, 'All Users Visible to Organization Admins', 'On');
8985
assertDetail(
9086
wrapper,
@@ -113,6 +109,11 @@ describe('<MiscSystemDetail />', () => {
113109
assertDetail(wrapper, 'Red Hat customer username', 'name1');
114110
assertDetail(wrapper, 'Red Hat or Satellite password', 'Encrypted');
115111
assertDetail(wrapper, 'Red Hat or Satellite username', 'name2');
112+
assertVariableDetail(
113+
wrapper,
114+
'Last gathered entries from the data collection service of Insights for Ansible Automation Platform',
115+
'{\n "foo": "2021-11-24R06:35:15.179Z"\n}'
116+
);
116117
assertVariableDetail(wrapper, 'Remote Host Headers', '[]');
117118
assertVariableDetail(wrapper, 'Proxy IP Allowed List', '[]');
118119
assertDetail(wrapper, 'Global default execution environment', 'Foo');

awx/ui/src/screens/Setting/MiscSystem/MiscSystemEdit/MiscSystemEdit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ function MiscSystemEdit() {
222222
type="number"
223223
isRequired
224224
/>
225-
<InputField
225+
<ObjectField
226226
name="AUTOMATION_ANALYTICS_LAST_ENTRIES"
227227
config={system.AUTOMATION_ANALYTICS_LAST_ENTRIES}
228+
revertValue={system.AUTOMATION_ANALYTICS_LAST_ENTRIES.default}
228229
/>
229230
<ObjectField
230231
name="REMOTE_HOST_HEADERS"

awx/ui/src/screens/Setting/shared/SharedFields.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ TextAreaField.propTypes = {
435435
config: shape({}).isRequired,
436436
};
437437

438-
const ObjectField = ({ name, config, isRequired = false }) => {
438+
const ObjectField = ({ name, config, revertValue, isRequired = false }) => {
439439
const validate = isRequired ? required(null) : null;
440440
const [field, meta, helpers] = useField({ name, validate });
441441
const isValid = !(meta.touched && meta.error);
@@ -446,7 +446,7 @@ const ObjectField = ({ name, config, isRequired = false }) => {
446446
return config ? (
447447
<FormFullWidthLayout>
448448
<SettingGroup
449-
defaultValue={defaultRevertValue}
449+
defaultValue={revertValue ?? defaultRevertValue}
450450
fieldId={name}
451451
helperTextInvalid={meta.error}
452452
isRequired={isRequired}

awx/ui/src/screens/Setting/shared/data.allSettingOptions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@
575575
"AUTOMATION_ANALYTICS_LAST_ENTRIES": {
576576
"type": "string",
577577
"required": false,
578-
"label": "Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.",
578+
"label": "Last gathered entries from the data collection service of Insights for Ansible Automation Platform",
579579
"category": "System",
580580
"category_slug": "system",
581581
"default": ""
@@ -4208,7 +4208,7 @@
42084208
},
42094209
"AUTOMATION_ANALYTICS_LAST_ENTRIES": {
42104210
"type": "string",
4211-
"label": "Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.",
4211+
"label": "Last gathered entries from the data collection service of Insights for Ansible Automation Platform",
42124212
"category": "System",
42134213
"category_slug": "system",
42144214
"defined_in_file": false

awx/ui/src/screens/Setting/shared/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export {
66
ChoiceField,
77
EncryptedField,
88
ExecutionEnvField,
9+
InputAlertField,
910
InputField,
1011
ObjectField,
11-
InputAlertField,
12+
TextAreaField,
1213
} from './SharedFields';

0 commit comments

Comments
 (0)