Skip to content

Commit c3ee794

Browse files
committed
[role_mapping] Partial progress
1 parent 470eed8 commit c3ee794

File tree

6 files changed

+40
-25
lines changed

6 files changed

+40
-25
lines changed

x-pack/plugins/security/public/management/management_urls.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ export const EDIT_ROLES_PATH = `/edit`;
1111
export const CLONE_ROLES_PATH = `/clone`;
1212
export const USERS_PATH = `../users`;
1313
export const EDIT_USERS_PATH = `${USERS_PATH}/edit`;
14-
export const ROLE_MAPPINGS_PATH = `../role_mappings`;
15-
const CREATE_ROLE_MAPPING_PATH = `${ROLE_MAPPINGS_PATH}/edit`;
1614

17-
export const getEditRoleHref = (roleName: string) => `/edit/${encodeURIComponent(roleName)}`;
18-
19-
export const getCreateRoleMappingHref = () => `${CREATE_ROLE_MAPPING_PATH}`;
15+
export const getEditRoleHref = (roleName: string) =>
16+
`../roles/edit/${encodeURIComponent(roleName)}`;
2017

2118
export const getEditRoleMappingHref = (roleMappingName: string) =>
22-
`${CREATE_ROLE_MAPPING_PATH}/${encodeURIComponent(roleMappingName)}`;
19+
`${EDIT_ROLES_PATH}/${encodeURIComponent(roleMappingName)}`;

x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '@elastic/eui';
2020
import { i18n } from '@kbn/i18n';
2121
import { FormattedMessage } from '@kbn/i18n/react';
22-
import { NotificationsStart } from 'src/core/public';
22+
import { NotificationsStart, ScopedHistory } from 'src/core/public';
2323
import { RoleMapping } from '../../../../common/model';
2424
import { RuleEditorPanel } from './rule_editor_panel';
2525
import {
@@ -29,7 +29,6 @@ import {
2929
SectionLoading,
3030
} from '../components';
3131
import { RolesAPIClient } from '../../roles';
32-
import { ROLE_MAPPINGS_PATH } from '../../management_urls';
3332
import { validateRoleMappingForSave } from './services/role_mapping_validation';
3433
import { MappingInfoPanel } from './mapping_info_panel';
3534
import { DocumentationLinksService } from '../documentation_links';
@@ -55,6 +54,7 @@ interface Props {
5554
rolesAPIClient: PublicMethodsOf<RolesAPIClient>;
5655
notifications: NotificationsStart;
5756
docLinks: DocumentationLinksService;
57+
history: ScopedHistory;
5858
}
5959

6060
export class EditRoleMappingPage extends Component<Props, State> {
@@ -342,7 +342,5 @@ export class EditRoleMappingPage extends Component<Props, State> {
342342
}
343343
}
344344

345-
private backToRoleMappingsList = () => {
346-
window.location.hash = ROLE_MAPPINGS_PATH;
347-
};
345+
private backToRoleMappingsList = () => this.props.history.push('/');
348346
}

x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/create_role_mapping_button/create_role_mapping_button.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
import React from 'react';
88
import { EuiButton } from '@elastic/eui';
99
import { FormattedMessage } from '@kbn/i18n/react';
10-
import { getCreateRoleMappingHref } from '../../../management_urls';
10+
import { withRouter } from 'react-router-dom';
11+
import { EDIT_ROLES_PATH } from '../../../management_urls';
12+
import { reactRouterNavigate } from '../../../../../../../../src/plugins/kibana_react/public';
1113

12-
export const CreateRoleMappingButton = () => {
14+
export const CreateRoleMappingButton = withRouter(({ history }) => {
1315
return (
14-
<EuiButton data-test-subj="createRoleMappingButton" href={getCreateRoleMappingHref()} fill>
16+
<EuiButton
17+
data-test-subj="createRoleMappingButton"
18+
{...reactRouterNavigate(history, EDIT_ROLES_PATH)}
19+
fill
20+
>
1521
<FormattedMessage
1622
id="xpack.security.management.roleMappings.createRoleMappingButton"
1723
defaultMessage="Create role mapping"
1824
/>
1925
</EuiButton>
2026
);
21-
};
27+
});

x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '@elastic/eui';
2525
import { i18n } from '@kbn/i18n';
2626
import { FormattedMessage } from '@kbn/i18n/react';
27-
import { NotificationsStart } from 'src/core/public';
27+
import { NotificationsStart, ScopedHistory } from 'src/core/public';
2828
import { RoleMapping, Role } from '../../../../common/model';
2929
import { EmptyPrompt } from './empty_prompt';
3030
import {
@@ -33,18 +33,20 @@ import {
3333
PermissionDenied,
3434
SectionLoading,
3535
} from '../components';
36-
import { getCreateRoleMappingHref, getEditRoleMappingHref } from '../../management_urls';
36+
import { EDIT_ROLES_PATH, getEditRoleMappingHref } from '../../management_urls';
3737
import { DocumentationLinksService } from '../documentation_links';
3838
import { RoleMappingsAPIClient } from '../role_mappings_api_client';
3939
import { RoleTableDisplay } from '../../role_table_display';
4040
import { RolesAPIClient } from '../../roles';
4141
import { EnabledBadge, DisabledBadge } from '../../badges';
42+
import { reactRouterNavigate } from '../../../../../../../src/plugins/kibana_react/public';
4243

4344
interface Props {
4445
rolesAPIClient: PublicMethodsOf<RolesAPIClient>;
4546
roleMappingsAPI: PublicMethodsOf<RoleMappingsAPIClient>;
4647
notifications: NotificationsStart;
4748
docLinks: DocumentationLinksService;
49+
history: ScopedHistory;
4850
}
4951

5052
interface State {
@@ -160,7 +162,10 @@ export class RoleMappingsGridPage extends Component<Props, State> {
160162
</EuiText>
161163
</EuiPageContentHeaderSection>
162164
<EuiPageContentHeaderSection>
163-
<EuiButton data-test-subj="createRoleMappingButton" href={getCreateRoleMappingHref()}>
165+
<EuiButton
166+
data-test-subj="createRoleMappingButton"
167+
{...reactRouterNavigate(this.props.history, EDIT_ROLES_PATH)}
168+
>
164169
<FormattedMessage
165170
id="xpack.security.management.roleMappings.createRoleMappingButtonLabel"
166171
defaultMessage="Create role mapping"
@@ -294,7 +299,7 @@ export class RoleMappingsGridPage extends Component<Props, State> {
294299
render: (roleMappingName: string) => {
295300
return (
296301
<EuiLink
297-
href={getEditRoleMappingHref(roleMappingName)}
302+
{...reactRouterNavigate(this.props.history, getEditRoleMappingHref(roleMappingName))}
298303
data-test-subj="roleMappingName"
299304
>
300305
{roleMappingName}
@@ -327,7 +332,7 @@ export class RoleMappingsGridPage extends Component<Props, State> {
327332
const role: Role | string =
328333
this.state.roles?.find(r => r.name === rolename) ?? rolename;
329334

330-
return <RoleTableDisplay role={role} key={rolename} />;
335+
return <RoleTableDisplay role={role} key={rolename} history={this.props.history} />;
331336
});
332337
return <div data-test-subj="roleMappingRoles">{roleLinks}</div>;
333338
},
@@ -371,7 +376,10 @@ export class RoleMappingsGridPage extends Component<Props, State> {
371376
iconType="pencil"
372377
color="primary"
373378
data-test-subj={`editRoleMappingButton-${record.name}`}
374-
href={getEditRoleMappingHref(record.name)}
379+
{...reactRouterNavigate(
380+
this.props.history,
381+
getEditRoleMappingHref(record.name)
382+
)}
375383
/>
376384
</EuiToolTip>
377385
);

x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export const roleMappingsManagementApp = Object.freeze({
2626
title: i18n.translate('xpack.security.management.roleMappingsTitle', {
2727
defaultMessage: 'Role Mappings',
2828
}),
29-
async mount({ basePath, element, setBreadcrumbs, history }) {
29+
async mount({ element, setBreadcrumbs, history }) {
3030
const roleMappingsBreadcrumbs = [
3131
{
3232
text: i18n.translate('xpack.security.roleMapping.breadcrumb', {
3333
defaultMessage: 'Role Mappings',
3434
}),
35-
href: `#${basePath}`,
35+
href: `/`,
3636
},
3737
];
3838

@@ -60,6 +60,7 @@ export const roleMappingsManagementApp = Object.freeze({
6060
rolesAPIClient={new RolesAPIClient(http)}
6161
roleMappingsAPI={roleMappingsAPIClient}
6262
docLinks={dockLinksService}
63+
history={history}
6364
/>
6465
);
6566
};
@@ -85,6 +86,7 @@ export const roleMappingsManagementApp = Object.freeze({
8586
rolesAPIClient={new RolesAPIClient(http)}
8687
notifications={notifications}
8788
docLinks={dockLinksService}
89+
history={history}
8890
/>
8991
);
9092
};

x-pack/plugins/security/public/management/role_table_display/role_table_display.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66

77
import React from 'react';
88
import { EuiLink, EuiToolTip, EuiIcon } from '@elastic/eui';
9+
import { ScopedHistory } from 'kibana/public';
910
import { Role, isRoleDeprecated, getExtendedRoleDeprecationNotice } from '../../../common/model';
1011
import { getEditRoleHref } from '../management_urls';
12+
import { reactRouterNavigate } from '../../../../../../src/plugins/kibana_react/public';
1113

1214
interface Props {
1315
role: Role | string;
16+
history: ScopedHistory;
1417
}
1518

16-
export const RoleTableDisplay = ({ role }: Props) => {
19+
export const RoleTableDisplay = ({ role, history }: Props) => {
1720
let content;
1821
let href;
1922
if (typeof role === 'string') {
@@ -35,5 +38,6 @@ export const RoleTableDisplay = ({ role }: Props) => {
3538
content = <div>{role.name}</div>;
3639
href = getEditRoleHref(role.name);
3740
}
38-
return <EuiLink href={href}>{content}</EuiLink>;
41+
42+
return <EuiLink {...reactRouterNavigate(history, href)}>{content}</EuiLink>;
3943
};

0 commit comments

Comments
 (0)