Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
reebalazs committed Jan 25, 2024
1 parent f1cb4f6 commit 38147b2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 55 deletions.
10 changes: 3 additions & 7 deletions src/components/theme/SolrSearch/SearchConditions.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { SearchConditionsField } from './SearchConditionsField';
import { useState, useCallback, useEffect, useMemo } from 'react';

const spy = (checked) => {
console.log('_ =>', checked);
return checked;
};
import { useCallback, useMemo } from 'react';

function isEmpty(obj) {
for (const prop in obj) {
Expand All @@ -24,6 +19,7 @@ export const decodeConditionTree = (encoded, { catchError } = {}) => {
return JSON.parse(atob(encoded));
} catch (exc) {
if (catchError) {
// eslint-disable-next-line no-console
console.warn(
`Ignored broken facet_conditions value [${encoded}] [${exc.message}]`,
);
Expand Down Expand Up @@ -76,7 +72,7 @@ export const SearchConditions = ({
...(conditionTree[fieldName] || {}),
c: {
...(conditionTree[fieldName]?.c || {}),
[value]: spy(checked),
[value]: checked,
},
},
})),
Expand Down
2 changes: 2 additions & 0 deletions src/components/theme/SolrSearch/SearchConditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('SOLR SearchConditions', () => {
jest.spyOn(console, 'warn').mockImplementation(jest.fn());
});
afterEach(() => {
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
it('works', () => {
Expand All @@ -39,6 +40,7 @@ describe('SOLR SearchConditions', () => {
});
it('errors are ignored with {catchError: true}', () => {
expect(decodeConditionTree('BORKEN', { catchError: true })).toEqual({});
// eslint-disable-next-line no-console
expect(console.warn.mock.calls).toHaveLength(1);
});
});
Expand Down
15 changes: 7 additions & 8 deletions src/components/theme/SolrSearch/SearchConditionsField.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { SearchConditionsValue } from './SearchConditionsValue';
import { useCallback, useMemo, useState } from 'react';
import { useCallback, useMemo } from 'react';
import { ShowMoreIndicator } from './ShowMoreIndicator';
import { SearchConditionsFieldSearch } from './SearchConditionsFieldSearch';

const empty = {};
const maxString = String.fromCharCode(255);

const spy = (fieldDef) => {
console.log('RENDER FIELD', fieldDef);
return fieldDef;
};

export const SearchConditionsField = ({
fieldDef,
Expand Down Expand Up @@ -68,7 +62,7 @@ export const SearchConditionsField = ({
() => (
<div className="searchConditionsField">
<div className="searchConditionsFieldHeader">
{spy(fieldDef.label ?? fieldDef.name)}
{fieldDef.label ?? fieldDef.name}
<SearchConditionsFieldSearch value={prefix} setValue={setPrefix} />
</div>
<div className="searchConditionsFieldContent">
Expand All @@ -90,10 +84,15 @@ export const SearchConditionsField = ({
),
// eslint-disable-next-line react-hooks/exhaustive-deps
[
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(fieldDef),
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(values),
// eslint-disable-next-line react-hooks/exhaustive-deps
prefix,
// eslint-disable-next-line react-hooks/exhaustive-deps
more,
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(condition),
],
);
Expand Down
11 changes: 2 additions & 9 deletions src/components/theme/SolrSearch/SearchConditionsValue.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Checkbox } from 'semantic-ui-react';
import { useState, useCallback, useMemo, useEffect } from 'react';

const spy = (value) => {
console.log('RENDER VALUE', value);
return value;
};
import { useCallback, useMemo } from 'react';

const ValueLabel = ({ value }) => (
<span className="searchConditionsHasValueLabel">{value}</span>
Expand All @@ -23,8 +18,6 @@ export const SearchConditionsValue = ({
]);
const checked = condition[value];

const fieldDefCmp = JSON.stringify(fieldDef);

return useMemo(
() =>
value ? (
Expand All @@ -37,7 +30,7 @@ export const SearchConditionsValue = ({
<div className="searchConditionsCounter" />
)}
<div className="searchConditionsLabel">
<ValueLabel value={spy(value)} />
<ValueLabel value={value} />
</div>
<div className="searchConditionsCheckbox">
<Checkbox
Expand Down
1 change: 1 addition & 0 deletions src/components/theme/SolrSearch/SearchQuery.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('SOLR SearchQuery', () => {
jest.spyOn(console, 'warn').mockImplementation(jest.fn());
});
afterEach(() => {
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
it('works', () => {
Expand Down
15 changes: 7 additions & 8 deletions src/components/theme/SolrSearch/SelectLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { useEffect } from 'react';
import { useIntl, defineMessages } from 'react-intl';
import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
import {
customSelectStyles,
selectTheme,
} from '@plone/volto/components/manage/Widgets/SelectStyling';
import { DropdownIndicator } from './DropdownIndicator';
import { Toolbar, Icon } from '@plone/volto/components';
import { Icon } from '@plone/volto/components';
import listBulletSVG from '@plone/volto/icons/list-bullet.svg';
import gridSVG from './icons/grid.svg';

Expand All @@ -24,6 +18,7 @@ const filterSupportedLayouts = (layouts) => {
: ['list']
).filter((layout) => ['list', 'grid'].includes(layout));
if (layouts && supportedLayouts.length !== layouts.length) {
// eslint-disable-next-line no-console
console.warn(
`Unsupported layouts are ignored from list: ${JSON.stringify(layouts)}`,
);
Expand All @@ -42,7 +37,7 @@ export const SelectLayout = ({ onChange, value, layouts }) => {
// If selected layout is not allowed: select the default
onChange(supportedLayouts[0]);
}
}, [supportedLayouts, value]);
}, [supportedLayouts, value.onChange]);

return supportedLayouts.length >= 2 ? (
<span className="layout-field">
Expand All @@ -52,12 +47,16 @@ export const SelectLayout = ({ onChange, value, layouts }) => {
<span
className={`layout-selector ${activeClass('list')}`}
onClick={() => onChange('list')}
onKeyDown={() => {}}
role="button"
>
<Icon name={listBulletSVG} size="18px" />
</span>
<span
className={`layout-selector ${activeClass('grid')}`}
onClick={() => onChange('grid')}
onKeyDown={() => {}}
role="button"
>
<Icon name={gridSVG} size="18px" color="red" />
</span>
Expand Down
7 changes: 6 additions & 1 deletion src/components/theme/SolrSearch/ShowMoreIndicator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const ShowMoreIndicator = ({ value, setValue }) => {
const intl = useIntl();
const onClick = useCallback((evt) => setValue((v) => !v), [setValue]);
return (
<span className="showMoreIndicator" onClick={onClick}>
<span
className="showMoreIndicator"
onClick={onClick}
onKeyDown={() => {}}
role="button"
>
{value ? (
<>
{intl.formatMessage(messages.showLess)}
Expand Down
20 changes: 2 additions & 18 deletions src/components/theme/SolrSearch/SolrSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
Pagination,
Button,
Dimmer,
DimmerDimmable,
Loader,
Checkbox,
} from 'semantic-ui-react';
Expand Down Expand Up @@ -115,21 +114,6 @@ const LocalCheckbox = ({ onChange, checked }) => {
);
};

// Replace search params **without** changing the route.
// Reason: as of today react-router will **remount** the component
// if the route changes, this means we cannot change the query without
// a full remount. This will cause a blink and then a rerender of the entire
// component tree. We want to avoid the remount, we don't want a state
// update because our state is the source of truth.
const updateLocation = (searchParams, { replace } = {}) => {
const url = new URL(location);
for (const key in searchParams) {
url.searchParams.set(key, searchParams[key]);
}
history.replaceState({}, '', url);
//(replace ? history.replaceState : history.pushState)({}, '', url);
};

const shallowDiffers = (a, b, { without = [] } = {}) => {
for (let i in a)
if (!without.includes(i) && !(i in b)) {
Expand Down Expand Up @@ -269,7 +253,7 @@ class SolrSearch extends Component {
...params,
sort_on: params.sort_on != 'relevance' ? params.sort_on : '',
b_start: (this.state.currentPage - 1) * config.settings.defaultPageSize,
path_prefix: getPathPrefix(location),
path_prefix: getPathPrefix(window.location),
});
};

Expand Down Expand Up @@ -553,7 +537,7 @@ export default compose(
dispatch(
searchActionWithDefault(searchAction)('', {
...qs.parse(location.search),
path_prefix: getPathPrefix(location),
path_prefix: getPathPrefix(window.location),
use_site_search_settings: 1,
metadata_fields: ['effective', 'UID', 'start'],
hl: 'true',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react';
import { Link } from 'react-router-dom';
import ResultItemDate, { thresholdDate } from './helpers/ResultItemDate';
import ConcatChildren from './helpers/ConcatChildren';
import ResultItemPreviewImage from './helpers/ResultItemPreviewImage';
import IconForContentType from './helpers/IconForContentType';
import locationSVG from '../icons/location.svg';
import phoneSVG from '../icons/phone.svg';
import emailSVG from '@plone/volto/icons/email.svg';
import fallbackAvatarSVG from '../icons/fallback-avatar.svg';
Expand Down

0 comments on commit 38147b2

Please sign in to comment.