Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

CompareFilter does not forward autocompleter setting to the Search #6890

Closed
tomalec opened this issue Apr 27, 2021 · 0 comments · Fixed by #6911
Closed

CompareFilter does not forward autocompleter setting to the Search #6890

tomalec opened this issue Apr 27, 2021 · 0 comments · Fixed by #6911
Labels
focus: components Issues for woocommerce components focus: marketing Related to Marketing Features

Comments

@tomalec
Copy link
Member

tomalec commented Apr 27, 2021

Describe the bug
This is similar to the problem with FilterPicker #6062

I'm trying to set up a <ReportFilters> with a custom type of options to be chosen. I'm not able to, as for custom type I have to provide autocompleter to the <Search> component, but <CompareFilter> does not forward this config. That results in

react-dom.development.js:22800 Uncaught Error: Invalid autocompleter provided to Search component, it requires a completer object when using 'custom' type.
    at Search.getAutocompleter (index.js?ver=1619021289:34783)
    at Search.render (index.js?ver=1619021289:34875)
    at finishClassComponent (react-dom.development.js:17295)
    at updateClassComponent (react-dom.development.js:17245)
    at beginWork (react-dom.development.js:18755)
    at HTMLUnknownElement.callCallback (react-dom.development.js:182)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:231)
    at invokeGuardedCallback (react-dom.development.js:286)
    at beginWork$1 (react-dom.development.js:23338)
    at performUnitOfWork (react-dom.development.js:22289)

To Reproduce
Steps to reproduce the behavior:

  1. Create <ReportFilters> or <CompareFilter> with settings that contains a custom type.
<ReportFilters
	  filters={ [{
	  label: 'Comparison',,
	  chartMode: 'item-comparison',
	  value: 'compare-programs',
	  settings: {
		  type: 'custom',
		  param: 'programs',
		  getLabels: () => Promise.resolve( [] ),
		  labels: {
			  helpText: 'Check at least two programs below to compare',
			  placeholder: 'Search for programs to compare'
			  title: 'Compare Programs',
			  update: 'Compare',
		  },
	  
		  autocompleter: {
			  name: 'programs',
			  options: () => Promise.resolve( arrayOfOptions ),
			  getOptionIdentifier: ( option ) => option.id,
			  getOptionLabel: ( option ) => option.name,
			  getOptionKeywords: ( option ) => [ option.name ],
			  getOptionCompletion: ( program ) => ({
				  key: program.id,
				  label: program.name,
			  }),
		  },
	  },
    ]} />
  1. See an error

Expected behavior
The component should render, with a specified autocompleter.

Screenshots
blank screen

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.2 LTS
  • Browser Chrome
  • Version 80

Smartphone (please complete the following information):

n/a

Additional context

It seems that the entire path of using any *Filter* component for a type other than predefined ('attributes', 'categories', 'countries', 'coupons', 'customers', 'downloadIps', 'emails', 'orders', 'products', 'taxes', 'usernames', 'variableProducts', 'variations') is pretty abandoned.
Maybe it's worth revisiting it as a whole, no just bug-by-bug. I noticed there are some bits of code that seems to serve custom usage, but also there are some non-WP/autocompleter -compliant properties in filters config, that is not fully explained in the docs, so I'm not sure what should I stick to when adding my own options to the filter.

As an external developer using FilterPicker or CompareFilter I was thinking that having already loaded a finite list of options would make it really straightforward to configure those components to use it. But it already took me few days trying to figure out and reverse-engineer, what additional functions, and promises I need to provide in the config, what those function should return, what promises should resolve with.

tomalec added a commit that referenced this issue Apr 29, 2021
Allow, to use the `custom` type of search, previously it was complaining about lack of `autocompleter`, even though it was provided.
Fixes: #6890
@tomalec tomalec added focus: components Issues for woocommerce components focus: marketing Related to Marketing Features labels Apr 30, 2021
tomalec added a commit that referenced this issue May 13, 2021
- Forward `autocompleter` prop from `CompareFilter` to `Search`.
	Allow, to use the `custom` type of search, 
	previously it was complaining about lack of `autocompleter`,
	even though it was provided.

- Move `path` in Storybooks example to a parameter, to allow setting it in unit tests.
- Add few tests for FilterPicker. 
	- it renders the basic storybook example without throwing an error
	- it forwards `autocompleter` & `type` props

Fixes: #6890
tomalec added a commit to woocommerce/google-listings-and-ads that referenced this issue May 20, 2021
tomalec added a commit to woocommerce/google-listings-and-ads that referenced this issue Nov 25, 2021
as those fixes were released in `@woocommerce/components`:
- woocommerce/woocommerce-admin#6890,
- woocommerce/woocommerce-admin#6062
Remove no longer needed dependencies.
ObliviousHarmony pushed a commit to woocommerce/woocommerce that referenced this issue Mar 18, 2022
…merce/woocommerce-admin#6911)

- Forward `autocompleter` prop from `CompareFilter` to `Search`.
	Allow, to use the `custom` type of search, 
	previously it was complaining about lack of `autocompleter`,
	even though it was provided.

- Move `path` in Storybooks example to a parameter, to allow setting it in unit tests.
- Add few tests for FilterPicker. 
	- it renders the basic storybook example without throwing an error
	- it forwards `autocompleter` & `type` props

Fixes: woocommerce/woocommerce-admin#6890
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: components Issues for woocommerce components focus: marketing Related to Marketing Features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant