Skip to content

Commit

Permalink
Fixed a bug that would clear role selections when editing a monitor. …
Browse files Browse the repository at this point in the history
…Updated help text for role selection dropdown menu.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
  • Loading branch information
AWSHurneyt committed Mar 14, 2024
1 parent 63b0b1b commit 553fc39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,12 @@ class DefineMonitor extends Component {
)}
{filterByBackendRolesEnabled ? (
<div>
<MonitorSecurity errors={errors} httpClient={httpClient} isDarkMode={isDarkMode} />
<MonitorSecurity
values={values}
errors={errors}
httpClient={httpClient}
isDarkMode={isDarkMode}
/>
<EuiSpacer />
</div>
) : null}
Expand Down
31 changes: 26 additions & 5 deletions public/pages/CreateMonitor/containers/MonitorRoles/MonitorRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import { EuiHealth, EuiHighlight } from '@elastic/eui';

import { EuiLink, EuiText } from '@elastic/eui';
import { FormikComboBox } from '../../../../components/FormControls';
import { createReasonableWait } from '../MonitorIndex/utils/helpers';
import { FORMIK_INITIAL_VALUES } from '../CreateMonitor/utils/constants';

const RBAC_DOCUMENTATION =
'https://opensearch.org/docs/latest/observing-your-data/alerting/security/';

const propTypes = {
httpClient: PropTypes.object.isRequired,
Expand All @@ -19,11 +22,16 @@ class MonitorRoles extends React.Component {
constructor(props) {
super(props);

// Retrieve, and parse roles when editing a monitor
const roles = _.get(props, 'values.roles', FORMIK_INITIAL_VALUES.roles).map((role) => ({
label: role,
}));

this.lastQuery = null;
this.state = {
isLoading: false,
showingRoleQueryErrors: false,
options: [],
options: roles,
roles: [],
};

Expand Down Expand Up @@ -93,8 +101,20 @@ class MonitorRoles extends React.Component {
name="roles"
formRow
rowProps={{
label: 'Backend roles',
helpText: 'You can optionally assign one or more backend roles to the monitor',
label: (
<div>
<EuiText size={'xs'}>
<strong>Backend roles</strong>
<i> - optional </i>
</EuiText>
<EuiText color={'subdued'} size={'xs'} style={{ width: '400px' }}>
Specify role-based access control (RBAC) backend roles.{' '}
<EuiLink external href={RBAC_DOCUMENTATION} target={'_blank'}>
Learn more
</EuiLink>
</EuiText>
</div>
),
style: { paddingLeft: '10px' },
}}
inputProps={{
Expand All @@ -111,6 +131,7 @@ class MonitorRoles extends React.Component {
onSearchChange: this.onSearchChange,
isClearable: true,
singleSelection: false,
selectedOptions: roles,
'data-test-subj': 'rolesComboBox',
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MonitorSecurity extends Component {
const { isMinimal } = this.props;
const monitorRoleDisplay = (
<>
<MonitorRoles httpClient={this.props.httpClient} />
<MonitorRoles values={this.props.values} httpClient={this.props.httpClient} />
</>
);

Expand Down

0 comments on commit 553fc39

Please sign in to comment.