Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/decap-cms-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ declare module 'decap-cms-core' {
publish?: boolean;
nested?: {
depth: number;
subfolders?: boolean;
};
meta?: { path?: { label: string; widget: string; index_file: string } };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class EntriesCollection extends React.Component {
}
}

export function filterNestedEntries(path, collectionFolder, entries) {
export function filterNestedEntries(path, collectionFolder, entries, subfolders) {
const filtered = entries.filter(e => {
let entryPath = e.get('path').slice(collectionFolder.length + 1);
if (!entryPath.startsWith(path)) {
Expand All @@ -130,6 +130,13 @@ export function filterNestedEntries(path, collectionFolder, entries) {
entryPath = entryPath.slice(path.length + 1);
}

// if subfolders legacy mode is enabled, show only immediate subfolders
// also show index file in root folder
if (subfolders) {
const depth = entryPath.split('/').length;
return path ? depth === 2 : depth <= 2;
}

// only show immediate children
return !entryPath.includes('/');
});
Expand All @@ -145,7 +152,12 @@ function mapStateToProps(state, ownProps) {

if (collection.has('nested')) {
const collectionFolder = collection.get('folder');
entries = filterNestedEntries(filterTerm || '', collectionFolder, entries);
entries = filterNestedEntries(
filterTerm || '',
collectionFolder,
entries,
collection.get('nested').get('subfolders'),
);
}
const entriesLoaded = selectEntriesLoaded(state.entries, collection.get('name'));
const isFetching = selectIsFetching(state.entries, collection.get('name'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ function TreeNode(props) {
const collectionName = collection.get('name');

const sortedData = sortBy(treeData, getNodeTitle);
const subfolders = collection.get('nested')?.get('subfolders');
return sortedData.map(node => {
const leaf = node.children.length === 0 && depth > 0;
const leaf =
depth > 0 &&
(subfolders
? node.children.length <= 1 && !node.children[0]?.isDir
: node.children.length === 0);
if (leaf) {
return null;
}
Expand All @@ -90,7 +95,11 @@ function TreeNode(props) {
}
const title = getNodeTitle(node);

const hasChildren = depth === 0 || node.children.some(c => c.isDir);
const hasChildren =
depth === 0 ||
(subfolders
? node.children.some(c => c.children.some(c => c.isDir))
: node.children.some(c => c.isDir));

return (
<React.Fragment key={node.path}>
Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-core/src/constants/configSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function getConfigSchema() {
type: 'object',
properties: {
depth: { type: 'number', minimum: 1, maximum: 1000 },
subfolders: { type: 'boolean' },
summary: { type: 'string' },
},
required: ['depth'],
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export type CollectionFile = StaticallyTypedRecord<{

export type CollectionFiles = List<CollectionFile>;

type NestedObject = { depth: number };
type NestedObject = { depth: number; subfolders?: boolean };

type Nested = StaticallyTypedRecord<NestedObject>;

Expand Down