Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/connectors/breadcrumb/connectBreadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import find from 'lodash/find';
import isEqual from 'lodash/isEqual';
import { checkRendering } from '../../lib/utils.js';
import { checkRendering, warn } from '../../lib/utils.js';

const usage = `Usage:
var customBreadcrumb = connectBreadcrumb(function renderFn(params, isFirstRendering) {
Expand Down Expand Up @@ -82,9 +82,8 @@ export default function connectBreadcrumb(renderFn, unmountFn) {
!isEqual(isFacetSet.attributes, attributes) ||
isFacetSet.separator !== separator
) {
// eslint-disable-next-line no-console
console.warn(
'Using Breadcrumb & HierarchicalMenu on the same facet with different options. Adding that one will override the configuration of the HierarchicalMenu. Check your options.'
warn(
'Using Breadcrumb and HierarchicalMenu on the same facet with different options overrides the configuration of the HierarchicalMenu.'
);
}
return {};
Expand Down
7 changes: 3 additions & 4 deletions src/connectors/hierarchical-menu/connectHierarchicalMenu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import find from 'lodash/find';
import isEqual from 'lodash/isEqual';

import { checkRendering } from '../../lib/utils.js';
import { checkRendering, warn } from '../../lib/utils.js';

const usage = `Usage:
var customHierarchicalMenu = connectHierarchicalMenu(function renderFn(params, isFirstRendering) {
Expand Down Expand Up @@ -131,9 +131,8 @@ export default function connectHierarchicalMenu(renderFn, unmountFn) {
isFacetSet.separator === separator
)
) {
// eslint-disable-next-line no-console
console.warn(
'using Breadcrumb & HierarchicalMenu on the same facet with different options'
warn(
'Using Breadcrumb and HierarchicalMenu on the same facet with different options overrides the configuration of the HierarchicalMenu.'
);
return {};
}
Expand Down
24 changes: 12 additions & 12 deletions src/connectors/hits-per-page/connectHitsPerPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import some from 'lodash/some';
import find from 'lodash/find';

import { checkRendering } from '../../lib/utils.js';
import { checkRendering, warn } from '../../lib/utils.js';

const usage = `Usage:
var customHitsPerPage = connectHitsPerPage(function render(params, isFirstRendering) {
Expand Down Expand Up @@ -145,20 +145,20 @@ The first one will be picked, you should probably set only one default value`

if (!isCurrentInOptions) {
if (state.hitsPerPage === undefined) {
if (window.console) {
window.console.warn(
`[Warning][hitsPerPage] hitsPerPage not defined.
You should probably set the value \`hitsPerPage\`
using the searchParameters attribute of the instantsearch constructor.`
);
}
} else if (window.console) {
window.console.warn(
`[Warning][hitsPerPage] No item in \`items\`
with \`value: hitsPerPage\` (hitsPerPage: ${state.hitsPerPage})`
warn(
`\`hitsPerPage\` is not defined.
The option \`hitsPerPage\` needs to be set using the \`configure\` widget.

Learn more: https://community.algolia.com/instantsearch.js/v2/widgets/configure.html`
);
}

warn(
`No items in HitsPerPage \`items\` with \`value: hitsPerPage\` (hitsPerPage: ${
state.hitsPerPage
})`
);

items = [{ value: '', label: '' }, ...items];
}

Expand Down
16 changes: 8 additions & 8 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,19 @@ function isReactElement(object) {
);
}

function logger(message) {
function log(message) {
// eslint-disable-next-line no-console
console.warn(`[InstantSearch.js]: ${message.trim()}`);
}

function deprecate(fn, message) {
let hasAlreadyPrint = false;
let hasAlreadyPrinted = false;

return function(...args) {
if (!hasAlreadyPrint) {
hasAlreadyPrint = true;
if (!hasAlreadyPrinted) {
hasAlreadyPrinted = true;

logger(message);
log(message);
}

return fn(...args);
Expand All @@ -428,12 +428,12 @@ function deprecate(fn, message) {

warn.cache = {};
function warn(message) {
const hasAlreadyPrint = warn.cache[message];
const hasAlreadyPrinted = warn.cache[message];

if (!hasAlreadyPrint) {
if (!hasAlreadyPrinted) {
warn.cache[message] = true;

logger(message);
log(message);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/widgets/hits-per-page/__tests__/hits-per-page-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,17 @@ describe('hitsPerPage()', () => {
items.push({ label: 'Label without a value' });
widget.init({ state: helper.state, helper });
expect(consoleWarn).toHaveBeenCalledTimes(1, 'console.warn called once');
expect(consoleWarn.mock.calls[0][0]).toEqual(
`[Warning][hitsPerPage] No item in \`items\`
with \`value: hitsPerPage\` (hitsPerPage: 20)`
expect(consoleWarn.mock.calls[0][0]).toMatchInlineSnapshot(
`"[InstantSearch.js]: No items in HitsPerPage \`items\` with \`value: hitsPerPage\` (hitsPerPage: 20)"`
);
});

it('must include the current hitsPerPage at initialization time', () => {
helper.state.hitsPerPage = -1;
widget.init({ state: helper.state, helper });
expect(consoleWarn).toHaveBeenCalledTimes(1, 'console.warn called once');
expect(consoleWarn.mock.calls[0][0]).toEqual(
`[Warning][hitsPerPage] No item in \`items\`
with \`value: hitsPerPage\` (hitsPerPage: -1)`
expect(consoleWarn.mock.calls[0][0]).toMatchInlineSnapshot(
`"[InstantSearch.js]: No items in HitsPerPage \`items\` with \`value: hitsPerPage\` (hitsPerPage: -1)"`
);
});

Expand Down
4 changes: 3 additions & 1 deletion src/widgets/pagination/__tests__/pagination-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ describe('pagination()', () => {
widget = pagination({ container });
widget.init({ helper });
widget.render({ results, helper, state: { page: 0 } });
const { props: { setCurrentPage } } = ReactDOM.render.mock.calls[0][0];
const {
props: { setCurrentPage },
} = ReactDOM.render.mock.calls[0][0];
setCurrentPage(2);
expect(scrollIntoView).toHaveBeenCalledTimes(1);
});
Expand Down