Disable claim type search if filtering by channel

This commit is contained in:
Franco Montenegro 2021-02-16 13:59:16 -03:00 committed by Sean Yesmunt
parent 62c7216b43
commit ddae2e8ac5
2 changed files with 15 additions and 7 deletions

View file

@ -1,7 +1,7 @@
// @flow // @flow
import { SEARCH_OPTIONS } from 'constants/search'; import { SEARCH_OPTIONS } from 'constants/search';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import React from 'react'; import React, { useMemo } from 'react';
import { Form, FormField } from 'component/common/form'; import { Form, FormField } from 'component/common/form';
import Button from 'component/button'; import Button from 'component/button';
@ -16,6 +16,11 @@ const SearchOptions = (props: Props) => {
const { options, setSearchOption, expanded, toggleSearchExpanded } = props; const { options, setSearchOption, expanded, toggleSearchExpanded } = props;
const resultCount = options[SEARCH_OPTIONS.RESULT_COUNT]; const resultCount = options[SEARCH_OPTIONS.RESULT_COUNT];
const isFilteringByChannel = useMemo(() => {
const claimType = String(options[SEARCH_OPTIONS.CLAIM_TYPE] || '');
return claimType.includes(SEARCH_OPTIONS.INCLUDE_CHANNELS);
}, [options]);
return ( return (
<div> <div>
<Button <Button
@ -54,7 +59,7 @@ const SearchOptions = (props: Props) => {
))} ))}
</fieldset> </fieldset>
<fieldset> <fieldset disabled={isFilteringByChannel}>
<legend className="search__legend">{__('Type')}</legend> <legend className="search__legend">{__('Type')}</legend>
{[ {[
{ {
@ -85,7 +90,7 @@ const SearchOptions = (props: Props) => {
blockWrap={false} blockWrap={false}
disabled={options[SEARCH_OPTIONS.CLAIM_TYPE] === SEARCH_OPTIONS.INCLUDE_CHANNELS} disabled={options[SEARCH_OPTIONS.CLAIM_TYPE] === SEARCH_OPTIONS.INCLUDE_CHANNELS}
label={label} label={label}
checked={options[option]} checked={!isFilteringByChannel && options[option]}
onChange={() => setSearchOption(option, !options[option])} onChange={() => setSearchOption(option, !options[option])}
/> />
))} ))}
@ -97,7 +102,7 @@ const SearchOptions = (props: Props) => {
type="select" type="select"
name="result-count" name="result-count"
value={resultCount} value={resultCount}
onChange={e => setSearchOption(SEARCH_OPTIONS.RESULT_COUNT, e.target.value)} onChange={(e) => setSearchOption(SEARCH_OPTIONS.RESULT_COUNT, e.target.value)}
blockWrap={false} blockWrap={false}
label={__('Returned Results')} label={__('Returned Results')}
> >

View file

@ -46,9 +46,12 @@ export const getSearchQueryString = (query: string, options: any = {}) => {
if (claimType) { if (claimType) {
queryParams.push(`claimType=${claimType}`); queryParams.push(`claimType=${claimType}`);
const searchingFiles = claimType.includes(SEARCH_OPTIONS.INCLUDE_FILES); /*
* Due to limitations in lighthouse, we can't pass
if (searchingFiles) { * the mediaType parameter when searching for
* channels or "everything".
*/
if (!claimType.includes(SEARCH_OPTIONS.INCLUDE_CHANNELS)) {
queryParams.push( queryParams.push(
`mediaType=${[ `mediaType=${[
SEARCH_OPTIONS.MEDIA_FILE, SEARCH_OPTIONS.MEDIA_FILE,