Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address some re-select inputStabilityCheck warnings. #3990

Merged
merged 1 commit into from
Nov 18, 2024
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
4 changes: 3 additions & 1 deletion src/state/selectors/companionWindows.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import groupBy from 'lodash/groupBy';
import { miradorSlice } from './utils';
import { getWindow, getWindows } from './getters';

const defaultConfig = Object.freeze({});

/**
* Returns companion windows.
* @param {object} state
* @returns {object}
*/
export function getCompanionWindows(state) {
return miradorSlice(state).companionWindows || {};
return miradorSlice(state).companionWindows || defaultConfig;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/state/selectors/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import deepmerge from 'deepmerge';
import { miradorSlice } from './utils';
import { getWorkspace } from './getters';

const defaultConfig = Object.freeze({});

/**
* Returns the config from the redux state.
* @param {object} state
* @returns {object} containing config
*/
export function getConfig(state) {
const slice = miradorSlice(state || {});
return slice.config || {};
return slice.config || defaultConfig;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/state/selectors/manifests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const getLocale = createSelector(
),
);

const defaultManifestStatus = Object.freeze({ missing: true });

/**
* Convenience selector to get a manifest (or placeholder).
* @param {object} state
Expand All @@ -38,7 +40,7 @@ const getLocale = createSelector(
*/
export const getManifestStatus = createSelector(
[getManifest],
manifest => manifest || { missing: true },
manifest => manifest || defaultManifestStatus,
);

/**
Expand Down
28 changes: 15 additions & 13 deletions src/state/selectors/searches.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ const getSearchHitsForCompanionWindow = createSelector(
})),
);

export const getSearchAnnotationsForCompanionWindow = createSelector(
[
getSearchResponsesForCompanionWindow,
],
results => results && searchResultsToAnnotation(results),
);

/**
* Returns sorted search hits based on canvas order.
* @param {object} state
Expand All @@ -156,18 +163,20 @@ export const getSortedSearchHitsForCompanionWindow = createSelector(
[
getSearchHitsForCompanionWindow,
getCanvases,
(state, { companionWindowId, windowId }) => (
annotationUri => getResourceAnnotationForSearchHit(state, { annotationUri, companionWindowId, windowId })
),
getSearchAnnotationsForCompanionWindow,
],
(searchHits, canvases, annotationForSearchHit) => {
(searchHits, canvases, annotation) => {
if (!canvases || canvases.length === 0) return [];
if (!searchHits || searchHits.length === 0) return [];
const canvasIds = canvases.map(canvas => canvas.id);

return [].concat(searchHits).sort((a, b) => {
const hitA = annotationForSearchHit(a.annotations[0]);
const hitB = annotationForSearchHit(b.annotations[0]);
const hitA = annotation.resources.find(
r => r.id === a.annotations[0],
);
const hitB = annotation.resources.find(
r => r.id === b.annotations[0],
);
return canvasIds.indexOf(hitA.targetId) - canvasIds.indexOf(hitB.targetId);
});
},
Expand All @@ -190,13 +199,6 @@ const searchResultsToAnnotation = (results) => {
};
};

export const getSearchAnnotationsForCompanionWindow = createSelector(
[
getSearchResponsesForCompanionWindow,
],
results => results && searchResultsToAnnotation(results),
);

/**
* Sorts search annotations based on canvas order.
* @returns {Array}
Expand Down