Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BWAP-806 updating paginator component to hand textField properties #1242

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 10 additions & 5 deletions src/components/Paginator/Paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SingleSelectDumb as SingleSelect,
ISingleSelectState,
} from '../SingleSelect/SingleSelect';
import TextField, { ITextFieldProps } from '../TextField/TextField';
import TextField, { ITextFieldProps, ITextFieldPropsWithPassThroughs } from '../TextField/TextField';
import { IButtonProps, Button } from '../Button/Button';
import ArrowIcon from '../Icon/ArrowIcon/ArrowIcon';
import { buildModernHybridComponent } from '../../util/state-management';
Expand All @@ -35,6 +35,10 @@ type IPaginatorSingleSelectProps = Partial<ISingleSelectProps>;

type ShowTotalObjects = (count: number) => string;

interface IExtendedTextFieldProps extends Omit<ITextFieldProps, 'value'> {
Copy link
Member

@tsantef tsantef Sep 13, 2021

Choose a reason for hiding this comment

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

Why do you need to redefine the value field?

value?: string | number
}

export interface IPaginatorProps
extends StandardProps,
React.DetailedHTMLProps<
Expand Down Expand Up @@ -116,7 +120,7 @@ export interface IPaginatorProps
/** Object of TextField props which are passed thru to the underlying TextField component. */

//TextField: TextField.defaultProps;
TextField: ITextFieldProps;
TextField: IExtendedTextFieldProps;
}

export interface IPaginatorState {
Expand Down Expand Up @@ -242,6 +246,7 @@ class Paginator extends React.Component<IPaginatorProps, IPaginatorState> {
event: React.FocusEvent | React.FormEvent;
}
): void => {
console.log(pageNum);
Copy link
Contributor

Choose a reason for hiding this comment

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

might want to remove the log statement here unless it's intentional

const { onPageSelect, selectedPageIndex, totalPages } = this.props;
const parsedPageNum = _.parseInt(pageNum);
if (_.isNaN(parsedPageNum)) {
Expand Down Expand Up @@ -310,11 +315,11 @@ class Paginator extends React.Component<IPaginatorProps, IPaginatorState> {
<ArrowIcon direction='left' />
</Button>
<TextField
lazyLevel={100}
{...textFieldProps}
lazyLevel={100}
onBlur={this.handleTextFieldChange}
onSubmit={this.handleTextFieldChange}
isDisabled={isDisabled}
isDisabled={isDisabled || textFieldProps.isDisabled}
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be covered in a test case?

{...textFieldProps}
Copy link
Contributor

Choose a reason for hiding this comment

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

this change of order would result in textFieldProps.isDisabled taking precedence over isDisabled.
if not intentional change, would leave the spread operator on the line above

Copy link
Author

Choose a reason for hiding this comment

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

Good callout. Updated and added a test case as an example for this.

value={selectedPageIndex + 1}
/>
{!_.isNil(totalPages) && <span>of {totalPages.toLocaleString()}</span>}
Expand Down
85 changes: 85 additions & 0 deletions src/components/Paginator/examples/5.text-field-props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import createClass from 'create-react-class';
import { Paginator } from '../../../index';

export default createClass({
getInitialState() {
return {
selectedPageIndex: 0,
};
},
render() {
return (
<div>
<p>A paginator where textField is disabled using textFieldProps.</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
isDisabled: true,
}}
/>
</section>

<p>A paginator where textField is disabled using textFieldProps and is passed an index value.</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
value: 3,
isDisabled: true,
}}
/>
</section>

<p>On submit</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
value: 3,
isDisabled: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

unless covered by another storybook example - also include an example if isDisabled: false (assume it is covered as the default value)

Copy link
Author

Choose a reason for hiding this comment

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

Covered by new storybook example

}}
/>
</section>

<p>On blur</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
value: this.state.selectedPageIndex,
onBlur: (value) => {this.setState(
{selectedPageIndex: value}
)}
}}
/>
</section>
</div>
);
},
});