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

Add a new InlineLabelSelect component for WCPay admin filter select inputs (with inline label) #8896

Merged
merged 25 commits into from
Jun 7, 2024

Conversation

Jinksi
Copy link
Member

@Jinksi Jinksi commented Jun 3, 2024

Resolves #8788

Changes proposed in this Pull Request

This PR introduces a new currency select component as part of the new UI for selecting currency on the Payment Overview page #8765. This PR does not make any changes to the existing UI, only introduces a new component.

Design.

image

Note, the placement of the inputs within the page is for demonstration only.

  • Introduces a new InlineLabelSelect component
  • Forked from the existing client/components/custom-select-control component (used for onboarding screens)

I've kept the API (props, interfaces) as close to the existing CustomSelectControl as practical, to allow us to adopt this for onboarding and more in the future. Differences from the existing CustomSelectControl component:

  • the label is rendered inside the input, rather than outside/above
  • options/items now accept a 'hint' property, a supplemental description for an option
  • style and UX changes to match the design

Tip

I've created code diffs to illustrate what has changed between the Gutenberg → WooPayments CustomSelectControlInlineLabelSelect:

Firstly, the diff between the Gutenberg (JSX) → WooPayments CustomSelectControl (TSX)

Secondly, the diff between the WooPayments CustomSelectControlInlineLabelSelect (this PR)

filter.select.component.demo.mov

Note, the placement of the inputs within the page is for demonstration only.

currency.select.component.demo.mov

Future

Future requirements related to this component that are not included in this initial PR:

  • The ability to add a second input in a second column with shared state (e.g. calendar input)
  • For onboarding country selection, to be implemented by @Automattic/moltres (see P2)
    • Apply and reset buttons to confirm selection
    • Search field to filter options

TODO

Testing instructions

Option A: Checkout PR #8791 which uses this component for the Payments Overview currency select

Option B: View the site Helix WooExpress site, which has PR #8791 active – find this component in use for the Payments Overview currency select.

Option C: View the demo components from the screenshot above by replacing client/components/welcome/index.tsx with the following code:

`client/components/welcome/index.tsx`
/**
 * External dependencies
 */
import React, { useState } from 'react';
import { CardBody, CardHeader, Flex, FlexItem } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import { useCurrentWpUser } from './hooks';
import wooPaymentsLogo from 'assets/images/woopayments.svg?asset';
import './style.scss';
import InlineLabelSelect, { Item } from '../inline-label-select';

type TimeOfDay = 'morning' | 'afternoon' | 'evening';
const greetingStrings = {
	withName: {
		/** translators: %s name of the person being greeted. */
		morning: __( 'Good morning, %s', 'woocommerce-payments' ),
		/** translators: %s name of the person being greeted. */
		afternoon: __( 'Good afternoon, %s', 'woocommerce-payments' ),
		/** translators: %s name of the person being greeted. */
		evening: __( 'Good evening, %s', 'woocommerce-payments' ),
	},
	withoutName: {
		morning: __( 'Good morning', 'woocommerce-payments' ),
		afternoon: __( 'Good afternoon', 'woocommerce-payments' ),
		evening: __( 'Good evening', 'woocommerce-payments' ),
	},
};

/**
 * Calculates the time of day based on the browser's time.
 *
 * @param {Date} date A date object to calculate the time of day for. Defaults to the current time.
 * @return {TimeOfDay} The time of day. One of 'morning', 'afternoon' or 'evening'.
 */
const getTimeOfDayString = ( date: Date = new Date() ): TimeOfDay => {
	const hour = date.getHours();
	// Morning 5am -11.59am
	if ( hour >= 5 && hour < 12 ) {
		return 'morning';
	}
	// Afternoon 12pm – 4:59pm
	if ( hour >= 12 && hour < 17 ) {
		return 'afternoon';
	}
	// Evening 5pm – 4:59am
	return 'evening';
};

/**
 * Returns a greeting string based on the time of day and a given name, if provided.
 *
 * @param {string} name A name to include in the greeting, optional.
 * @param {Date} date A date object to calculate the time of day for. Defaults to the current time.
 * @return {string} A greeting string.
 */
const getGreeting = ( name?: string, date: Date = new Date() ): string => {
	const timeOfDay = getTimeOfDayString( date );
	let greeting = greetingStrings.withoutName[ timeOfDay ];
	if ( name ) {
		greeting = sprintf( greetingStrings.withName[ timeOfDay ], name );
	}
	greeting += ' 👋';
	return greeting;
};

const FilterSelectDemo = () => {
	const [ selectedCurrency, setSelectedCurrency ] = useState<
		string | undefined
	>( 'USD' );
	const [ selectedPeriod, setSelectedPeriod ] = useState<
		string | undefined
	>( 'none' );

	const currencyOptions: Item[] = [
		{ key: 'USD', name: 'USD $' },
		{ key: 'EUR', name: 'EUR €' },
		{ key: 'GBP', name: 'GBP £' },
	];

	const periodOptions: Item[] = [
		{
			key: 'previous',
			name: 'Previous period',
			hint: 'May 22 – May 31 2024',
		},
		{
			key: 'current',
			name: 'Current period',
			hint: 'June 1 – June 10 2024',
		},
		{ key: 'next', name: 'Next period', hint: 'June 11 – June 20 2024' },
		{
			key: 'custom',
			name: 'Custom',
		},
		{
			key: 'none',
			name: 'No comparison',
		},
	];

	return (
		<CardBody
			style={ {
				width: 'auto',
				display: 'flex',
			} }
		>
			<InlineLabelSelect
				label="Currency"
				options={ currencyOptions }
				name="currency"
				onChange={ ( { selectedItem } ) =>
					setSelectedCurrency( selectedItem?.key )
				}
				value={ currencyOptions.find(
					( option ) => option.key === selectedCurrency
				) }
			/>
			&emsp;
			<InlineLabelSelect
				label="Compared to"
				options={ periodOptions }
				name="comparison"
				onChange={ ( { selectedItem } ) =>
					setSelectedPeriod( selectedItem?.key )
				}
				value={ periodOptions.find(
					( option ) => option.key === selectedPeriod
				) }
			/>
		</CardBody>
	);
};

/**
 * Renders a welcome card header with a greeting and the WooPayments logo.
 *
 * @return {JSX.Element} Rendered element with the account balances card header.
 */
const Welcome: React.FC = () => {
	const { user } = useCurrentWpUser();
	const greeting = getGreeting( user?.first_name );

	return (
		<CardHeader className="wcpay-welcome">
			<FilterSelectDemo />
		</CardHeader>
	);
};

export default Welcome;

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Jun 3, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 8896 or branch name add/8788-select-component-for-currency-switcher in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: c84c9a5
  • Build time: 2024-06-07 00:20:50 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Jun 3, 2024

Size Change: 0 B

Total Size: 1.25 MB

ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.08 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.08 kB
release/woocommerce-payments/assets/css/success.css 172 B
release/woocommerce-payments/assets/css/success.rtl.css 172 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.07 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.07 kB
release/woocommerce-payments/dist/blocks-checkout.js 51.1 kB
release/woocommerce-payments/dist/bnpl-announcement-rtl.css 530 B
release/woocommerce-payments/dist/bnpl-announcement.css 531 B
release/woocommerce-payments/dist/bnpl-announcement.js 20 kB
release/woocommerce-payments/dist/cart-block.js 15.3 kB
release/woocommerce-payments/dist/cart.js 4.5 kB
release/woocommerce-payments/dist/checkout-rtl.css 599 B
release/woocommerce-payments/dist/checkout.css 599 B
release/woocommerce-payments/dist/checkout.js 31.5 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 155 B
release/woocommerce-payments/dist/express-checkout.css 155 B
release/woocommerce-payments/dist/express-checkout.js 3.59 kB
release/woocommerce-payments/dist/index-rtl.css 40.7 kB
release/woocommerce-payments/dist/index.css 40.7 kB
release/woocommerce-payments/dist/index.js 293 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.28 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 59.5 kB
release/woocommerce-payments/dist/multi-currency.css 3.29 kB
release/woocommerce-payments/dist/multi-currency.js 54.7 kB
release/woocommerce-payments/dist/order-rtl.css 733 B
release/woocommerce-payments/dist/order.css 735 B
release/woocommerce-payments/dist/order.js 41.8 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.21 kB
release/woocommerce-payments/dist/payment-gateways.css 1.21 kB
release/woocommerce-payments/dist/payment-gateways.js 38.6 kB
release/woocommerce-payments/dist/payment-request-rtl.css 155 B
release/woocommerce-payments/dist/payment-request.css 155 B
release/woocommerce-payments/dist/payment-request.js 5.92 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 388 B
release/woocommerce-payments/dist/plugins-page.css 388 B
release/woocommerce-payments/dist/plugins-page.js 19.3 kB
release/woocommerce-payments/dist/product-details-rtl.css 398 B
release/woocommerce-payments/dist/product-details.css 402 B
release/woocommerce-payments/dist/product-details.js 11.2 kB
release/woocommerce-payments/dist/settings-rtl.css 11 kB
release/woocommerce-payments/dist/settings.css 10.9 kB
release/woocommerce-payments/dist/settings.js 201 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 19.4 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 693 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 18.5 kB
release/woocommerce-payments/dist/tokenized-payment-request-rtl.css 155 B
release/woocommerce-payments/dist/tokenized-payment-request.css 155 B
release/woocommerce-payments/dist/tokenized-payment-request.js 6.33 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 21 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 4.86 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 155 B
release/woocommerce-payments/dist/woopay-express-button.css 155 B
release/woocommerce-payments/dist/woopay-express-button.js 15.1 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.25 kB
release/woocommerce-payments/dist/woopay.css 4.22 kB
release/woocommerce-payments/dist/woopay.js 69.4 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 622 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 815 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.44 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 196 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 20 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 196 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 627 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 20 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 628 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 390 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 214 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 523 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 722 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 408 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 517 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.36 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.5 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.36 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.03 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 291 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 781 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.05 kB

compressed-size-action

Copy link
Contributor

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Tested by running #8791 and the component is working pretty well 🎉

I started reviewing the code and then backed out because we need to get aligned on what code to review, how to fence off Gutenberg or other "borrowed" code.

* https://github.com/WordPress/gutenberg/tree/7aa042605ff42bb437e650c39132c0aa8eb4ef95/packages/components/src/custom-select-control
*
* It has been forked from the existing WooPayments copy of this component (client/components/custom-select-control)
* to match this specific select input design with an inline label and option hints.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add to this comment a rough plan for how we might merge this upstream or reduce number of forks in WooPayments code base 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

Update: I've paused my review because I think I need to review the diff from the Gutenberg code (and maybe other WooPayments CustomSelectControl forks. @Jinksi how do you think we should handle this?

*/
import './style.scss';

export interface Item {
Copy link
Contributor

Choose a reason for hiding this comment

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

Item is pretty amorphous, can we give this a clearer name? I like DropdownItem, but that's because I'm familiar with macOS UI patterns/naming.

Looks like the current naming for this component in mac is Pop-up button. So if we follow that the items would be PopupButtonItems. Or if we stick with Select, SelectItems, or SelectControlItems.

Copy link
Member Author

@Jinksi Jinksi Jun 5, 2024

Choose a reason for hiding this comment

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

The name item was used by the Gutenberg CustomSelectControl. I assume this naming was used to match the downshift library API and naming.

https://github.com/Automattic/woocommerce-payments/blob/b56b86b1a5fda78cfc57f18b674d2d93ed621c89/client/components/filter-select-control/index.tsx/#L127-L134

However, there is no harm in changing the name of the TS Item interface to be more descriptive. I will make this change (00940a3).

style?: React.CSSProperties;
}

export interface Props< ItemType > {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious about the decision to templateise Props.

  • Do we want to allow different ItemTypes?
  • What does that allow us to do?
  • What does the TypeScript look like if we lock it down to a single SelectComponentProps, is that a better fit for our use case/user model?

I just realised that I'm probably commenting on the Gutenberg code, likely not worthwhile revisiting the Gutenberg code.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was carried over from the WooPayments CustomSelectControl. Custom item types and components are a requirement for onboarding country selection. I'm leaving this feature to allow onboarding screens to more easily adopt this new component.

@Jinksi
Copy link
Member Author

Jinksi commented Jun 5, 2024

we need to get aligned on what code to review, how to fence off Gutenberg or other "borrowed" code.

This has been an unusual challenge of this implementation – I've intentionally kept most of the naming, API, logic and styling from either Gutenberg or the existing WooPayments CustomSelectControl.

I'll see if I can find a suitable way to differentiate the changes from Gutenberg → WooPayments → this PR.

@Jinksi
Copy link
Member Author

Jinksi commented Jun 5, 2024

I'll see if I can find a suitable way to differentiate the changes from Gutenberg → WooPayments → this PR.

Firstly, the diff between the Gutenberg (JSX) → WooPayments CustomSelectControl (TSX)

Secondly, the diff between the WooPayments CustomSelectControlFilterSelectControl (this PR)

cc @haszari. I'll add this information to the PR description to help illustrate what has changed.

@Jinksi Jinksi requested a review from a team June 5, 2024 21:22
@haszari
Copy link
Contributor

haszari commented Jun 6, 2024

Awesome, thank you @Jinksi – those diffs are really instructive. I'm going to review and leave some raw notes on those diffs. Then switch focus to reviewing this PR from our project point of view.

Firstly, the diff between the Gutenberg (JSX) → WooPayments CustomSelectControl (TSX)
Gutenberg → WooPayments CustomSelectControl
This was previous work that was used for onboarding screens
The original component is JSX, so a migration to TSX occurred

Summary of the changes:

  • Adding types / TSX, some type safety checks
  • Some variables renamed / code drift?
  • New WCPay:
    • Allow a totally custom component for rendering each option, and for the placeholder
    • placeholder, i.e. display a hint value when empty
    • aria-describedBy, accessibility
    • add a wcpay class (is this essential?)
    • add specific class to value/item span
  • New WP core:
    • VisuallyHidden support (accessibility?)
    • hint support (experimentalHint)

Excluding the custom item type, I'm more confident that there's a path to using the WP component direct – most differences are minimal, and not really woo or payments specific.

The custom component … need to understand this better, and explore if there are objections/risks to that flexibility in Gutenberg. Best case maybe that feature is useful in core!

Possible next step:

  • Open a PR on Gutenberg to add the features we need for WooPayments, to see what the diff looks like, and get feedback on whether our changes are palatable for WP core.

Side note: our use of TypeScript might be a barrier to merging upstream. We should find out what WP core TypeScript policy is and if they are JS only, add a carve-out in our guidelines for code borrowed from core. (I will add a comment about this to TypeScript discussion internally)

@haszari
Copy link
Contributor

haszari commented Jun 6, 2024

Secondly, the diff between the WooPayments CustomSelectControl → Helix Payment Widget FilterSelectControl (this PR)
index.tsx
style.scss

Summary of changes:

  • Helix new:
    • Allow a totally custom component for rendering each option, and for the placeholder.
    • Customise class wcpay-filter:
      • wrapper div
      • menu element
      • button
      • icon
      • item (li)
    • Move label inside button
    • Show check mark icon on selected item in dropdown
  • No new stuff in WooPayments control, forked recently 😅
  • Assuming, CSS changes could be overridden without forking, so I didn't review in detail

The changes here are more extensive. The big one is the custom item component, I wonder if there is a way we can implement that with composition. ( 🤦🏻 I was confused )

The check mark option seems doable to add as an option. CSS would need to be explored, might be challenges there.

@Jinksi
Copy link
Member Author

Jinksi commented Jun 6, 2024

the differences are minimal

It was almost a css-only change, which I initially attempted, but the inline label and show/hiding behaviour of the selected value were the main differences that required markup changes.

get feedback on whether our changes are palatable for WP core.

Since the design of these component variants is complete we can discuss them with Gutenberg before a PR is opened. Also, with @Automattic/moltres working on the next iteration of this component, we may want to see what implementation we settle on.

@haszari
Copy link
Contributor

haszari commented Jun 6, 2024

Since the design of these component variants is complete we can discuss them with Gutenberg before a PR is opened.

Not sure what you mean by "before" – a PR is the a great way to start a discussion. But not a priority for us for this project, unless it makes it easier to get our component shipshape!

the inline label and show/hiding behaviour of the selected value were the main differences that required markup changes.

Understandable. Now that you've implemented this behaviour (these behaviours?), how would you expose them as an API or prop? i.e feature(s) that a client of CustomSelectControl can opt in to ?

  • inline label could be showLabelInsideButton or similar (?)
  • I don't understand the "show/hiding behaviour of the selected value" - can you explain this or draft a prop interface to help me understand (would be good to add to PR description/title too, sounds like this is the key value add)

@Jinksi
Copy link
Member Author

Jinksi commented Jun 6, 2024

Not sure what you mean by "before" – a PR is the a great way to start a discussion

I mean, we can show Gutenberg the new design and ask if it's something that could replace or sit alongside the existing CustomSelectComponent.

But I agree, a PR is great since it shows the code and APIs as well. This would be best to achieve once we settle on a shared API across our use-cases (including onboarding).

@haszari
Copy link
Contributor

haszari commented Jun 6, 2024

This would be best to achieve once we settle on a shared API across our use-cases (including onboarding).

That's one option; we could also advocate for our needs independently – e.g. divide and conquer strategy 🚀

@Jinksi
Copy link
Member Author

Jinksi commented Jun 6, 2024

I don't understand the "show/hiding behaviour of the selected value"

  1. The select input show Currency: CHF
  2. When opened, the input shows Currency without : or CHF
Screen.Recording.2024-06-06.at.13.55.41.mov

This is just CSS (although the inline label requires some markup changes), but since WooPayments doesn't currently require the alternative, I just made the changes. But we may want to make this a choice/prop for a Gutenberg contribution.

@haszari
Copy link
Contributor

haszari commented Jun 6, 2024

The select input show Currency: CHF
When opened, the input shows Currency without : or CHF

Thanks for explaining – that's really clear now 👍🏻 . I can see that this might be considered custom behaviour that others might not need.

@Jinksi Please add this info clearly to the PR description and title. That new custom behaviour is IMO a big reason for this PR (i.e. looking back, this PR will be where that behaviour originated).

@haszari
Copy link
Contributor

haszari commented Jun 6, 2024

InlineLabelSelect might be a good name for the new component that we need. Or if it's a prop:

<CustomSelectControl
  inlineLabel={true}
/>

I think the value disappearing thing could be considered part of the inline label functionality.

What do you think would be a good name/API for this functionality?

@Jinksi Jinksi changed the title Add a new component for WCPay admin filter select inputs Add a new component for WCPay admin filter select inputs (with inline label) Jun 6, 2024
@Jinksi
Copy link
Member Author

Jinksi commented Jun 6, 2024

InlineLabelSelect might be a good name for the new component that we need. Or if it's a prop:

@haszari I think InlineLabelSelect is a good name and clarifies the different behaviour of this component. I'll make this change (c84c9a5).

After discovering that a Gutenberg CustomSelectControl v2 is in progress, I am less concerned with maintaining interoperability. It would be best for WooPayments to make use of the v2 Gutenberg component when it is ready (it may not require a fork this time).

WordPress/gutenberg#55023

FYI @mordeth @oaratovskyi the v2 of Gutenberg's CustomSelectControl component will change to a JSX composition API rather than a props/configuration API that aligns with our P2 discussion paJDYF-dgT-p2#comment-24870. There may be an opportunity to use this for onboarding.

const UncontrolledCustomSelect = () => (
	<CustomSelect label="Colors">
		<CustomSelectItem value="Blue">
			{ /* The `defaultValue` since it wasn't defined */ }
			<span style={ { color: 'blue' } }>Blue</span>
		</CustomSelectItem>
		<CustomSelectItem value="Purple">
			<span style={ { color: 'purple' } }>Purple</span>
		</CustomSelectItem>
		<CustomSelectItem value="Pink">
			<span style={ { color: 'deeppink' } }>Pink</span>
		</CustomSelectItem>
	</CustomSelect>
);

@Jinksi Jinksi changed the title Add a new component for WCPay admin filter select inputs (with inline label) Add a new InlineLabelSelect component for WCPay admin filter select inputs (with inline label) Jun 7, 2024
@Jinksi Jinksi requested review from haszari and nagpai June 7, 2024 01:39
@Jinksi
Copy link
Member Author

Jinksi commented Jun 7, 2024

@nagpai I've requested your review here, as your PR #8910 will using this component directly.

This discussion has dived into the trade-offs, differences and approaches of the Gutenberg & WooPayments components.

This has been resolved for the most part – we can now focus on reviewing this to see if it is fit for the immediate project needs:

Copy link
Contributor

@jessy-p jessy-p left a comment

Choose a reason for hiding this comment

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

Tested this changes as part of #8791 as well as separately, working fine. Approving!

@Jinksi
Copy link
Member Author

Jinksi commented Jun 7, 2024

I’ll merge this PR and @nagpai in your PR #8910 we can iterate further if needed.

@Jinksi Jinksi added this pull request to the merge queue Jun 7, 2024
Merged via the queue into develop with commit 597aea4 Jun 7, 2024
23 checks passed
@Jinksi Jinksi deleted the add/8788-select-component-for-currency-switcher branch June 7, 2024 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Epic: Create new shared select component – for payments overview currency select initially
4 participants