Skip to content

Commit

Permalink
Update to PF5 - part II - handle rest of event handlers
Browse files Browse the repository at this point in the history
Reference: #1098

For avoiding uncaught PF 4 -> PF 5 migration errors, this PR named and typed
(i.e. (add type to function signature) the following callbacks appearances which use parameters:
 onFilter
 onTextInput
 onClear
 onDrop
 onInputKeyDown
 onSetPage
 onPerPageSelect
 onUserMinus
 onUserPlus
 onDataChange
 onTextChange

Signed-off-by: Sharon Gratch <[email protected]>
  • Loading branch information
sgratch committed Jul 18, 2024
1 parent ae6d381 commit 60691e8
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 30 deletions.
5 changes: 4 additions & 1 deletion packages/common/src/components/Filter/AutocompleteFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const AutocompleteFilter = ({

const options = validSupported.map(({ label }) => <SelectOption key={label} value={label} />);

const onFilter = (_, textInput) => {
const onFilter: (
event: React.ChangeEvent<HTMLInputElement> | null,
textInput: string,
) => React.ReactElement[] | undefined = (_event, textInput) => {
if (textInput === '') {
return options;
}
Expand Down
15 changes: 13 additions & 2 deletions packages/common/src/components/Filter/FreetextFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export const FreetextFilter = ({
placeholderLabel,
}: FilterTypeProps) => {
const [inputValue, setInputValue] = useState('');
const onTextInput = (): void => {

const onTextInput: (
event: React.SyntheticEvent<HTMLButtonElement>,
value: string,
attrValueMap: {
[key: string]: string;
},
) => void = () => {
if (!inputValue || selectedFilters.includes(inputValue)) {
return;
}
Expand All @@ -39,6 +46,10 @@ export const FreetextFilter = ({
setInputValue(value);
};

const onClear: (event: React.SyntheticEvent<HTMLButtonElement>) => void = () => {
setInputValue('');
};

return (
<ToolbarFilter
key={filterId}
Expand All @@ -56,7 +67,7 @@ export const FreetextFilter = ({
value={inputValue}
onChange={onChange}
onSearch={onTextInput}
onClear={() => setInputValue('')}
onClear={onClear}
/>
</InputGroup>
</ToolbarFilter>
Expand Down
5 changes: 4 additions & 1 deletion packages/common/src/components/Filter/GroupedEnumFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export const GroupedEnumFilter = ({
</SelectGroup>
));

const onFilter = (_, textInput) => {
const onFilter: (
event: React.ChangeEvent<HTMLInputElement> | null,
textInput: string,
) => React.ReactElement[] | undefined = (_event, textInput) => {
if (textInput === '') {
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DataListItemRow,
DragDrop,
Draggable,
DraggableItemPosition,
Droppable,
Modal,
Text,
Expand Down Expand Up @@ -96,7 +97,10 @@ export const ManageColumnsModal = ({
}: ManagedColumnsProps) => {
const [editedColumns, setEditedColumns] = useState(filterActionsAndHidden(resourceFields));
const restoreDefaults = () => setEditedColumns([...filterActionsAndHidden(defaultColumns)]);
const onDrop = (source: { index: number }, dest: { index: number }) => {
const onDrop: (source: DraggableItemPosition, dest?: DraggableItemPosition) => boolean = (
source: { index: number },
dest: { index: number },
) => {
const draggedItem = editedColumns[source?.index];
const itemCurrentlyAtDestination = editedColumns[dest?.index];
if (!draggedItem || !itemCurrentlyAtDestination) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const FilterableSelect: React.FunctionComponent<FilterableSelectProps> =
* @param {React.FormEvent<HTMLInputElement>} _event The input event.
* @param {string} value The new input value.
*/
const onTextInputChange: (_event: React.FormEvent<HTMLInputElement>, value: string) => void = (
const onTextInputChange: (event: React.FormEvent<HTMLInputElement>, value: string) => void = (
_event,
value,
) => {
Expand Down Expand Up @@ -187,7 +187,7 @@ export const FilterableSelect: React.FunctionComponent<FilterableSelectProps> =
*
* @param {React.KeyboardEvent<HTMLInputElement>} event The keyboard event.
*/
const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
const onInputKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (event) => {
const enabledMenuItems = selectOptions.filter((menuItem) => !menuItem.isDisabled);
const [firstMenuItem] = enabledMenuItems;
const focusedItem = focusedItemIndex ? enabledMenuItems[focusedItemIndex] : firstMenuItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,27 @@ export function StandardPage<T>({
.filter((field) => field.filter?.primary)
.map(toFieldFilter(sortedData));

const onSetPage: (
event: React.MouseEvent | React.KeyboardEvent | MouseEvent,
newPage: number,
perPage?: number,
startIdx?: number,
endIdx?: number,
) => void = (_event, newPage) => {
setPage(newPage);
};

const onPerPageSelect: (
event: React.MouseEvent | React.KeyboardEvent | MouseEvent,
newPerPage: number,
newPage: number,
startIdx?: number,
endIdx?: number,
) => void = (_event, perPage, page) => {
setPerPage(perPage);
setPage(page);
};

return (
<span className={className}>
{title && (
Expand Down Expand Up @@ -413,11 +434,8 @@ export function StandardPage<T>({
perPage={itemsPerPage}
page={currentPage}
itemCount={filteredData.length}
onSetPage={(even, page) => setPage(page)}
onPerPageSelect={(even, perPage, page) => {
setPerPage(perPage);
setPage(page);
}}
onSetPage={onSetPage}
onPerPageSelect={onPerPageSelect}
/>
</ToolbarItem>
)}
Expand Down Expand Up @@ -460,11 +478,8 @@ export function StandardPage<T>({
perPage={itemsPerPage}
page={currentPage}
itemCount={filteredData.length}
onSetPage={(_event, page) => setPage(page)}
onPerPageSelect={(_event, perPage, page) => {
setPerPage(perPage);
setPage(page);
}}
onSetPage={onSetPage}
onPerPageSelect={onPerPageSelect}
/>
)}
</PageSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const SettingsNumberInput: React.FC<SettingsSelectInputProps> = ({
onChange(newValue.toString());
};

const onUserMinus = () => {
const onUserMinus: (event: React.MouseEvent, name?: string) => void = () => {
const newValue = (value || 0) - 1;
setNewValue(newValue);
};

const onUserPlus = () => {
const onUserPlus: (event: React.MouseEvent, name?: string) => void = () => {
const newValue = (value || 0) + 1;
setNewValue(newValue);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ export const SearchInputProvider: React.FunctionComponent<SearchInputProviderPro
updateNameFilter(value);
};

const onClear: (event: React.SyntheticEvent<HTMLButtonElement>) => void = () => {
updateNameFilter('');
};

return (
<div className="forklift--create-plan--search-input-provider">
<SearchInput
placeholder={t('Filter provider')}
value={filterState.nameFilter}
onChange={onChange}
onClear={() => updateNameFilter('')}
onClear={onClear}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export const EsxiCredentialsEdit: React.FC<EditComponentProps> = ({ secret, onCh
handleChange('insecureSkipVerify', checked ? 'true' : 'false');
};

const onDataChange: (data: string) => void = (data) => {
handleChange('cacert', data);
};

const onTextChange: (text: string) => void = (text) => {
handleChange('cacert', text);
};

return (
<Form isWidthLimited className="forklift-section-secret-edit">
<FormGroupWithHelpText
Expand Down Expand Up @@ -230,8 +238,8 @@ export const EsxiCredentialsEdit: React.FC<EditComponentProps> = ({ secret, onCh
url={url}
value={cacert}
validated={state.validation.cacert.type}
onDataChange={(value) => handleChange('cacert', value)}
onTextChange={(value) => handleChange('cacert', value)}
onDataChange={onDataChange}
onTextChange={onTextChange}
onClearClick={() => handleChange('cacert', '')}
isDisabled={insecureSkipVerify === 'true'}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export const OpenshiftCredentialsEdit: React.FC<EditComponentProps> = ({ secret,
handleChange('insecureSkipVerify', checked ? 'true' : 'false');
};

const onDataChange: (data: string) => void = (data) => {
handleChange('cacert', data);
};

const onTextChange: (text: string) => void = (text) => {
handleChange('cacert', text);
};

return (
<Form isWidthLimited className="forklift-section-secret-edit">
<FormGroupWithHelpText
Expand Down Expand Up @@ -206,8 +214,8 @@ export const OpenshiftCredentialsEdit: React.FC<EditComponentProps> = ({ secret,
filenamePlaceholder="Drag and drop a file or upload one"
value={cacert}
validated={state.validation.cacert.type}
onDataChange={(value) => handleChange('cacert', value)}
onTextChange={(value) => handleChange('cacert', value)}
onDataChange={onDataChange}
onTextChange={onTextChange}
onClearClick={() => handleChange('cacert', '')}
browseButtonText="Upload"
url={url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ export const OpenstackCredentialsEdit: React.FC<EditComponentProps> = ({ secret,
handleChange('insecureSkipVerify', checked ? 'true' : 'false');
};

const onDataChange: (data: string) => void = (data) => {
handleChange('cacert', data);
};

const onTextChange: (text: string) => void = (text) => {
handleChange('cacert', text);
};

return (
<Form isWidthLimited className="forklift-section-secret-edit">
<FormGroupWithHelpText
Expand Down Expand Up @@ -283,8 +291,8 @@ export const OpenstackCredentialsEdit: React.FC<EditComponentProps> = ({ secret,
filenamePlaceholder="Drag and drop a file or upload one"
value={cacert}
validated={state.validation.cacert.type}
onDataChange={(value) => handleChange('cacert', value)}
onTextChange={(value) => handleChange('cacert', value)}
onDataChange={onDataChange}
onTextChange={onTextChange}
onClearClick={() => handleChange('cacert', '')}
browseButtonText="Upload"
url={url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export const OvirtCredentialsEdit: React.FC<EditComponentProps> = ({ secret, onC
handleChange('insecureSkipVerify', checked ? 'true' : 'false');
};

const onDataChange: (data: string) => void = (data) => {
handleChange('cacert', data);
};

const onTextChange: (text: string) => void = (text) => {
handleChange('cacert', text);
};

return (
<Form isWidthLimited className="forklift-section-secret-edit">
<FormGroupWithHelpText
Expand Down Expand Up @@ -237,8 +245,8 @@ export const OvirtCredentialsEdit: React.FC<EditComponentProps> = ({ secret, onC
filenamePlaceholder="Drag and drop a file or upload one"
value={cacert}
validated={state.validation.cacert.type}
onDataChange={(value) => handleChange('cacert', value)}
onTextChange={(value) => handleChange('cacert', value)}
onDataChange={onDataChange}
onTextChange={onTextChange}
onClearClick={() => handleChange('cacert', '')}
browseButtonText="Upload"
url={url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export const VCenterCredentialsEdit: React.FC<EditComponentProps> = ({ secret, o
handleChange('insecureSkipVerify', checked ? 'true' : 'false');
};

const onDataChange: (data: string) => void = (data) => {
handleChange('cacert', data);
};

const onTextChange: (text: string) => void = (text) => {
handleChange('cacert', text);
};

return (
<Form isWidthLimited className="forklift-section-secret-edit">
<FormGroupWithHelpText
Expand Down Expand Up @@ -216,8 +224,8 @@ export const VCenterCredentialsEdit: React.FC<EditComponentProps> = ({ secret, o
url={url}
value={cacert}
validated={state.validation.cacert.type}
onDataChange={(value) => handleChange('cacert', value)}
onTextChange={(value) => handleChange('cacert', value)}
onDataChange={onDataChange}
onTextChange={onTextChange}
onClearClick={() => handleChange('cacert', '')}
isDisabled={insecureSkipVerify === 'true'}
/>
Expand Down

0 comments on commit 60691e8

Please sign in to comment.