Skip to content

Commit

Permalink
added jsdoc for workspace, windows, viewer and utils selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Stoehr committed Sep 26, 2023
1 parent 04c5b67 commit a62f51c
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 9 deletions.
46 changes: 46 additions & 0 deletions src/state/selectors/searches.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { miradorSlice } from './utils';
/** Get searches from state */
const getSearches = (state) => miradorSlice(state).searches;

/**
* Returns the search result for a specific window.
* @param {object} state
* @param {string} windowId
* @returns {object}
*/
export const getSearchForWindow = createSelector(
[
(state, { windowId }) => windowId,
Expand All @@ -22,6 +28,12 @@ export const getSearchForWindow = createSelector(
},
);

/**
* Returns the search result for a specific companion window.
* @param {object} state
* @param {string} companionWindowId
* @returns {object|undefined}
*/
const getSearchForCompanionWindow = createSelector(
[
getSearchForWindow,
Expand All @@ -33,6 +45,11 @@ const getSearchForCompanionWindow = createSelector(
},
);

/**
* Returns an array of search responses for a specific companion window.
* @param {object} state
* @returns {Array}
*/
const getSearchResponsesForCompanionWindow = createSelector(
[
getSearchForCompanionWindow,
Expand All @@ -43,20 +60,37 @@ const getSearchResponsesForCompanionWindow = createSelector(
},
);

/**
* Returns the search query for a specific companion window.
* @param {object} state
* @param {string} windowId
* @returns {string|undefined}
*/
export const getSearchQuery = createSelector(
[
getSearchForCompanionWindow,
],
results => results && results.query,
);

/**
* Returns if search response for a companion window is fetching.
* @param {object} state
* @returns {boolean}
*/
export const getSearchIsFetching = createSelector(
[
getSearchResponsesForCompanionWindow,
],
results => results.some(result => result.isFetching),
);

/**
* Returns the total number of search results for a companion window.
* @param {object} state
* @param {string} windowId
* @returns {number|undefined}
*/
export const getSearchNumTotal = createSelector(
[
getSearchForCompanionWindow,
Expand All @@ -73,6 +107,12 @@ export const getSearchNumTotal = createSelector(
},
);

/**
* Returns the Id of the next search.
* @param {object} state
* @param {string} windowId
* @returns {number|undefined}
*/
export const getNextSearchId = createSelector(
[
getSearchForCompanionWindow,
Expand Down Expand Up @@ -104,6 +144,12 @@ const getSearchHitsForCompanionWindow = createSelector(
})),
);

/**
* Returns sorted search hits based on canvas order.
* @param {object} state
* @param {string} manifestId
* @returns {Array}
*/
export const getSortedSearchHitsForCompanionWindow = createSelector(
[
getSearchHitsForCompanionWindow,
Expand Down
17 changes: 15 additions & 2 deletions src/state/selectors/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
} from './manifests';
import { getWindow } from './getters';

/**
* @param {string} companionWindowId
*/
export const getSequences = createSelector(
[getManifestoInstance],
(manifest) => {
Expand All @@ -29,6 +32,9 @@ export const getSequences = createSelector(
},
);

/**
* @param {string} companionWindowId
*/
export const getSequence = createSelector(
[
getSequences,
Expand Down Expand Up @@ -83,7 +89,10 @@ export const getSequenceViewingHint = createSelector(
},
);

/** */
/**
* @param {object} state
* @param {string} windowId
*/
export const getSequenceViewingDirection = createSelector(
[getWindow, getSequence, getManifestoInstance],
(window, sequence, manifest) => {
Expand Down Expand Up @@ -122,7 +131,11 @@ export const getSequenceBehaviors = createSelector(
},
);

/** */
/**
* @param {object} state
* @param {string} companionWindowId
*
*/
export const getSequenceTreeStructure = createSelector(
[getSequence, getManifestoInstance],
(sequence, manifest) => {
Expand Down
7 changes: 6 additions & 1 deletion src/state/selectors/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import settings from '../../config/settings';

/** */
/**
* Returns a slice of the mirador redux state based on settings.
* Otherwise the entire Redux state is returned
* @param {object} state
* @returns {object}
*/
export function miradorSlice(state) {
if (settings.state.slice) return state[settings.state.slice];

Expand Down
6 changes: 5 additions & 1 deletion src/state/selectors/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { getVisibleCanvases } from './canvases';
import { getLayersForVisibleCanvases } from './layers';
import { getSequenceViewingDirection } from './sequences';

/** Instantiate a manifesto instance */
/** Instantiate a manifesto instance
* @param {object} state
* @param {string} windowId
* @returns {object}
*/
export const getCurrentCanvasWorld = createSelector(
getVisibleCanvases,
getLayersForVisibleCanvases,
Expand Down
20 changes: 17 additions & 3 deletions src/state/selectors/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { getWindows, getWindow, getWindowIds } from './getters';
import { getWorkspaceType } from './workspace';
import { getSequenceViewingHint, getSequenceBehaviors } from './sequences';

/** */
/**
* Returns the window configuration
* @param {object} state
* @param {string} windowId
* @returns {object}
*/
export const getWindowConfig = createSelector(
[getConfig, getWindow],
({ window: defaultConfig }, windowConfig = {}) => ({ ...defaultConfig, ...windowConfig }),
Expand All @@ -28,7 +33,11 @@ export function getWindowTitles(state) {
return result;
}

/** */
/**
* Returns an array containing the maximized windowIds
* @param {object} state
* @returns {Array}
*/
export const getMaximizedWindowsIds = createSelector(
[getWindows],
windows => Object.values(windows)
Expand Down Expand Up @@ -62,7 +71,12 @@ export const getWindowViewType = createSelector(
},
);

/** */
/**
* Returns the window view type for a given window
* @param {object} state
* @param {string} windowId
* @returns {string} 'single' | 'book' | 'scroll' | 'gallery'
*/
export const getAllowedWindowViewTypes = createSelector(
[
getSequenceViewingHint,
Expand Down
25 changes: 23 additions & 2 deletions src/state/selectors/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import { createSelector } from 'reselect';
import { getWorkspace } from './getters';
import { miradorSlice } from './utils';

/** */
/** Returns the elastic layout from the state
* @param {object} state
* @returns {object}
*/
export function getElasticLayout(state) {
return miradorSlice(state).elasticLayout;
}

/** Returns if fullscreen is enabled
* @param {object} state
* @returns {boolean}
*/
export const getFullScreenEnabled = createSelector(
[getWorkspace],
workspace => workspace.isFullscreenEnabled,
Expand All @@ -21,17 +28,31 @@ export function getLatestError(state) {
return miradorSlice(state).errors[errorId];
}

/**
* Selector that returns the type of the workspace
* @param {object} state
* @returns {string} 'mosaic' | 'elastic'
*/
export const getWorkspaceType = createSelector(
[getWorkspace],
({ type }) => type,
);

/**
* Selector that returns the ID of the focused window.
* @param {object} state
* @returns {string|undefined}
*/
export const getFocusedWindowId = createSelector(
[getWorkspace],
({ focusedWindowId }) => focusedWindowId,
);

/** Check if the current window is focused */
/** Check if the current window is focused
* @param {object} state
* @param {string} windowId
* @returns {boolean}
*/
export const isFocused = (state, { windowId }) => (
getFocusedWindowId(state) === windowId
);

0 comments on commit a62f51c

Please sign in to comment.