Fix: get files by path depth (#2993)
* fix: get files up to depth specified by colletion path * test(e2e): update mock data * chore: fix comment
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { parseLinkHeader, getAllResponses } from '../backendUtil';
|
||||
import { parseLinkHeader, getAllResponses, getCollectionDepth } from '../backendUtil';
|
||||
import { oneLine } from 'common-tags';
|
||||
import { Map } from 'immutable';
|
||||
import nock from 'nock';
|
||||
|
||||
describe('parseLinkHeader', () => {
|
||||
@ -69,3 +70,13 @@ describe('getAllResponses', () => {
|
||||
expect(pages[2]).toHaveLength(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCollectionDepth', () => {
|
||||
it('should return 1 for collection with no path', () => {
|
||||
expect(getCollectionDepth(Map({}))).toBe(1);
|
||||
});
|
||||
|
||||
it('should return 2 for collection with path of one nested folder', () => {
|
||||
expect(getCollectionDepth(Map({ path: '{{year}}/{{slug}}' }))).toBe(2);
|
||||
});
|
||||
});
|
||||
|
@ -77,3 +77,8 @@ export const getAllResponses = async (url, options = {}, linkHeaderRelName = 'ne
|
||||
|
||||
return pageResponses;
|
||||
};
|
||||
|
||||
export const getCollectionDepth = collection => {
|
||||
const depth = collection.get('path', '').split('/').length;
|
||||
return depth;
|
||||
};
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
parseLinkHeader,
|
||||
parseResponse,
|
||||
responseParser,
|
||||
getCollectionDepth,
|
||||
} from './backendUtil';
|
||||
import loadScript from './loadScript';
|
||||
import getBlobSHA from './getBlobSHA';
|
||||
@ -46,6 +47,7 @@ export const NetlifyCmsLibUtil = {
|
||||
responseParser,
|
||||
loadScript,
|
||||
getBlobSHA,
|
||||
getCollectionDepth,
|
||||
};
|
||||
export {
|
||||
APIError,
|
||||
@ -73,4 +75,5 @@ export {
|
||||
getBlobSHA,
|
||||
asyncLock,
|
||||
isAbsolutePath,
|
||||
getCollectionDepth,
|
||||
};
|
||||
|
Reference in New Issue
Block a user