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

Refactor PostSchedule to make calendar/clock available as components #4180

Merged
merged 8 commits into from
Dec 27, 2017
Merged

Refactor PostSchedule to make calendar/clock available as components #4180

merged 8 commits into from
Dec 27, 2017

Conversation

travislopes
Copy link
Contributor

This PR refactors the PostSchedule editor component to make the date and time picker available as components throughout Gutenberg. You can call the date and time picker together via DateTimePicker or individually via DatePicker and TimePicker respectively. As DatePicker utilizes the React DatePicker library, the spread operator is used to support passing arguments not directly defined by these components.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Nice work here 👍

/**
* WordPress dependencies
*/
import { settings } from '@wordpress/date';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer if we avoid using the date module in the components module to keep it as generic as possible?

/**
* External dependencies
*/
import { default as ReactDatePicker } from 'react-datepicker';
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: this could be import ReactDatePicker from 'react-datepicker';

Copy link
Contributor

Choose a reason for hiding this comment

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

(Note that we may change react-datepicker later as it's not accessible.

import { DatePicker } from './date';
import { TimePicker } from './time';

export { DatePicker } from './date';
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we already imported those, we could drop the from

export { DatePicker, TimePicker }


/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import Button from '../button';
import { settings } from '@wordpress/date';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we may avoid this dependency and just add a is12Hour prop instead?

export { DatePicker } from './date';
export { TimePicker } from './time';

export function DateTimePicker( { currentDate, onChange, locale, ...args } ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could be exported as "default"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exporting the function as default doesn't seem possible; doing so returns undefined when React attempts to render it.

is12Hour={ is12HourTime }
/>,
];
return <DateTimePicker
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, for multi-lines elements, we tend to wrap them in () so something like

return (
  <Component
    prop={ value }
  />
);

@youknowriad
Copy link
Contributor

Thanks for the changes, just one last thing I forgot: we should add "moment" to the dependencies of the "wp-components" script in lib/client-assets.php.

Also, do you mind adding a README.md for these components (see other components for README examples)

@travislopes
Copy link
Contributor Author

Added a README.md for the components; probably needs some adjustments but it's a start.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, this is ready for prime time

@youknowriad
Copy link
Contributor

youknowriad commented Dec 27, 2017

@travislopes It looks like the unit tests are failing because of eslint. It might be a good idea to install an eslint plugin for your IDE of choice. This will help you catch those lint errors early.

You can still run npm run lint locally :)
Might be good to run the JS unit tests as well npm run test-unit

@@ -10,7 +10,7 @@ import moment from 'moment';
import { __ } from '@wordpress/i18n';
import Button from '../button';

export function TimePicker( { currentTime, onChange, is12Hour, ...args } ) {
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 makes me wonder if the extra args are really necessary for the DateTimePicker and DatePicker. It may be better if we're explicit here. (for example, explicitly pass the locale prop to the DatePicker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TimePicker makes 100% sense to remove the extra args from since no other variables are utilized.

DatePicker, and therefore DateTimePicker, however I believe should allow it as it will allow developers extending it to utilize everything the DatePicker component has to offer: filtering which dates are including, highlighting dates, onSelect events, enabling month/year dropdowns, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, let's remove passing the extra args to the TimePicker

@youknowriad youknowriad merged commit e3e849f into WordPress:master Dec 27, 2017
@travislopes travislopes deleted the add/datetime-picker branch December 27, 2017 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants