import { createSelector } from 'reselect' ; import { IApplicationState } from '../index' ; import { IAssetItem , IAssetSearchParams , ISetItem , ASSET_LIST_STYLE , ASSET_CONTENT_PANEL_STATE , } from '../../interfaces' ; import { getSetsById } from '../sets/selectors' ; export function getAssets ( state ) { return state . assets . assets ; } export function getAssetSearchParams ( state ) { return state . assets . searchParams ; } export const getSelectedSetId = createSelector < IApplicationState , IAssetSearchParams , ISetItem [ '_id' ] | undefined > ( [ getAssetSearchParams ] , ( searchParams ) => searchParams ?. setId ) ; export function getAssetListItemIds ( state ) { return state . assets . listItemIds ; } export function getAssetListStyle ( state ) { return state . assets . listStyle ; } export function getAssetListTotal ( state ) { return state . assets . searchResultTotal ; } export function getSelectedAssetId ( state ) { return state . assets . selectedAssetId ; } export function getSelectedAssetIds ( state ) { return state . assets . selectedAssetIds ; } export function getSetContentPanelState ( state ) { return state . assets . contentPanelState ?? ASSET_CONTENT_PANEL_STATE . CLOSED ; } export const getAssetSetFilter = createSelector < IApplicationState , Dictionary < string , ISetItem > , IAssetSearchParams , ISetItem | undefined > ( [ getSetsById , getAssetSearchParams ] , ( sets , searchParams ) => ( searchParams . setId != null ? sets [ searchParams . setId ] : undefined ) ) ; export const getAssetSearchResults = createSelector < IApplicationState , Array < string > , Dictionary < string , IAssetItem > , Array < IAssetItem > > ( [ getAssetListItemIds , getAssets ] , ( assetIds , assets ) => ( assetIds . map ( ( assetId ) => assets [ assetId ] ) ) ) ; export const getSelectedAsset = createSelector < IApplicationState , Dictionary < string , IAssetItem > , string | undefined , IAssetItem | undefined > ( [ getAssets , getSelectedAssetId ] , ( assets , assetId ? ) => ( assetId != null ? assets ?. [ assetId ] : undefined ) ) ; export const getSetNameForSelectedAsset = createSelector < IApplicationState , Dictionary < string , ISetItem > , IAssetItem | undefined , string | undefined > ( [ getSetsById , getSelectedAsset ] , ( sets , asset ? ) => ( asset != null ? sets ?. [ asset . set_id ] . name : undefined ) ) ; export const getSelectedAssetItems = createSelector < IApplicationState , Array < string > , Dictionary < string , IAssetItem > , Array < IAssetItem > > ( [ getSelectedAssetIds , getAssets ] , ( assetIds , assets ) => ( assetIds . map ( ( assetId ) => assets [ assetId ] ) ) ) ;