diff --git a/packages/core/src/components/Collection/Collection.tsx b/packages/core/src/components/Collection/Collection.tsx index 2486dec0..91032fb0 100644 --- a/packages/core/src/components/Collection/Collection.tsx +++ b/packages/core/src/components/Collection/Collection.tsx @@ -83,6 +83,10 @@ const CollectionView = ({ }, [collection]); const newEntryUrl = useMemo(() => { + if (!collectionName || !collection) { + return undefined; + } + let url = 'fields' in collection && collection.create ? getNewEntryUrl(collectionName) : ''; if (url && filterTerm) { url = getNewEntryUrl(collectionName); @@ -90,6 +94,7 @@ const CollectionView = ({ url = `${newEntryUrl}?path=${filterTerm}`; } } + return url; }, [collection, collectionName, filterTerm]); @@ -120,6 +125,10 @@ const CollectionView = ({ ); } + if (!collection) { + return null; + } + return ( { - await sortByField(collection, key, direction); + collection && (await sortByField(collection, key, direction)); }, [collection, sortByField], ); const onFilterClick = useCallback( async (filter: ViewFilter) => { - await filterByField(collection, filter); + collection && (await filterByField(collection, filter)); }, [collection, filterByField], ); const onGroupClick = useCallback( async (group: ViewGroup) => { - await groupByField(collection, group); + collection && (await groupByField(collection, group)); }, [collection, groupByField], ); @@ -176,7 +185,7 @@ const CollectionView = ({ return; } - const defaultSort = collection.sortable_fields?.default; + const defaultSort = collection?.sortable_fields?.default; if (!defaultSort || !defaultSort.field) { if (!readyToLoad) { setReadyToLoad(true); @@ -220,7 +229,7 @@ const CollectionView = ({ <> - {t(searchResultKey, { searchTerm, collection: collection.label })} + {t(searchResultKey, { searchTerm, collection: collection?.label })} @@ -254,7 +263,7 @@ const CollectionView = ({ interface CollectionViewOwnProps { isSearchResults?: boolean; isSingleSearchResult?: boolean; - name: string; + name?: string; searchTerm?: string; filterTerm?: string; } @@ -270,13 +279,13 @@ function mapStateToProps(state: RootState, ownProps: TranslatedProps getDefaultPath(collections), [collections]); - if (!name || !collection) { + if (!searchTerm && (!name || !collection)) { return ; } - if ('files' in collection && collection.files?.length === 1) { + if (collection && 'files' in collection && collection.files?.length === 1) { return ; } diff --git a/packages/core/src/components/Collection/Entries/EntriesSearch.tsx b/packages/core/src/components/Collection/Entries/EntriesSearch.tsx index 4bad8b53..dad645ef 100644 --- a/packages/core/src/components/Collection/Entries/EntriesSearch.tsx +++ b/packages/core/src/components/Collection/Entries/EntriesSearch.tsx @@ -25,6 +25,7 @@ const EntriesSearch = ({ searchEntries, clearSearch, }: EntriesSearchProps) => { + console.log('collections', collections); const collectionNames = useMemo(() => Object.keys(collections), [collections]); const getCursor = useCallback(() => { @@ -80,6 +81,7 @@ function mapStateToProps(state: RootState, ownProps: EntriesSearchOwnProps) { const isFetching = state.search.isFetching; const page = state.search.page; const entries = selectSearchedEntries(state, collectionNames); + console.log('searched entries', entries); return { isFetching, page, collections, viewStyle, entries, searchTerm }; } diff --git a/packages/core/src/lib/util/collection.util.ts b/packages/core/src/lib/util/collection.util.ts index 36004ab4..97af6dfd 100644 --- a/packages/core/src/lib/util/collection.util.ts +++ b/packages/core/src/lib/util/collection.util.ts @@ -156,9 +156,13 @@ export function selectDefaultSortableFields(collection: Collection, backend: Bac } export function selectSortableFields( - collection: Collection, + collection: Collection | undefined, t: (key: string) => string, ): SortableField[] { + if (!collection) { + return []; + } + const fields = (collection.sortable_fields?.fields ?? []) .map(key => { if (key === COMMIT_DATE) { @@ -177,12 +181,12 @@ export function selectSortableFields( return fields; } -export function selectViewFilters(collection: Collection) { - return collection.view_filters; +export function selectViewFilters(collection?: Collection) { + return collection?.view_filters; } -export function selectViewGroups(collection: Collection) { - return collection.view_groups; +export function selectViewGroups(collection?: Collection) { + return collection?.view_groups; } export function selectFieldsComments(collection: Collection, entryMap: Entry) { diff --git a/packages/core/src/reducers/selectors/entries.ts b/packages/core/src/reducers/selectors/entries.ts index e48723d6..9ab229be 100644 --- a/packages/core/src/reducers/selectors/entries.ts +++ b/packages/core/src/reducers/selectors/entries.ts @@ -17,17 +17,29 @@ import type { } from '@staticcms/core/interface'; import type { RootState } from '@staticcms/core/store'; -export function selectEntriesSort(entries: RootState, collection: string) { +export function selectEntriesSort(entries: RootState, collection?: string) { + if (!collection) { + return undefined; + } + const sort = entries.entries.sort as Sort | undefined; return sort?.[collection]; } -export function selectEntriesFilter(entries: RootState, collection: string) { +export function selectEntriesFilter(entries: RootState, collection?: string) { + if (!collection) { + return {}; + } + const filter = entries.entries.filter as Filter | undefined; return filter?.[collection] || {}; } -export function selectEntriesGroup(entries: RootState, collection: string) { +export function selectEntriesGroup(entries: RootState, collection?: string) { + if (!collection) { + return {}; + } + const group = entries.entries.group as Group | undefined; return group?.[collection] || {}; } diff --git a/yarn.lock b/yarn.lock index f49462a7..2e254e6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1730,21 +1730,6 @@ dependencies: eslint-visitor-keys "^3.3.0" -"@eslint/eslintrc@^1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.1.tgz#af58772019a2d271b7e2d4c23ff4ddcba3ccfb3e" - integrity sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA== - dependencies: - ajv "^6.12.4" - debug "^4.3.2" - espree "^9.4.0" - globals "^13.19.0" - ignore "^5.2.0" - import-fresh "^3.2.1" - js-yaml "^4.1.0" - minimatch "^3.1.2" - strip-json-comments "^3.1.1" - "@eslint/eslintrc@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.0.0.tgz#943309d8697c52fc82c076e90c1c74fbbe69dbff" @@ -6142,9 +6127,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001426, caniuse-lite@^1.0.30001449: - version "1.0.30001457" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001457.tgz#6af34bb5d720074e2099432aa522c21555a18301" - integrity sha512-SDIV6bgE1aVbK6XyxdURbUE89zY7+k1BBBaOwYwkNCglXlel/E7mELiHC64HQ+W0xSKlqWhV9Wh7iHxUjMs4fA== + version "1.0.30001458" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001458.tgz#871e35866b4654a7d25eccca86864f411825540c" + integrity sha512-lQ1VlUUq5q9ro9X+5gOEyH7i3vm+AYVT1WDCVB69XOZ17KZRhnZ9J0Sqz7wTHQaLBJccNCHq8/Ww5LlOIZbB0w== case-sensitive-paths-webpack-plugin@^2.4.0: version "2.4.0" @@ -7676,9 +7661,9 @@ ejs@^3.1.6, ejs@^3.1.7: jake "^10.8.5" electron-to-chromium@^1.4.284: - version "1.4.310" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.310.tgz#cb85dc8ceac536e99b20a364d7ab00ea35168f9e" - integrity sha512-/xlATgfwkm5uDDwLw5nt/MNEf7c1oazLURMZLy39vOioGYyYzLWIDT8fZMJak6qTiAJ7udFTy7JG7ziyjNutiA== + version "1.4.311" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.311.tgz#953bc9a4767f5ce8ec125f9a1ad8e00e8f67e479" + integrity sha512-RoDlZufvrtr2Nx3Yx5MB8jX3aHIxm8nRWPJm3yVvyHmyKaRvn90RjzB6hNnt0AkhS3IInJdyRfQb4mWhPvUjVw== emittery@^0.10.2: version "0.10.2" @@ -8207,7 +8192,7 @@ eslint-webpack-plugin@^3.1.1: normalize-path "^3.0.0" schema-utils "^4.0.0" -eslint@8.35.0: +eslint@8.35.0, eslint@^8.3.0: version "8.35.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.35.0.tgz#fffad7c7e326bae606f0e8f436a6158566d42323" integrity sha512-BxAf1fVL7w+JLRQhWl2pzGeSiGqbWumV4WNvc9Rhp6tiCtm4oHnyPBSEtMGZwrQgudFQ+otqzWoPB7x+hxoWsw== @@ -8253,51 +8238,6 @@ eslint@8.35.0: strip-json-comments "^3.1.0" text-table "^0.2.0" -eslint@^8.3.0: - version "8.34.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.34.0.tgz#fe0ab0ef478104c1f9ebc5537e303d25a8fb22d6" - integrity sha512-1Z8iFsucw+7kSqXNZVslXS8Ioa4u2KM7GPwuKtkTFAqZ/cHMcEaR+1+Br0wLlot49cNxIiZk5wp8EAbPcYZxTg== - dependencies: - "@eslint/eslintrc" "^1.4.1" - "@humanwhocodes/config-array" "^0.11.8" - "@humanwhocodes/module-importer" "^1.0.1" - "@nodelib/fs.walk" "^1.2.8" - ajv "^6.10.0" - chalk "^4.0.0" - cross-spawn "^7.0.2" - debug "^4.3.2" - doctrine "^3.0.0" - escape-string-regexp "^4.0.0" - eslint-scope "^7.1.1" - eslint-utils "^3.0.0" - eslint-visitor-keys "^3.3.0" - espree "^9.4.0" - esquery "^1.4.0" - esutils "^2.0.2" - fast-deep-equal "^3.1.3" - file-entry-cache "^6.0.1" - find-up "^5.0.0" - glob-parent "^6.0.2" - globals "^13.19.0" - grapheme-splitter "^1.0.4" - ignore "^5.2.0" - import-fresh "^3.0.0" - imurmurhash "^0.1.4" - is-glob "^4.0.0" - is-path-inside "^3.0.3" - js-sdsl "^4.1.4" - js-yaml "^4.1.0" - json-stable-stringify-without-jsonify "^1.0.1" - levn "^0.4.1" - lodash.merge "^4.6.2" - minimatch "^3.1.2" - natural-compare "^1.4.0" - optionator "^0.9.1" - regexpp "^3.2.0" - strip-ansi "^6.0.1" - strip-json-comments "^3.1.0" - text-table "^0.2.0" - espree@^9.4.0: version "9.4.1" resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd" @@ -11521,7 +11461,7 @@ json-stringify-safe@^5.0.1: resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA== -json5@^1.0.1: +json5@^1.0.1, json5@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA== @@ -12930,9 +12870,9 @@ minipass@^3.0.0, minipass@^3.1.1, minipass@^3.1.6: yallist "^4.0.0" minipass@^4.0.0: - version "4.2.1" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.1.tgz#084031141113657662d40f66f9c2329036892128" - integrity sha512-KS4CHIsDfOZetnT+u6fwxyFADXLamtkPxkGScmmtTW//MlRrImV+LtbmbJpLQ86Hw7km/utbfEfndhGBrfwvlA== + version "4.2.4" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.4.tgz#7d0d97434b6a19f59c5c3221698b48bbf3b2cd06" + integrity sha512-lwycX3cBMTvcejsHITUgYj6Gy6A7Nh4Q6h9NP4sTHY1ccJlC7yKzDmiShEHsJ16Jf1nKGDEaiHxiltsJEvk0nQ== minizlib@^2.1.1, minizlib@^2.1.2: version "2.1.2" @@ -13592,9 +13532,9 @@ obuf@^1.0.0, obuf@^1.1.2: integrity sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg== ol-mapbox-style@^9.2.0: - version "9.6.0" - resolved "https://registry.yarnpkg.com/ol-mapbox-style/-/ol-mapbox-style-9.6.0.tgz#d20d700520eca3830a979bb93a9251b9c16496a0" - integrity sha512-5XK1fAikf2q6gFozsdrRUCfRgKeQEj7EORECAb7zzi91MXL97AjSUSaKCMzNXtKhm2yyXx4jQth9KsF5h658Iw== + version "9.7.0" + resolved "https://registry.yarnpkg.com/ol-mapbox-style/-/ol-mapbox-style-9.7.0.tgz#38a4f7abc8f0a94f378dcdb7cefdcc69ca3f6287" + integrity sha512-YX3u8FBJHsRHaoGxmd724Mp5WPTuV7wLQW6zZhcihMuInsSdCX1EiZfU+8IAL7jG0pbgl5YgC0aWE/MXJcUXxg== dependencies: "@mapbox/mapbox-gl-style-spec" "^13.23.1" mapbox-to-css-font "^2.4.1" @@ -17391,12 +17331,12 @@ tsconfig-paths-webpack-plugin@4.0.0: tsconfig-paths "^4.0.0" tsconfig-paths@^3.14.1: - version "3.14.1" - resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a" - integrity sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ== + version "3.14.2" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088" + integrity sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g== dependencies: "@types/json5" "^0.0.29" - json5 "^1.0.1" + json5 "^1.0.2" minimist "^1.2.6" strip-bom "^3.0.0"