-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate security/roles component #23984
Changes from 2 commits
2630186
5eb9c92
bbac404
0cc02a5
d088841
81c9c9f
321da7e
0dd7da6
ba4ed34
b73e3c4
a6194c0
2f1460d
ff29818
4ba759b
30aebd2
39afaa9
18a70a5
273373b
31ae437
6d6f1e6
bfe526d
6dd7add
ee2ad70
143202b
fd21a0e
d051135
626d0ef
00e5b82
1cc23d0
092eddd
e9ca6e0
399bf4d
2537432
bd0f87f
a86f3d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
EuiSpacer, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { injectI18n } from '@kbn/i18n/react'; | ||
import React, { Component, Fragment } from 'react'; | ||
import './collapsible_panel.less'; | ||
|
||
|
@@ -25,7 +26,7 @@ interface State { | |
collapsed: boolean; | ||
} | ||
|
||
export class CollapsiblePanel extends Component<Props, State> { | ||
export class CollapsiblePanelUI extends Component<Props, State> { | ||
public state = { | ||
collapsed: false, | ||
}; | ||
|
@@ -40,6 +41,8 @@ export class CollapsiblePanel extends Component<Props, State> { | |
} | ||
|
||
public getTitle = () => { | ||
const { intl } = this.props; | ||
|
||
return ( | ||
// @ts-ignore | ||
<EuiFlexGroup alignItems={'baseline'} gutterSize="s" responsive={false}> | ||
|
@@ -56,7 +59,19 @@ export class CollapsiblePanel extends Component<Props, State> { | |
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiLink onClick={this.toggleCollapsed}>{this.state.collapsed ? 'show' : 'hide'}</EuiLink> | ||
<EuiLink onClick={this.toggleCollapsed}> | ||
{this.state.collapsed | ||
? intl.formatMessage({ | ||
id: | ||
'xpack.security.views.management.editRoles.components.collapsiblePanel.showTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. showTitle => showLinkText |
||
defaultMessage: 'show', | ||
}) | ||
: intl.formatMessage({ | ||
id: | ||
'xpack.security.views.management.editRoles.components.collapsiblePanel.hideTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hideTitle => hideLinkText |
||
defaultMessage: 'hide', | ||
})} | ||
</EuiLink> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
|
@@ -81,3 +96,5 @@ export class CollapsiblePanel extends Component<Props, State> { | |
}); | ||
}; | ||
} | ||
|
||
export const CollapsiblePanel = injectI18n(CollapsiblePanelUI); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
// @ts-ignore | ||
EuiOverlayMask, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; | ||
import React, { Component, Fragment } from 'react'; | ||
|
||
interface Props { | ||
|
@@ -22,7 +23,7 @@ interface State { | |
showModal: boolean; | ||
} | ||
|
||
export class DeleteRoleButton extends Component<Props, State> { | ||
export class DeleteRoleButtonUI extends Component<Props, State> { | ||
public state = { | ||
showModal: false, | ||
}; | ||
|
@@ -35,29 +36,55 @@ export class DeleteRoleButton extends Component<Props, State> { | |
return ( | ||
<Fragment> | ||
<EuiButtonEmpty color={'danger'} onClick={this.showModal}> | ||
Delete role | ||
<FormattedMessage | ||
id="xpack.security.views.management.editRoles.components.deleteRoleButton.deleteRoleButton" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => deleteRoleButtonLabel |
||
defaultMessage="Delete role" | ||
/> | ||
</EuiButtonEmpty> | ||
{this.maybeShowModal()} | ||
</Fragment> | ||
); | ||
} | ||
|
||
public maybeShowModal = () => { | ||
const { intl } = this.props; | ||
if (!this.state.showModal) { | ||
return null; | ||
} | ||
return ( | ||
<EuiOverlayMask> | ||
<EuiConfirmModal | ||
title={'Delete Role'} | ||
title={intl.formatMessage({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check if title property supports JSX. I mean try to use FormattedMessage. If it works, then do not use injectI18n |
||
id: | ||
'xpack.security.views.management.editRoles.components.deleteRoleButton.deleteRoleTitle', | ||
defaultMessage: 'Delete Role', | ||
})} | ||
onCancel={this.closeModal} | ||
onConfirm={this.onConfirmDelete} | ||
cancelButtonText={"No, don't delete"} | ||
confirmButtonText={'Yes, delete role'} | ||
cancelButtonText={intl.formatMessage({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above |
||
id: | ||
'xpack.security.views.management.editRoles.components.deleteRoleButton.dontDeleteButton', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dontDeleteButton => cancelButtonLabel |
||
defaultMessage: "No, don't delete", | ||
})} | ||
confirmButtonText={intl.formatMessage({ | ||
id: | ||
'xpack.security.views.management.editRoles.components.deleteRoleButton.yesDeleteButton', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yesDeleteButton => confirmButtonLabel |
||
defaultMessage: 'Yes, delete role', | ||
})} | ||
buttonColor={'danger'} | ||
> | ||
<p>Are you sure you want to delete this role?</p> | ||
<p>This action cannot be undone!</p> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.security.views.management.editRoles.components.deleteRoleButton.areYouSureTitle" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. areYouSureTitle => deletingRoleConfirmationText |
||
defaultMessage="Are you sure you want to delete this role?" | ||
/> | ||
</p> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.security.views.management.editRoles.components.deleteRoleButton.actionCannotUndoneTitle" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actionCannotUndoneTitle => deletingRoleWarningText |
||
defaultMessage="This action cannot be undone!" | ||
/> | ||
</p> | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
); | ||
|
@@ -80,3 +107,5 @@ export class DeleteRoleButton extends Component<Props, State> { | |
this.props.onDelete(); | ||
}; | ||
} | ||
|
||
export const DeleteRoleButton = injectI18n(DeleteRoleButtonUI); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
EuiButton, | ||
EuiButtonEmpty, | ||
|
@@ -19,6 +20,7 @@ import { | |
EuiText, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; | ||
import { get } from 'lodash'; | ||
import React, { ChangeEvent, Component, Fragment, HTMLProps } from 'react'; | ||
import { toastNotifications } from 'ui/notify'; | ||
|
@@ -54,7 +56,7 @@ interface State { | |
formError: RoleValidationResult | null; | ||
} | ||
|
||
export class EditRolePage extends Component<Props, State> { | ||
export class EditRolePageUI extends Component<Props, State> { | ||
private validator: RoleValidator; | ||
|
||
constructor(props: Props) { | ||
|
@@ -67,9 +69,18 @@ export class EditRolePage extends Component<Props, State> { | |
} | ||
|
||
public render() { | ||
const { intl } = this.props; | ||
const description = this.props.spacesEnabled | ||
? `Set privileges on your Elasticsearch data and control access to your Kibana spaces.` | ||
: `Set privileges on your Elasticsearch data and control access to Kibana.`; | ||
? intl.formatMessage({ | ||
id: | ||
'xpack.security.views.management.editRoles.components.editRoles.accessToYourKibanaTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. editRoles => editRole for all ids in this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accessToYourKibanaTitle => setPrivilegesToKibanaSpacesDescription |
||
defaultMessage: | ||
'Set privileges on your Elasticsearch data and control access to your Kibana spaces.', | ||
}) | ||
: intl.formatMessage({ | ||
id: 'xpack.security.views.management.editRoles.components.editRoles.accessToKibanaTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accessToKibanaTitle => setPrivilegesToKibanaDescription |
||
defaultMessage: 'Set privileges on your Elasticsearch data and control access to Kibana.', | ||
}); | ||
|
||
return ( | ||
<EuiPage className="editRolePage" restrictWidth> | ||
|
@@ -86,7 +97,10 @@ export class EditRolePage extends Component<Props, State> { | |
<EuiSpacer size="s" /> | ||
<EuiText size="s" color="subdued"> | ||
<p id="reservedRoleDescription" tabIndex={1}> | ||
Reserved roles are built-in and cannot be removed or modified. | ||
<FormattedMessage | ||
id="xpack.security.views.management.editRoles.components.editRoles.reversedRolesTitle" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most cases text in reversedRolesTitle => modifyingReversedRolesDescription |
||
defaultMessage="Reserved roles are built-in and cannot be removed or modified." | ||
/> | ||
</p> | ||
</EuiText> | ||
</Fragment> | ||
|
@@ -110,17 +124,27 @@ export class EditRolePage extends Component<Props, State> { | |
} | ||
|
||
public getFormTitle = () => { | ||
const { intl } = this.props; | ||
let titleText; | ||
const props: HTMLProps<HTMLDivElement> = { | ||
tabIndex: 0, | ||
}; | ||
if (isReservedRole(this.props.role)) { | ||
titleText = 'Viewing role'; | ||
titleText = intl.formatMessage({ | ||
id: 'xpack.security.components.management.user.editUser.viewingRoleTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check ids in this file. Why some of them have .user.editUser? I looks like it should be xpack.security.views.management.editRole.components.editRolePage |
||
defaultMessage: 'Viewing role', | ||
}); | ||
props['aria-describedby'] = 'reservedRoleDescription'; | ||
} else if (this.editingExistingRole()) { | ||
titleText = 'Edit role'; | ||
titleText = intl.formatMessage({ | ||
id: 'xpack.security.components.management.user.editUser.editRoleTitle', | ||
defaultMessage: 'Edit role', | ||
}); | ||
} else { | ||
titleText = 'Create role'; | ||
titleText = intl.formatMessage({ | ||
id: 'xpack.security.components.management.user.editUser.createRoleTitle', | ||
defaultMessage: 'Create role', | ||
}); | ||
} | ||
|
||
return ( | ||
|
@@ -145,13 +169,22 @@ export class EditRolePage extends Component<Props, State> { | |
}; | ||
|
||
public getRoleName = () => { | ||
const { intl } = this.props; | ||
|
||
return ( | ||
<EuiPanel> | ||
<EuiFormRow | ||
label={'Role name'} | ||
label={intl.formatMessage({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use FormattedMessage instead of intl.formatMessage |
||
id: 'xpack.security.views.management.editRoles.components.editRoles.roleNameTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. roleNameTitle => roleNameFormRowTitle |
||
defaultMessage: 'Role name', | ||
})} | ||
helpText={ | ||
!isReservedRole(this.props.role) && this.editingExistingRole() | ||
? "A role's name cannot be changed once it has been created." | ||
? intl.formatMessage({ | ||
id: | ||
'xpack.security.views.management.editRoles.components.editRoles.cannotChangeNameTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cannotChangeNameTitle => roleNameFormRowHelpText |
||
defaultMessage: "A role's name cannot be changed once it has been created.", | ||
}) | ||
: undefined | ||
} | ||
{...this.validator.validateRoleName(this.state.role)} | ||
|
@@ -224,11 +257,27 @@ export class EditRolePage extends Component<Props, State> { | |
}; | ||
|
||
public getFormButtons = () => { | ||
const { intl } = this.props; | ||
if (isReservedRole(this.props.role)) { | ||
return <EuiButton onClick={this.backToRoleList}>Return to role list</EuiButton>; | ||
return ( | ||
<EuiButton onClick={this.backToRoleList}> | ||
<FormattedMessage | ||
id="xpack.security.views.management.editRoles.components.editRoles.returnToListTitle" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returnToListTitle => returnToRoleListButtonLabel |
||
defaultMessage="Return to role list" | ||
/> | ||
</EuiButton> | ||
); | ||
} | ||
|
||
const saveText = this.editingExistingRole() ? 'Update role' : 'Create role'; | ||
const saveText = this.editingExistingRole() | ||
? intl.formatMessage({ | ||
id: 'xpack.security.views.management.editRoles.components.editRoles.updateRoleOneTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateRoleOneTitle => updateRoleText |
||
defaultMessage: 'Update role', | ||
}) | ||
: intl.formatMessage({ | ||
id: 'xpack.security.views.management.editRoles.components.editRoles.createRoleOneTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createRoleOneTitle => createRoleText |
||
defaultMessage: 'Create role', | ||
}); | ||
|
||
return ( | ||
<EuiFlexGroup responsive={false}> | ||
|
@@ -244,7 +293,10 @@ export class EditRolePage extends Component<Props, State> { | |
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty data-test-subj={`roleFormCancelButton`} onClick={this.backToRoleList}> | ||
Cancel | ||
<FormattedMessage | ||
id="xpack.security.views.management.editRoles.components.editRoles.cancelTitle" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cancelTitle => cancelButtonLabel |
||
defaultMessage="Cancel" | ||
/> | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true} /> | ||
|
@@ -274,7 +326,7 @@ export class EditRolePage extends Component<Props, State> { | |
formError: null, | ||
}); | ||
|
||
const { httpClient } = this.props; | ||
const { httpClient, intl } = this.props; | ||
|
||
const role = { | ||
...this.state.role, | ||
|
@@ -287,7 +339,12 @@ export class EditRolePage extends Component<Props, State> { | |
|
||
saveRole(httpClient, role) | ||
.then(() => { | ||
toastNotifications.addSuccess('Saved role'); | ||
toastNotifications.addSuccess( | ||
intl.formatMessage({ | ||
id: 'xpack.security.views.management.editRoles.components.editRoles.savedRoleTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. savedRoleTitle => roleSuccessfullySavedNotificationMessage |
||
defaultMessage: 'Saved role', | ||
}) | ||
); | ||
this.backToRoleList(); | ||
}) | ||
.catch((error: any) => { | ||
|
@@ -297,11 +354,16 @@ export class EditRolePage extends Component<Props, State> { | |
}; | ||
|
||
public handleDeleteRole = () => { | ||
const { httpClient, role } = this.props; | ||
const { httpClient, role, intl } = this.props; | ||
|
||
deleteRole(httpClient, role.name) | ||
.then(() => { | ||
toastNotifications.addSuccess('Deleted role'); | ||
toastNotifications.addSuccess( | ||
intl.formatMessage({ | ||
id: 'xpack.security.views.management.editRoles.components.editRoles.deletedRoleTitle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deletedRoleTitle => roleSuccessfullyDeletedNotificationMessage |
||
defaultMessage: 'Deleted role', | ||
}) | ||
); | ||
this.backToRoleList(); | ||
}) | ||
.catch((error: any) => { | ||
|
@@ -313,3 +375,5 @@ export class EditRolePage extends Component<Props, State> { | |
window.location.hash = ROLES_PATH; | ||
}; | ||
} | ||
|
||
export const EditRolePage = injectI18n(EditRolePageUI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use FormattedMessage here. So you do not need to use injectI18n