Skip to content

Commit

Permalink
MGMT-14644: Fix missing I18N in action names (#2219)
Browse files Browse the repository at this point in the history
Co-authored-by: Montse Ortega <[email protected]>
  • Loading branch information
mareklibra and ammont82 authored Aug 11, 2023
1 parent ddffc63 commit b270560
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 25 deletions.
9 changes: 9 additions & 0 deletions libs/locales/lib/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@
"ai:Developer preview release": "Developer preview release",
"ai:DHCP only": "DHCP only",
"ai:DHCP or static IP Addresses": "DHCP or static IP Addresses",
"ai:Disable in cluster": "Disable in cluster",
"ai:Discover a single host via Baseboard Management Controller": "Discover a single host via Baseboard Management Controller",
"ai:Discover hosts by booting a discovery image": "Discover hosts by booting a discovery image",
"ai:Discover multiple hosts by providing yaml with Bare Metal Host definitions": "Discover multiple hosts by providing YAML with Bare Metal Host definitions",
"ai:Discovered hostname": "Discovered hostname",
"ai:Discovered on": "Discovered on",
"ai:Discovery ISO": "Discovery ISO",
"ai:Discovery ISO is ready to be downloaded": "Discovery ISO is ready to be downloaded.",
Expand All @@ -246,6 +248,7 @@
"ai:Do not use forbidden words, for example: \"localhost\".": "Do not use forbidden words, for example: \"localhost\".",
"ai:Download Discovery ISO": "Download Discovery ISO",
"ai:Download host discovery ISO dialog": "Download host discovery ISO dialog",
"ai:Download host logs": "Download host logs",
"ai:Download Installation Logs": "Download Installation Logs",
"ai:Download kubeconfig": "Download kubeconfig",
"ai:Download script file": "Download script file",
Expand All @@ -255,6 +258,7 @@
"ai:Download the example iPXE script file": "Download the example iPXE script file",
"ai:Draft": "Draft",
"ai:Drag a file here or browse to upload": "Drag a file here or browse to upload",
"ai:Edit BMC": "Edit BMC",
"ai:Edit BMH": "Edit BMH",
"ai:Edit BMH dialog": "Edit BMH dialog",
"ai:Edit cluster-wide proxy settings": "Edit cluster-wide proxy settings",
Expand All @@ -267,6 +271,7 @@
"ai:Edit pull secret dialog": "Edit pull secret dialog",
"ai:Edit SSH public key": "Edit SSH public key",
"ai:Edit SSH public key dialog": "Edit SSH public key dialog",
"ai:Enable in cluster": "Enable in cluster",
"ai:Enabled for the installation": "Enabled for the installation",
"ai:Enter a password for the BMC": "Enter a password for the BMC",
"ai:Enter a username for the BMC": "Enter a username for the BMC",
Expand Down Expand Up @@ -598,6 +603,8 @@
"ai:Recommended option. The generated discovery ISO will be smaller, but will need to download additional data during boot. This option is useful if ISO storage capacity is limited or if it's being served over a constrained network.": "Recommended option. The generated discovery ISO will be smaller, but will need to download additional data during boot. This option is useful if ISO storage capacity is limited or if it's being served over a constrained network.",
"ai:Release domain resolution": "Release domain resolution",
"ai:Remove": "Remove",
"ai:Remove from the cluster": "Remove from the cluster",
"ai:Remove host": "Remove host",
"ai:Remove hosts": "Remove hosts",
"ai:Remove hosts dialog": "Remove hosts dialog",
"ai:Remove hosts?": "Remove hosts?",
Expand All @@ -609,6 +616,7 @@
"ai:Report a bug": "Report a bug",
"ai:Required field": "Required field",
"ai:Required.": "Required.",
"ai:Reset host": "Reset host",
"ai:Review and create": "Review and create",
"ai:Role": "Role",
"ai:Run these commands to use the script:": "Run these commands to use the script:",
Expand Down Expand Up @@ -773,6 +781,7 @@
"ai:View {{count}} affected host_plural": "View {{count}} affected hosts",
"ai:View cluster events": "View cluster events",
"ai:View documentation": "View documentation",
"ai:View host events": "View host events",
"ai:VIP IP allocation from DHCP server has been timed out": "VIP IP allocation from DHCP server has timed out",
"ai:Virtual machine": "Virtual machine",
"ai:Vsphere disk uuid enabled": "Vsphere disk uuid enabled",
Expand Down
2 changes: 1 addition & 1 deletion libs/ui-lib/lib/cim/components/Agent/tableUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export const useAgentsTable = (
agentClusterInstalls,
],
);
const actionResolver = React.useMemo(() => hostActionResolver(actions), [actions]);
const actionResolver = React.useMemo(() => hostActionResolver({ t, ...actions }), [actions, t]);
return [hosts, actions, actionResolver];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const InfraEnvAgentTable: React.FC<InfraEnvAgentTableProps> = ({
canEditHostname ? undefined : t('ai:Hostname cannot be changed for selected hosts.')
}
>
Change hostname
{t('ai:Change hostname')}
</DropdownItem>,
<MassApproveAction
key="approve"
Expand Down
2 changes: 1 addition & 1 deletion libs/ui-lib/lib/common/components/hosts/EditHostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const EditHostForm = ({
title={t('ai:This name will replace the original discovered hostname.')}
isInline
/>
<StaticTextField name="discoveredHostname" label="Discovered hostname">
<StaticTextField name="discoveredHostname" label={t('ai:Discovered hostname')}>
{hostname || ''}
</StaticTextField>
<RichInputField
Expand Down
16 changes: 12 additions & 4 deletions libs/ui-lib/lib/common/components/hosts/EditHostModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Modal, ModalVariant } from '@patternfly/react-core';
import { Host, Inventory } from '../../api';
import { useTranslation } from '../../hooks/use-translation-wrapper';
import EditHostForm, { EditHostFormProps } from './EditHostForm';

type EditHostModalProps = Pick<
Expand All @@ -22,11 +23,17 @@ const EditHostModal = ({
onSave,
onHostSaveError,
getEditErrorMessage,
}: EditHostModalProps) =>
host && inventory ? (
}: EditHostModalProps) => {
const { t } = useTranslation();

if (!host || !inventory) {
return null;
}

return (
<Modal
aria-label="Change hostname dialog"
title="Change hostname"
title={t('ai:Change hostname')}
isOpen={isOpen}
onClose={onClose}
variant={ModalVariant.small}
Expand All @@ -42,6 +49,7 @@ const EditHostModal = ({
onHostSaveError={onHostSaveError}
/>
</Modal>
) : null;
);
};

export default EditHostModal;
15 changes: 9 additions & 6 deletions libs/ui-lib/lib/common/components/hosts/HostToolbarActions.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as React from 'react';
import { DropdownItem } from '@patternfly/react-core';
import { useTranslation } from '../../hooks/use-translation-wrapper';

type ChangeHostnameActionProps = {
onChangeHostname: VoidFunction;
};

export const ChangeHostnameAction: React.FC<ChangeHostnameActionProps> = ({ onChangeHostname }) => (
<DropdownItem onClick={onChangeHostname}>Change hostname</DropdownItem>
);
export const ChangeHostnameAction: React.FC<ChangeHostnameActionProps> = ({ onChangeHostname }) => {
const { t } = useTranslation();
return <DropdownItem onClick={onChangeHostname}>{t('ai:Change hostname')}</DropdownItem>;
};

type DeleteHostActionProps = {
onDeleteHost: VoidFunction;
};

export const DeleteHostAction: React.FC<DeleteHostActionProps> = ({ onDeleteHost }) => (
<DropdownItem onClick={onDeleteHost}>Remove</DropdownItem>
);
export const DeleteHostAction: React.FC<DeleteHostActionProps> = ({ onDeleteHost }) => {
const { t } = useTranslation();
return <DropdownItem onClick={onDeleteHost}>{t('ai:Remove')}</DropdownItem>;
};
37 changes: 25 additions & 12 deletions libs/ui-lib/lib/common/components/hosts/tableUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ const ActionTitle: React.FC<{ disabled: boolean; description?: string; title: st

export const hostActionResolver =
({
t,
onInstallHost,
canInstallHost,
onEditHost,
Expand All @@ -385,7 +386,7 @@ export const hostActionResolver =
canEditBMH,
canUnbindHost,
onUnbindHost,
}: HostsTableActions): ActionsResolver<Host> =>
}: HostsTableActions & { t: TFunction }): ActionsResolver<Host> =>
(host) => {
const actions = [];
if (host) {
Expand All @@ -405,15 +406,19 @@ export const hostActionResolver =
if (typeof canEdit === 'boolean') {
canEdit &&
actions.push({
title: 'Change hostname',
title: t('ai:Change hostname'),
id: `button-edit-host-${hostname}`, // id is everchanging, not ideal for tests
onClick: () => onEditHost(host),
});
} else {
const [enabled, reason] = canEdit;
actions.push({
title: (
<ActionTitle disabled={!enabled} description={reason} title="Change hostname" />
<ActionTitle
disabled={!enabled}
description={reason}
title={t('ai:Change hostname')}
/>
),
id: `button-edit-host-${hostname}`, // id is everchanging, not ideal for tests
onClick: () => onEditHost(host),
Expand All @@ -424,35 +429,35 @@ export const hostActionResolver =
}
if (onHostEnable && canEnable?.(host)) {
actions.push({
title: 'Enable in cluster',
title: t('ai:Enable in cluster'),
id: `button-enable-in-cluster-${hostname}`,
onClick: () => onHostEnable(host),
});
}
if (onHostDisable && canDisable?.(host)) {
actions.push({
title: 'Disable in cluster',
title: t('ai:Disable in cluster'),
id: `button-disable-in-cluster-${hostname}`,
onClick: () => onHostDisable(host),
});
}
if (onHostReset && canReset?.(host)) {
actions.push({
title: 'Reset host',
title: t('ai:Reset host'),
id: `button-reset-host-${hostname}`,
onClick: () => onHostReset(host),
});
}
if (onViewHostEvents) {
actions.push({
title: 'View host events',
title: t('ai:View host events'),
id: `button-view-host-events-${hostname}`,
onClick: () => onViewHostEvents(host),
});
}
if (onDownloadHostLogs && canDownloadHostLogs?.(host)) {
actions.push({
title: 'Download host logs',
title: t('ai:Download host logs'),
id: `button-download-host-installation-logs-${hostname}`,
onClick: () => onDownloadHostLogs(host),
});
Expand All @@ -463,14 +468,16 @@ export const hostActionResolver =
if (typeof canDeleteHost === 'boolean') {
canDeleteHost &&
actions.push({
title: 'Remove host',
title: t('ai:Remove host'),
id: `button-delete-host-${hostname}`,
onClick: () => onDeleteHost(host),
});
} else {
const [enabled, reason] = canDeleteHost;
actions.push({
title: <ActionTitle disabled={!enabled} description={reason} title="Remove host" />,
title: (
<ActionTitle disabled={!enabled} description={reason} title={t('ai:Remove host')} />
),
id: `button-delete-host-${hostname}`,
onClick: () => onDeleteHost(host),
isDisabled: !enabled,
Expand All @@ -482,7 +489,9 @@ export const hostActionResolver =
if (canEditBMH) {
const [enabled, reason] = canEditBMH(host);
actions.push({
title: <ActionTitle disabled={!enabled} description={reason} title="Edit BMC" />,
title: (
<ActionTitle disabled={!enabled} description={reason} title={t('ai:Edit BMC')} />
),
id: `button-edit-bmh-host-${hostname}`,
onClick: () => onEditBMH(host),
isDisabled: !enabled,
Expand All @@ -494,7 +503,11 @@ export const hostActionResolver =
const [enabled, reason] = canUnbindHost(host);
actions.push({
title: (
<ActionTitle disabled={!enabled} description={reason} title="Remove from the cluster" />
<ActionTitle
disabled={!enabled}
description={reason}
title={t('ai:Remove from the cluster')}
/>
),
id: `button-unbind-host-${hostname}`,
onClick: () => onUnbindHost(host),
Expand Down
3 changes: 3 additions & 0 deletions libs/ui-lib/lib/ocm/components/hosts/use-hosts-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const useHostsTable = (cluster: Cluster) => {
} = useModalDialogsContext();
const { resetCluster } = React.useContext(AddHostsContext);
const { isViewerMode } = useSelector(selectCurrentClusterPermissionsState);
const { t } = useTranslation();

const dispatch = useDispatch();

Expand Down Expand Up @@ -330,6 +331,7 @@ export const useHostsTable = (cluster: Cluster) => {
const actionResolver = React.useMemo(
() =>
hostActionResolver({
t,
...actionChecks,
onEditRole,
onDiskRole,
Expand All @@ -342,6 +344,7 @@ export const useHostsTable = (cluster: Cluster) => {
...hostActions,
}),
[
t,
actionChecks,
hostActions,
onEditRole,
Expand Down

0 comments on commit b270560

Please sign in to comment.