Skip to content

Commit

Permalink
chore: localize stored credentials table
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Aug 23, 2024
1 parent bc70e39 commit 579136e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
1 change: 1 addition & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"ADD": "Add",
"ARCHIVAL_PERIOD": "Archival Period",
"AriaLabels": {
"MAXIMUM_AGE": "Maximum age value",
Expand Down
8 changes: 8 additions & 0 deletions locales/en/public.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@
"TABLE": "Shortcuts table"
}
},
"StoredCredentials": {
"ARIA_LABELS": {
"Add": "add-credential",
"Delete": "delete-selected-credential"
},
"AT_LEAST_ONE_MATCH": ">= 1 Match Only",
"NO_MATCH": "No Match Only"
},
"TargetContextSelector": {
"CLEAR_SELECTION": "Clear selection",
"CREATE_TARGET": "Create Target",
Expand Down
94 changes: 51 additions & 43 deletions src/app/SecurityPanel/Credentials/StoredCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ import {
Text,
TextContent,
TextVariants,
Toolbar,
ToolbarContent,
ToolbarItem,
EmptyStateHeader,
Dropdown,
DropdownList,
DropdownItem,
MenuToggleElement,
MenuToggle,
MenuToggleCheckbox,
ActionList,
ActionListItem,
} from '@patternfly/react-core';
import { OutlinedQuestionCircleIcon, SearchIcon } from '@patternfly/react-icons';
import { ExpandableRowContent, Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { forkJoin } from 'rxjs';
import { SecurityCard } from '../types';
import { CreateCredentialModal } from './CreateCredentialModal';
Expand Down Expand Up @@ -181,6 +181,7 @@ const tableColumns: TableColumn[] = [
const tableTitle = 'Stored Credentials';

export const StoredCredentials = () => {
const { t } = useTranslation();
const context = React.useContext(ServiceContext);
const [state, dispatch] = React.useReducer(reducer, {
credentials: [] as StoredCredential[],
Expand Down Expand Up @@ -278,49 +279,51 @@ export const StoredCredentials = () => {
setWarningModalOpen(false);
}, [setWarningModalOpen]);

const TargetCredentialsToolbar = () => {
const buttons = React.useMemo(() => {
const arr = [
<Button key="add" variant="primary" aria-label="add-credential" onClick={handleAuthModalOpen}>
Add
</Button>,
<Button
key="delete"
variant="danger"
aria-label="delete-selected-credential"
onClick={handleDeleteButton}
isDisabled={!state.checkedCredentials.length}
>
Delete
</Button>,
];
return (
<>
{arr.map((btn, idx) => (
<ToolbarItem key={idx}>{btn}</ToolbarItem>
))}
</>
);
}, []);
const targetCredentialsToolbar = React.useMemo(() => {
const buttons = [
<Button
key="add"
variant="primary"
aria-label={t('StoredCredentials.ARIA_LABELS.Add')}
onClick={handleAuthModalOpen}
>
{t('ADD', { ns: 'common' })}
</Button>,
<Button
key="delete"
variant="danger"
aria-label={t('StoredCredentials.ARIA_LABELS.Delete')}
onClick={handleDeleteButton}
isDisabled={!state.checkedCredentials.length}
>
{t('DELETE', { ns: 'common' })}
</Button>,
];

const deleteCredentialModal = React.useMemo(() => {
return (
return (
<>
<ActionList>
{buttons.map((btn, idx) => (
<ActionListItem key={idx}>{btn}</ActionListItem>
))}
</ActionList>
<DeleteWarningModal
warningType={DeleteOrDisableWarningType.DeleteCredentials}
visible={warningModalOpen}
onAccept={handleDeleteCredentials}
onClose={handleWarningModalClose}
/>
);
}, []);

return (
<Toolbar id="target-credentials-toolbar">
<ToolbarContent>{buttons}</ToolbarContent>
{deleteCredentialModal}
</Toolbar>
</>
);
};
}, [
t,
handleAuthModalOpen,
handleDeleteButton,
warningModalOpen,
handleDeleteCredentials,
handleWarningModalClose,
state.checkedCredentials.length,
]);

const matchExpressionRows = React.useMemo(() => {
return sortResources(sortBy, state.credentials, tableColumns).map((credential, idx) => {
Expand Down Expand Up @@ -414,7 +417,7 @@ export const StoredCredentials = () => {
<>
<EmptyState>
<EmptyStateHeader
titleText={<>No{tableTitle}</>}
titleText={<>No {tableTitle}</>}
icon={<EmptyStateIcon icon={SearchIcon} />}
headingLevel="h4"
/>
Expand Down Expand Up @@ -455,7 +458,7 @@ export const StoredCredentials = () => {

return (
<>
<TargetCredentialsToolbar />
{targetCredentialsToolbar}
{content}
<CreateCredentialModal
visible={showAuthModal}
Expand All @@ -479,18 +482,21 @@ export const CheckBoxActions: React.FC<CheckBoxActionsProps> = ({
onSelectAll,
isSelectAll,
}) => {
const { t } = useTranslation();
const [isOpen, setIsOpen] = React.useState(false);

const handleToggle = React.useCallback(() => setIsOpen((isOpen) => !isOpen), [setIsOpen]);

const dropdownItems = React.useMemo(() => {
return [
<DropdownItem key="action" onClick={onNoMatchSelect}>
No Match Only
{t('StoredCredentials.NO_MATCH')}
</DropdownItem>,
<DropdownItem key="action" onClick={onAtLeastOneMatchSelect}>
{t('StoredCredentials.AT_LEAST_ONE_MATCH')}
</DropdownItem>,
<DropdownItem key="action" onClick={onAtLeastOneMatchSelect}>{`>= 1 Match Only`}</DropdownItem>,
];
}, [onNoMatchSelect, onAtLeastOneMatchSelect]);
}, [onNoMatchSelect, onAtLeastOneMatchSelect, t]);

const toggle = React.useCallback(
(toggleRef: React.Ref<MenuToggleElement>) => (
Expand Down Expand Up @@ -520,6 +526,8 @@ export const CheckBoxActions: React.FC<CheckBoxActionsProps> = ({
}}
toggle={toggle}
isOpen={isOpen}
onOpenChange={setIsOpen}
onOpenChangeKeys={['Escape']}
popperProps={{
appendTo: portalRoot,
}}
Expand Down

0 comments on commit 579136e

Please sign in to comment.