Update label and display of "Last gathered entries..." setting

This commit is contained in:
Marliana Lara 2021-12-13 15:02:50 -05:00
parent edca19a697
commit 0566a0f1d6
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
7 changed files with 63 additions and 26 deletions

View File

@ -687,7 +687,7 @@ register(
register(
'AUTOMATION_ANALYTICS_LAST_ENTRIES',
field_class=fields.CharField,
label=_('Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.'),
label=_('Last gathered entries from the data collection service of Insights for Ansible Automation Platform'),
default='',
allow_blank=True,
category=_('System'),

View File

@ -5,6 +5,7 @@ import { t } from '@lingui/macro';
import { Button } from '@patternfly/react-core';
import { CaretLeftIcon } from '@patternfly/react-icons';
import { CardBody, CardActionsRow } from 'components/Card';
import CodeDetail from 'components/DetailList/CodeDetail';
import ContentError from 'components/ContentError';
import ContentLoading from 'components/ContentLoading';
import { DetailList } from 'components/DetailList';
@ -14,7 +15,11 @@ import useRequest from 'hooks/useRequest';
import { useConfig } from 'contexts/Config';
import { useSettings } from 'contexts/Settings';
import { SettingDetail } from '../../shared';
import { sortNestedDetails, pluck } from '../../shared/settingUtils';
import {
formatJson,
pluck,
sortNestedDetails,
} from '../../shared/settingUtils';
function MiscSystemDetail() {
const { me } = useConfig();
@ -62,7 +67,12 @@ function MiscSystemDetail() {
const mergedData = {};
Object.keys(systemData).forEach((key) => {
mergedData[key] = options[key];
mergedData[key].value = systemData[key];
if (key === 'AUTOMATION_ANALYTICS_LAST_ENTRIES') {
mergedData[key].value = formatJson(systemData[key]) ?? '';
} else {
mergedData[key].value = systemData[key];
}
});
return sortNestedDetails(mergedData);
}, [options]),
@ -91,6 +101,11 @@ function MiscSystemDetail() {
},
];
// Display this detail in a code editor for readability
if (options?.AUTOMATION_ANALYTICS_LAST_ENTRIES) {
options.AUTOMATION_ANALYTICS_LAST_ENTRIES.type = 'nested object';
}
return (
<>
<RoutedTabs tabsArray={tabsArray} />
@ -99,17 +114,36 @@ function MiscSystemDetail() {
{!isLoading && error && <ContentError error={error} />}
{!isLoading && system && (
<DetailList>
{system.map(([key, detail]) => (
<SettingDetail
key={key}
id={key}
helpText={detail?.help_text}
label={detail?.label}
type={detail?.type}
unit={detail?.unit}
value={detail?.value}
/>
))}
{system.map(([key, detail]) => {
if (key === 'AUTOMATION_ANALYTICS_LAST_ENTRIES') {
return (
<CodeDetail
key={key}
dataCy={key}
helpText={detail?.help_text}
label={detail?.label}
mode="javascript"
rows={4}
value={
detail?.value
? JSON.stringify(detail.value, undefined, 2)
: ''
}
/>
);
}
return (
<SettingDetail
key={key}
id={key}
helpText={detail?.help_text}
label={detail?.label}
type={detail?.type}
unit={detail?.unit}
value={detail?.value}
/>
);
})}
</DetailList>
)}
{me?.is_superuser && (

View File

@ -40,7 +40,8 @@ describe('<MiscSystemDetail />', () => {
CUSTOM_VENV_PATHS: [],
INSIGHTS_TRACKING_STATE: false,
AUTOMATION_ANALYTICS_LAST_GATHER: null,
AUTOMATION_ANALYTICS_LAST_ENTRIES: 'foo',
AUTOMATION_ANALYTICS_LAST_ENTRIES:
'{"foo": "2021-11-24R06:35:15.179Z"}',
AUTOMATION_ANALYTICS_GATHER_INTERVAL: 14400,
},
});
@ -80,11 +81,6 @@ describe('<MiscSystemDetail />', () => {
'Unique identifier for an installation',
'db39b9ec-0c6e-4554-987d-42aw9c732ed8'
);
assertDetail(
wrapper,
'Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.',
'foo'
);
assertDetail(wrapper, 'All Users Visible to Organization Admins', 'On');
assertDetail(
wrapper,
@ -113,6 +109,11 @@ describe('<MiscSystemDetail />', () => {
assertDetail(wrapper, 'Red Hat customer username', 'name1');
assertDetail(wrapper, 'Red Hat or Satellite password', 'Encrypted');
assertDetail(wrapper, 'Red Hat or Satellite username', 'name2');
assertVariableDetail(
wrapper,
'Last gathered entries from the data collection service of Insights for Ansible Automation Platform',
'{\n "foo": "2021-11-24R06:35:15.179Z"\n}'
);
assertVariableDetail(wrapper, 'Remote Host Headers', '[]');
assertVariableDetail(wrapper, 'Proxy IP Allowed List', '[]');
assertDetail(wrapper, 'Global default execution environment', 'Foo');

View File

@ -222,9 +222,10 @@ function MiscSystemEdit() {
type="number"
isRequired
/>
<InputField
<ObjectField
name="AUTOMATION_ANALYTICS_LAST_ENTRIES"
config={system.AUTOMATION_ANALYTICS_LAST_ENTRIES}
revertValue={system.AUTOMATION_ANALYTICS_LAST_ENTRIES.default}
/>
<ObjectField
name="REMOTE_HOST_HEADERS"

View File

@ -435,7 +435,7 @@ TextAreaField.propTypes = {
config: shape({}).isRequired,
};
const ObjectField = ({ name, config, isRequired = false }) => {
const ObjectField = ({ name, config, revertValue, isRequired = false }) => {
const validate = isRequired ? required(null) : null;
const [field, meta, helpers] = useField({ name, validate });
const isValid = !(meta.touched && meta.error);
@ -446,7 +446,7 @@ const ObjectField = ({ name, config, isRequired = false }) => {
return config ? (
<FormFullWidthLayout>
<SettingGroup
defaultValue={defaultRevertValue}
defaultValue={revertValue ?? defaultRevertValue}
fieldId={name}
helperTextInvalid={meta.error}
isRequired={isRequired}

View File

@ -575,7 +575,7 @@
"AUTOMATION_ANALYTICS_LAST_ENTRIES": {
"type": "string",
"required": false,
"label": "Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.",
"label": "Last gathered entries from the data collection service of Insights for Ansible Automation Platform",
"category": "System",
"category_slug": "system",
"default": ""
@ -4208,7 +4208,7 @@
},
"AUTOMATION_ANALYTICS_LAST_ENTRIES": {
"type": "string",
"label": "Last gathered entries for expensive collectors for Insights for Ansible Automation Platform.",
"label": "Last gathered entries from the data collection service of Insights for Ansible Automation Platform",
"category": "System",
"category_slug": "system",
"defined_in_file": false

View File

@ -6,7 +6,8 @@ export {
ChoiceField,
EncryptedField,
ExecutionEnvField,
InputAlertField,
InputField,
ObjectField,
InputAlertField,
TextAreaField,
} from './SharedFields';