Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@
"Expand row": "Expand row",
"{page} of <2>{totalPages}</2>": "{page} of <2>{totalPages}</2>",
"{{ numberOfItems }} items": "{{ numberOfItems }} items",
"Search value cannot contain spaces": "Search value cannot contain spaces",
"Waiting for terminal session to open...": "Waiting for terminal session to open...",
"Architecture": "Architecture",
"Agent version": "Agent version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const DecommissionedDevicesTable = ({
<Switch
id="decommissioned-devices-switch"
label={<span className="fctl-switch__label">{t('Show decommissioned devices')}</span>}
aria-checked
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds the required accessibility field for checkboxes (same for the enrolledDevicesTable)

isChecked
onChange={() => {
setOnlyDecommissioned(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const EnrolledDevicesTable = ({
id="enrolled-devices-switch"
label={<span className="fctl-switch__label">{t('Show decommissioned devices')}</span>}
isChecked={false}
aria-checked={false}
onChange={() => {
clearAllFilters();
setOnlyDecommissioned(true);
Expand Down
72 changes: 60 additions & 12 deletions libs/ui-components/src/components/Table/TableTextSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,70 @@
import * as React from 'react';
import { HelperText, HelperTextItem, SearchInput, SearchInputProps, Stack, StackItem } from '@patternfly/react-core';

import { SearchInput, SearchInputProps } from '@patternfly/react-core';
import { useTranslation } from '../../hooks/useTranslation';

export type TableTextSearchProps = Omit<SearchInputProps, 'onChange' | 'aria-label'> & {
export type TableTextSearchProps = Omit<SearchInputProps, 'onChange' | 'onClear' | 'aria-label'> & {
setValue: (val: string) => void;
onClear?: VoidFunction;
};

const TableTextSearch: React.FC<TableTextSearchProps> = ({ value, setValue, placeholder, onClear, ...rest }) => {
const TableTextSearch: React.FC<TableTextSearchProps> = ({ value, setValue, placeholder, ...rest }) => {
const { t } = useTranslation();
const [hasError, setHasError] = React.useState<boolean>(false);
const [actualValue, setActualValue] = React.useState<string>(value || '');

React.useEffect(() => {
// When the value is cleared externally, reset the component state
if (value === '') {
setActualValue('');
setHasError(false);
}
}, [value]);

const handleClear = React.useCallback(() => {
setActualValue('');
setValue('');
setHasError(false);
}, [setValue]);

const handleChange = React.useCallback(
(_event: React.FormEvent<HTMLInputElement>, newValue: string) => {
setActualValue(newValue);

if (newValue === '') {
handleClear();
} else {
const stripped = newValue.replace(/\s/g, '');
if (stripped === newValue) {
setValue(stripped);
setHasError(false);
} else {
setHasError(true);
}
}
},
[handleClear, setValue],
);

return (
<SearchInput
aria-label={placeholder}
onChange={(_event, value) => (value === '' && onClear ? onClear() : setValue(value))}
value={value}
placeholder={placeholder}
onClear={() => (onClear ? onClear() : setValue(''))}
{...rest}
/>
<Stack>
<StackItem>
<SearchInput
aria-label={placeholder}
onChange={handleChange}
value={actualValue}
placeholder={placeholder}
onClear={handleClear}
{...rest}
/>
</StackItem>
{hasError && (
<StackItem className="pf-v6-u-mt-sm">
<HelperText>
<HelperTextItem variant="error">{t('Search value cannot contain spaces')}</HelperTextItem>
</HelperText>
</StackItem>
)}
</Stack>
);
};

Expand Down
Loading