Skip to content

Commit

Permalink
Update eslint to 8.31.0, handle lint (#1941)
Browse files Browse the repository at this point in the history
* update eslint, handle lint

* remove effect in useAdvancedSearch hook

* remove only

* don't use require.context in the jsdom browser

* resolve sticky columns story conflict
  • Loading branch information
JohnC-80 authored Jan 18, 2023
1 parent 98b90bb commit 945f665
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 77 deletions.
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
"max-classes-per-file": "off",
"max-len": "off",
"no-unused-expressions": "off",
"react/prop-types": "off"
"react/prop-types": "off",
"semi": "off"
}
},
{
"files": ["lib/**/**"],
"rules": {
"semi": "off"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion hooks/tests/useClickOutside-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { mountWithContext } from '../../tests/helpers';
import useClickOutside from '../useClickOutside';

const UseClickOutsideInteractor = interactor(class UseClickOutsideInteractor {
static defaultScope ='#test-component';
static defaultScope = '#test-component';
clickOutsideElement = clickable('#click-outside-element');
clickInsideElement = clickable('#click-inside-element');
});
Expand Down
14 changes: 7 additions & 7 deletions lib/Accordion/ExpandAllButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const propTypes = {
setStatus: PropTypes.func,
};

function handleClick({ accordionStatus, func, setStatus, onToggle }) {
const newState = expandAll(accordionStatus, func);
if (setStatus) setStatus(newState);
if (onToggle) onToggle(newState);
}

const ExpandAllButton = ({
accordionStatus,
collapseLabel: collapseLabelProp,
Expand All @@ -40,17 +46,11 @@ const ExpandAllButton = ({

const func = majorityCollapsed(accordionStatus);

function handleClick() {
const newState = expandAll(accordionStatus, func);
if (setStatus) setStatus(newState);
if (onToggle) onToggle(newState);
}

return (
<Button
buttonStyle="link bottomMargin0"
id={id}
onClick={handleClick}
onClick={() => { handleClick({ accordionStatus, func, setStatus, onToggle }); }}
data-tast-expand-button
>
<strong>{func ? expandLabel : collapseLabel}</strong>
Expand Down
18 changes: 9 additions & 9 deletions lib/AdvancedSearch/hooks/useAdvancedSearch/useAdvancedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
useCallback,
useState,
useMemo,
useEffect,
} from 'react';
import { isEqual } from 'lodash';
import { useIntl } from 'react-intl';

import splitQueryRows from '../../utilities/splitQueryRows';
Expand Down Expand Up @@ -37,12 +37,14 @@ const useAdvancedSearch = ({
searchOptions,
}) => {
const initialRowState = useMemo(() => {
return createInitialRowState(firstRowInitialSearch, defaultSearchOptionValue);
const initialRows = createInitialRowState(firstRowInitialSearch, defaultSearchOptionValue);
return splitQueryRows(initialRows);
}, [firstRowInitialSearch, defaultSearchOptionValue]);

const intl = useIntl();
const [rowState, setRowState] = useState(initialRowState);
const [showEmptyFirstRowMessage, setShowEmptyFirstRowMessage] = useState(false);
const [prevFirstRowInitialSearch, setPrevFirstRowInitialSearch] = useState(firstRowInitialSearch);

const searchOptionsWithQuery = useMemo(() => (
[{
Expand Down Expand Up @@ -83,15 +85,13 @@ const useAdvancedSearch = ({

const handleCancel = useCallback(onCancel, [onCancel]);

const handleInitialSearchChange = () => {
// if the firstRowInitialSearch is updated, go ahead and update state
// before the state is committed to the DOM...
if (!isEqual(firstRowInitialSearch, prevFirstRowInitialSearch)) {
const splitRows = splitQueryRows(initialRowState);

setPrevFirstRowInitialSearch(firstRowInitialSearch);
setRowState(splitRows);
};

useEffect(() => {
handleInitialSearchChange();
}, [firstRowInitialSearch]);
}

return {
handleCancel,
Expand Down
59 changes: 58 additions & 1 deletion lib/AdvancedSearch/tests/AdvancedSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* AdvancedSearch test
*/

import React from 'react';
import React, { useState } from 'react';

import { expect } from 'chai';
import {
Expand All @@ -22,6 +22,31 @@ import {
import { mountWithContext } from '../../../tests/helpers';

import AdvancedSearch from '../AdvancedSearch';
import Button from '../../Button';

const Harness = (props) => {
const [initState, setInitState] = useState({ query: 'try', option: 'keyword' });
return (
<>
<Button onClick={() => { setInitState({ query: 'test', option: 'keyword' }) }}>Reset</Button>
<AdvancedSearch
firstRowInitialSearch={initState}
{...props}
>
{({ resetRows }) => (
<>
<button
type="button"
onClick={resetRows}
>
Change
</button>
</>
)}
</AdvancedSearch>
</>
)
}

describe('AdvancedSearch', () => {
const advancedSearch = new Interactor();
Expand Down Expand Up @@ -235,4 +260,36 @@ describe('AdvancedSearch', () => {
expect(onCancelSpy.calledOnce).to.be.true;
});
});

describe('updating initialRowSearch', () => {
beforeEach(async () => {
await mountWithContext(
<Harness
open
onSearch={onSearchSpy}
onCancel={onCancelSpy}
defaultSearchOptionValue={defaultSearchOptionValue}
searchOptions={searchOptions}
/>
);
});

it('renders applicable values', async () => {
await advancedSearch.find(RowInteractor({ index: 0 })).perform(el => {
expect(el.querySelector('[data-test-advanced-search-query]').value).to.equal('try');
});
});

describe('resetting from the outside', () => {
beforeEach(async () => {
await ButtonInteractor('Reset').click();
});

it('renders updated query values', async () => {
await advancedSearch.find(RowInteractor({ index: 0 })).perform(el => {
expect(el.querySelector('[data-test-advanced-search-query]').value).to.equal('test');
});
});
})
})
});
76 changes: 38 additions & 38 deletions lib/FocusLink/FocusLink.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useCallback, useRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import css from './FocusLink.css';
Expand All @@ -18,58 +18,58 @@ const propTypes = {
targetNextAfter: PropTypes.element,
};

const FocusLink = (props) => {
// eslint-disable-next-line react/forbid-foreign-prop-types
const [{ target, component, tabIndex, targetNextAfter }, rest] = separateComponentProps(props, FocusLink.propTypes);

let link = null;

function focusTarget() {
if (typeof target === 'string') {
let id = target;
function focusTarget(target) {
if (typeof target === 'string') {
let id = target;

if (target.charAt(0) === '#') {
id = target.replace('#', '');
}
if (target.charAt(0) === '#') {
id = target.replace('#', '');
}

const tgt = document.getElementById(id);
if (tgt) {
tgt.focus();
}
} else if (typeof target === 'object') {
props.target.focus();
const tgt = document.getElementById(id);
if (tgt) {
tgt.focus();
}
} else if (typeof target === 'object') {
target.focus();
}
}

function focusNext() {
let nextFocusable;
if (props.targetNextAfter) {
nextFocusable = getNextFocusable(targetNextAfter, false);
} else {
nextFocusable = getNextFocusable(link, false);
}
nextFocusable.focus();
function focusNext(targetNextAfter = false, link) {
let nextFocusable;
if (targetNextAfter) {
nextFocusable = getNextFocusable(targetNextAfter, false);
} else {
nextFocusable = getNextFocusable(link.current, false);
}
nextFocusable.focus();
}

const FocusLink = (props) => {
// eslint-disable-next-line react/forbid-foreign-prop-types
const [{ target, component, tabIndex, targetNextAfter }, rest] = separateComponentProps(props, FocusLink.propTypes);

let link = useRef(null);

function handleClick(e) {
const handleClick = useCallback((e) => {
e.preventDefault();
if (props.target) {
focusTarget();
focusTarget(target);
} else {
focusNext();
focusNext(targetNextAfter, link);
}
}
}, [props.target, targetNextAfter, link, target])

function handleKeyPress(e) {
const handleKeyDown = useCallback((e) => {
e.preventDefault();
if (e.key === 'Enter') {
if (props.target) {
focusTarget();
focusTarget(target);
} else {
focusNext();
focusNext(targetNextAfter, link);
}
}
}
}, [props.target, targetNextAfter, link, target])

function getClass() {
return classNames(
Expand All @@ -84,11 +84,11 @@ const FocusLink = (props) => {
return (
<Component
data-test-focus-link
ref={(ref) => { link = ref; }}
ref={link}
role="button"
tabIndex={tabIndex || 0}
onClick={handleClick}
onKeyPress={handleKeyPress}
onKeyDown={handleKeyDown}
className={getClass()}
{...rest}
>
Expand All @@ -103,7 +103,7 @@ const FocusLink = (props) => {
role="button"
tabIndex={tabIndex || 0}
onClick={handleClick}
onKeyPress={handleKeyPress}
onKeyDown={handleKeyDown}
className={getClass()}
{...rest}
>
Expand Down
14 changes: 10 additions & 4 deletions lib/Icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ import omitProps from '../../util/omitProps';
/**
* Import SVG icons
*/
const req = require.context('!!react-svg-loader!./icons/', true, /\.svg$/);
const icons = req.keys().reduce((images, path) => Object.assign(images, {
[path.slice(2, path.length - 4)]: req(path).default,
}), {});
let icons = { default: import('./icons/default.svg') };
// check to see if we're in the node test browser - this environment doesn't
// use webpack to build, so it will failwhen require.context is executed for whatever reason.
if (!navigator.userAgent.includes('jsdom')) {
const req = require.context('!!react-svg-loader!./icons/', true, /\.svg$/);
icons = req.keys().reduce((images, path) => Object.assign(images, {
[path.slice(2, path.length - 4)]: req(path).default,
}), {});
}


const SpinnerEllipsis = ({ className, ...rest }) => (
<div className={`${dotSpinner.spinner} ${className}`} {...omitProps(rest, ['viewBox'])}>
Expand Down
8 changes: 4 additions & 4 deletions lib/List/tests/interactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export default interactor(class ListInteractor {
return count(selector);
}

hasUL= isPresent('ul');
hasUL = isPresent('ul');
hasEmptyMessage = isPresent('[class*=isEmptyMessage---]');
emptyMessageText = text('[class*=isEmptyMessage---]');
hasMarginBottom0Class= hasClass('ul', `${css.marginBottom0}`);
hasBulletedClass= hasClass('ul', `${css.listStyleBullets}`);
hasDefaultClass= hasClass('ul', `${css.listStyleDefault}`);
hasMarginBottom0Class = hasClass('ul', `${css.marginBottom0}`);
hasBulletedClass = hasClass('ul', `${css.listStyleBullets}`);
hasDefaultClass = hasClass('ul', `${css.listStyleDefault}`);
itemCount = this.countItems();
});
2 changes: 1 addition & 1 deletion lib/MultiColumnList/stories/CheckboxSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class CheckboxSelect extends React.Component {
}
}

isSelected =({ item }) => (
isSelected = ({ item }) => (
this.state.allSelected ||
(this.state.selected.findIndex(s => s.index === item.index) !== -1)
);
Expand Down
2 changes: 0 additions & 2 deletions lib/MultiColumnList/tests/interactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export default interactor(class MultiColumnListInteractor {

listScrollTop = property('[class*=mclScrollable---]', 'scrollTop');

listScrollTop = property('[class*=mclScrollable---]', 'scrollTop');

columnsMeasured() {
return this.when(() => (this.cell.style && this.cell.style.width !== ''));
}
Expand Down
7 changes: 6 additions & 1 deletion lib/MultiSelection/MultiSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class MultiSelection extends React.Component {
asyncFiltering: PropTypes.bool,
autoFocus: PropTypes.bool,
backspaceDeletes: PropTypes.bool,
dataOptions: PropTypes.arrayOf(PropTypes.any),
dataOptions: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.string,
PropTypes.object
])
),
dirty: PropTypes.bool,
disabled: PropTypes.bool,
emptyMessage: PropTypes.string,
Expand Down
15 changes: 15 additions & 0 deletions lib/Paneset/PaneResizeContainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useRef, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import cloneDeep from 'lodash/cloneDeep';
import isEqual from 'lodash/isEqual';
import insertByClientRect from './insertByClientRect';
Expand Down Expand Up @@ -248,4 +249,18 @@ const PaneResizeContainer = ({ isRoot, children, onElementResize, parentElement,
return children;
};

PaneResizeContainer.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
isRoot: PropTypes.bool,
onElementResize: PropTypes.func,
parentElement: PropTypes.element,
resizeContainerRef: PropTypes.oneOfType([
PropTypes.object,
PropTypes.func
])
}

export default PaneResizeContainer;
Loading

0 comments on commit 945f665

Please sign in to comment.