Skip to content

Commit

Permalink
chore(pf5): migrate events, login, modal and recording components
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Nov 2, 2023
1 parent d4a6663 commit b353f48
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const ClickableAutomatedAnalysisLabel: React.FC<ClickableAutomatedAnalysi

return (
<Popover
aria-label={t('ClickableAutomatedAnalysisresult.ARIA_LABELS.POPOVER')}
aria-label={t('ClickableAutomatedAnalysisLabel.ARIA_LABELS.POPOVER')}
isVisible={isDescriptionVisible}
headerContent={<div className={`${clickableAutomatedAnalysisKey}-popover-header`}>{result.name}</div>}
alertSeverityVariant={alertPopoverVariant}
Expand Down
2 changes: 1 addition & 1 deletion src/app/Events/EventTemplates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const EventTemplates: React.FC<EventTemplatesProps> = (_) => {
type="search"
placeholder="Filter..."
aria-label="Event template filter"
onChange={setFilterText}
onChange={(_, value: string) => setFilterText(value)}
value={filterText}
isDisabled={errorMessage != ''}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/app/Events/EventTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const EventTypes: React.FC<EventTypesProps> = (_) => {
);

const onFilterTextChange = React.useCallback(
(filterText: string) => {
(_, filterText: string) => {
setFilterText(filterText);
setCurrentPage(1);
},
Expand Down
28 changes: 25 additions & 3 deletions src/app/Login/BasicAuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@

import { AuthMethod } from '@app/Shared/Services/service.types';
import { ServiceContext } from '@app/Shared/Services/Services';
import { ActionGroup, Button, Checkbox, Form, FormGroup, Text, TextInput, TextVariants } from '@patternfly/react-core';
import {
ActionGroup,
Button,
Checkbox,
Form,
FormGroup,
FormHelperText,
HelperText,
HelperTextItem,
Text,
TextInput,
TextVariants,
} from '@patternfly/react-core';
import { Base64 } from 'js-base64';
import * as React from 'react';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -85,7 +97,12 @@ export const BasicAuthForm: React.FC<FormProps> = ({ onSubmit }) => {

return (
<Form onSubmit={handleSubmit}>
<FormGroup label="Username" isRequired fieldId="username" helperText="Please provide your username">
<FormGroup label="Username" isRequired fieldId="username">
<FormHelperText>
<HelperText>
<HelperTextItem>Please provide your username</HelperTextItem>
</HelperText>
</FormHelperText>
<TextInput
isRequired
type="text"
Expand All @@ -97,7 +114,12 @@ export const BasicAuthForm: React.FC<FormProps> = ({ onSubmit }) => {
onKeyDown={handleKeyDown}
/>
</FormGroup>
<FormGroup label="Password" isRequired fieldId="password" helperText="Please provide your password">
<FormGroup label="Password" isRequired fieldId="password">
<FormHelperText>
<HelperText>
<HelperTextItem>Please provide your password</HelperTextItem>
</HelperText>
</FormHelperText>
<TextInput
isRequired
type="password"
Expand Down
2 changes: 1 addition & 1 deletion src/app/Modal/DeleteWarningModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const DeleteWarningModal: React.FC<DeleteWarningProps> = ({
);

const onInnerClose = React.useCallback(
(ev?: React.MouseEvent) => {
(ev?: KeyboardEvent | React.MouseEvent<Element, MouseEvent>) => {
ev && ev.stopPropagation();
onClose();
},
Expand Down
16 changes: 14 additions & 2 deletions src/app/RecordingMetadata/BulkEditLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ import {
import { ServiceContext } from '@app/Shared/Services/Services';
import { useSubscriptions } from '@app/utils/hooks/useSubscriptions';
import { hashCode, portalRoot } from '@app/utils/utils';
import { Button, Split, SplitItem, Stack, StackItem, Text, Tooltip, ValidatedOptions } from '@patternfly/react-core';
import {
Button,
Icon,
Split,
SplitItem,
Stack,
StackItem,
Text,
Tooltip,
ValidatedOptions,
} from '@patternfly/react-core';
import { HelpIcon } from '@patternfly/react-icons';
import * as React from 'react';
import { combineLatest, concatMap, filter, first, forkJoin, map, Observable, of } from 'rxjs';
Expand Down Expand Up @@ -291,7 +301,9 @@ export const BulkEditLabels: React.FC<BulkEditLabelsProps> = ({
}
appendTo={portalRoot}
>
<HelpIcon noVerticalAlign />
<Icon>
<HelpIcon />
</Icon>
</Tooltip>
</SplitItem>
</Split>
Expand Down
7 changes: 6 additions & 1 deletion src/app/RecordingMetadata/RecordingLabelFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
FormHelperText,
HelperText,
HelperTextItem,
Icon,
List,
ListItem,
Popover,
Expand Down Expand Up @@ -261,7 +262,11 @@ export const RecordingLabelFields: React.FC<RecordingLabelFieldsProps> = ({
variant="link"
aria-label="Remove Label"
isDisabled={isDisabled}
icon={<CloseIcon color="gray" size="sm" />}
icon={
<Icon size="sm">
<CloseIcon color="gray" />{' '}
</Icon>
}
/>
</SplitItem>
</Split>
Expand Down
2 changes: 1 addition & 1 deletion src/app/Recordings/ActiveRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ export const ActiveRecordingRow: React.FC<ActiveRecordingRowProps> = ({
const handleToggle = React.useCallback(() => toggleExpanded(expandedRowId), [expandedRowId, toggleExpanded]);

const handleCheck = React.useCallback(
(checked: boolean) => {
(_, checked: boolean) => {
handleRowCheck(checked, index);
},
[index, handleRowCheck],
Expand Down
2 changes: 1 addition & 1 deletion src/app/Recordings/ArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ export const ArchivedRecordingRow: React.FC<ArchivedRecordingRowProps> = ({
}, [expandedRowId, expandedRows]);

const handleCheck = React.useCallback(
(checked: boolean) => {
(_, checked: boolean) => {
handleRowCheck(checked, index);
},
[index, handleRowCheck],
Expand Down
2 changes: 1 addition & 1 deletion src/app/Recordings/Filters/DatetimeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const DateTimeFilter: React.FC<DateTimeFilterProps> = ({ onSubmit }) => {
);

const handleTextInput = React.useCallback(
(value: string) => {
(_, value: string) => {
setDatetimeInput((_) => {
if (value === '') {
return _emptyDatetimeInput;
Expand Down
4 changes: 2 additions & 2 deletions src/app/Recordings/Filters/DurationFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const DurationFilter: React.FC<DurationFilterProps> = ({
const isContinuous = React.useMemo(() => durations && durations.includes('continuous'), [durations]);

const handleContinuousCheckBoxChange = React.useCallback(
(checked) => {
(_, checked: boolean) => {
onContinuousDurationSelect(checked);
},
[onContinuousDurationSelect],
Expand All @@ -56,7 +56,7 @@ export const DurationFilter: React.FC<DurationFilterProps> = ({
value={duration}
id="duration-input"
aria-label="duration filter"
onChange={(e) => setDuration(Number(e))}
onChange={(e, value) => setDuration(Number(value))}
min="0"
onKeyDown={handleEnterKey}
/>
Expand Down
99 changes: 77 additions & 22 deletions src/app/Recordings/Filters/LabelFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@

import { parseLabels, getLabelDisplay } from '@app/RecordingMetadata/utils';
import { Recording } from '@app/Shared/Services/api.types';
import { Label } from '@patternfly/react-core';
import { Select, SelectOption, SelectVariant } from '@patternfly/react-core/deprecated';
import {
Button,
Label,
MenuToggle,
MenuToggleElement,
Select,
SelectList,
SelectOption,
SelectOptionProps,
TextInputGroup,
TextInputGroupMain,
TextInputGroupUtilities,
} from '@patternfly/react-core';
import { TimesIcon } from '@patternfly/react-icons';
import * as React from 'react';

export interface LabelFilterProps {
Expand All @@ -28,18 +40,23 @@ export interface LabelFilterProps {

export const LabelFilter: React.FC<LabelFilterProps> = ({ recordings, filteredLabels, onSubmit }) => {
const [isExpanded, setIsExpanded] = React.useState(false);
const [filterValue, setFilterValue] = React.useState('');

const onSelect = React.useCallback(
(_, selection, isPlaceholder) => {
if (!isPlaceholder) {
(_, selection: string) => {
if (selection) {
setIsExpanded(false);
onSubmit(selection);
}
},
[onSubmit, setIsExpanded],
);

const labels = React.useMemo(() => {
const onToggle = React.useCallback(() => setIsExpanded((isExpanded) => !isExpanded), [setIsExpanded]);

const onInputChange = React.useCallback((_, inputVal: string) => setFilterValue(inputVal), [setFilterValue]);

const labelOptions = React.useMemo(() => {
const labels = new Set<string>();
recordings.forEach((r) => {
if (!r || !r.metadata || !r.metadata.labels) return;
Expand All @@ -50,24 +67,62 @@ export const LabelFilter: React.FC<LabelFilterProps> = ({ recordings, filteredLa
.sort();
}, [recordings, filteredLabels]);

const filteredLabelOptions = React.useMemo(() => {
return !filterValue ? labelOptions : labelOptions.filter((l) => l.includes(filterValue.toLowerCase()));
}, [filterValue, labelOptions]);

const selectOptionProps: SelectOptionProps[] = React.useMemo(() => {
if (!filteredLabelOptions.length) {
return [{ isDisabled: true, children: `No results found for "${filterValue}"`, value: undefined }];
}
return filteredLabelOptions.map((l) => ({ children: l, value: l }));
}, [filteredLabelOptions]);

const toggle = React.useCallback(
(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} variant="typeahead" onClick={onToggle} isExpanded={isExpanded} isFullWidth>
<TextInputGroup isPlain>
<TextInputGroupMain
value={filterValue}
onClick={onToggle}
onChange={onInputChange}
autoComplete="off"
placeholder="Filter by label..."
isExpanded={isExpanded}
role="combobox"
id="typeahead-label-filter"
aria-controls="typeahead-label-select"
/>
<TextInputGroupUtilities>
{filterValue ? (
<Button
variant="plain"
onClick={() => {
setFilterValue('');
}}
aria-label="Clear input value"
>
<TimesIcon aria-hidden />
</Button>
) : null}
</TextInputGroupUtilities>
</TextInputGroup>
</MenuToggle>
),
[onToggle, isExpanded, filterValue, onInputChange, setFilterValue],
);

return (
<Select
variant={SelectVariant.typeahead}
onToggle={setIsExpanded}
onSelect={onSelect}
isOpen={isExpanded}
aria-label="Filter by label"
typeAheadAriaLabel="Filter by label..."
placeholderText="Filter by label..."
maxHeight="16em"
>
{labels.map((option, index) => (
<SelectOption key={index} value={option}>
<Label key={option} color="grey">
{option}
</Label>
</SelectOption>
))}
<Select toggle={toggle} onSelect={onSelect} isOpen={isExpanded} aria-label="Filter by label">
<SelectList id="typeahead-label-select">
{selectOptionProps.map(({ value, children }, index) => (
<SelectOption key={index} value={value}>
<Label key={value} color="grey">
{children}
</Label>
</SelectOption>
))}
</SelectList>
</Select>
);
};
Loading

0 comments on commit b353f48

Please sign in to comment.