Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat(indexId): rely on indexId rather than indexName in SSR [PART-4] #1842

Merged
merged 6 commits into from
Jan 4, 2019
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { omit, difference, keys } from 'lodash';
import createConnector from '../core/createConnector';
import { hasMultipleIndex, getIndex, refineValue } from '../core/indexUtils';
import {
refineValue,
getIndexId,
hasMultipleIndices,
} from '../core/indexUtils';

function getId() {
return 'configure';
Expand Down Expand Up @@ -29,10 +33,10 @@ export default createConnector({
},
cleanUp(props, searchState) {
const id = getId();
const index = getIndex(this.context);
const indexId = getIndexId(this.context);
const subState =
hasMultipleIndex(this.context) && searchState.indices
? searchState.indices[index]
hasMultipleIndices(this.context) && searchState.indices
? searchState.indices[indexId]
: searchState;
const configureKeys =
subState && subState[id] ? Object.keys(subState[id]) : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import createConnector from '../core/createConnector';
import {
getResults,
getCurrentRefinementValue,
getIndex,
getIndexId,
refineValue,
cleanUpValue,
} from '../core/indexUtils';
Expand Down Expand Up @@ -205,7 +205,7 @@ export default createConnector({
getMetadata(props, searchState) {
const items = [];
const id = getBoundingBoxId();
const index = getIndex(this.context);
const index = getIndexId(this.context);
const nextRefinement = {};
const currentRefinement = getCurrentRefinement(
props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SearchParameters } from 'algoliasearch-helper';
import createConnector from '../core/createConnector';
import {
cleanUpValue,
getIndex,
getIndexId,
refineValue,
getCurrentRefinementValue,
getResults,
Expand Down Expand Up @@ -270,7 +270,7 @@ export default createConnector({

return {
id,
index: getIndex(this.context),
index: getIndexId(this.context),
items: !currentRefinement
? []
: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { orderBy } from 'lodash';
import PropTypes from 'prop-types';
import createConnector from '../core/createConnector';
import {
getIndex,
getIndexId,
cleanUpValue,
refineValue,
getCurrentRefinementValue,
Expand Down Expand Up @@ -222,7 +222,7 @@ export default createConnector({
);
return {
id,
index: getIndex(this.context),
index: getIndexId(this.context),
items:
currentRefinement === null
? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
refineValue,
getCurrentRefinementValue,
getResults,
getIndex,
getIndexId,
} from '../core/indexUtils';

function stringifyItem(item) {
Expand Down Expand Up @@ -209,7 +209,7 @@ export default createConnector({
const id = getId(props);
const value = getCurrentRefinement(props, searchState, this.context);
const items = [];
const index = getIndex(this.context);
const index = getIndexId(this.context);
if (value !== '') {
const { label } = find(
props.items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import createConnector from '../core/createConnector';
import {
cleanUpValue,
getIndex,
getIndexId,
refineValue,
getCurrentRefinementValue,
getResults,
Expand Down Expand Up @@ -332,7 +332,7 @@ export default createConnector({

return {
id: getId(props),
index: getIndex(this.context),
index: getIndexId(this.context),
items,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import createConnector from '../core/createConnector';
import {
cleanUpValue,
getIndex,
getIndexId,
refineValue,
getCurrentRefinementValue,
getResults,
Expand Down Expand Up @@ -226,7 +226,7 @@ export default createConnector({
const context = this.context;
return {
id,
index: getIndex(this.context),
index: getIndexId(this.context),
items:
getCurrentRefinement(props, searchState, context).length > 0
? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import createConnector from '../core/createConnector';
import {
getCurrentRefinementValue,
hasMultipleIndex,
getIndex,
hasMultipleIndices,
getIndexId,
} from '../core/indexUtils';
import { shallowEqual } from '../core/utils';

Expand Down Expand Up @@ -44,9 +44,10 @@ export default createConnector({
}

/* Get the subpart of the state that interest us*/
if (hasMultipleIndex(this.context)) {
const index = getIndex(this.context);
searchState = searchState.indices ? searchState.indices[index] : {};
if (hasMultipleIndices(this.context)) {
searchState = searchState.indices
? searchState.indices[getIndexId(this.context)]
: {};
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
cleanUpValue,
refineValue,
getCurrentRefinementValue,
getIndex,
getIndexId,
} from '../core/indexUtils';

function getId() {
Expand Down Expand Up @@ -86,7 +86,7 @@ export default createConnector({
);
return {
id,
index: getIndex(this.context),
index: getIndexId(this.context),
items:
currentRefinement === null
? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import createConnector from '../core/createConnector';
import {
cleanUpValue,
getIndex,
getIndexId,
getResults,
refineValue,
getCurrentRefinementValue,
Expand Down Expand Up @@ -149,7 +149,7 @@ export default createConnector({
const id = getId(props);
const checked = getCurrentRefinement(props, searchState, this.context);
const items = [];
const index = getIndex(this.context);
const index = getIndexId(this.context);

if (checked) {
items.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import algoliasearchHelper from 'algoliasearch-helper';
import createWidgetsManager from './createWidgetsManager';
import createStore from './createStore';
import { HIGHLIGHT_TAGS } from './highlight';
import { hasMultipleIndex } from './indexUtils';
import { hasMultipleIndices } from './indexUtils';

const isMultiIndexContext = widget => hasMultipleIndex(widget.context);
const isMultiIndexContext = widget => hasMultipleIndices(widget.context);
const isTargetedIndexEqualIndex = (widget, indexId) =>
widget.context.multiIndexContext.targetedIndex === indexId;

Expand Down
Loading