Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/decap-cms-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare module 'decap-cms-core' {
label?: string;
required?: boolean;
hint?: string;
pattern?: [string, string];
pattern?: [string | RegExp, string];
i18n?: boolean | 'translate' | 'duplicate' | 'none';
media_folder?: string;
public_folder?: string;
Expand Down Expand Up @@ -299,7 +299,7 @@ declare module 'decap-cms-core' {
export interface ViewFilter {
label: string;
field: string;
pattern: string;
pattern: string | boolean;
}

export interface ViewGroup {
Expand Down
16 changes: 9 additions & 7 deletions packages/decap-cms-core/src/reducers/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,16 @@ function getGroup(entry: EntryMap, selectedGroup: GroupMap) {
if (selectedGroup.has('pattern')) {
const pattern = selectedGroup.get('pattern');
let value = '';
try {
const regex = new RegExp(pattern);
const matched = dataAsString.match(regex);
if (matched) {
value = matched[0];
if (pattern !== undefined) {
try {
const regex = new RegExp(pattern);
const matched = dataAsString.match(regex);
if (matched) {
value = matched[0];
}
} catch (e) {
console.warn(`Invalid view group pattern '${pattern}' for field '${field}'`, e);
}
} catch (e) {
console.warn(`Invalid view group pattern '${pattern}' for field '${field}'`, e);
}
return {
id: `${label}${value}`,
Expand Down
6 changes: 3 additions & 3 deletions packages/decap-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface CmsFieldBase {
label?: string;
required?: boolean;
hint?: string;
pattern?: [string, string];
pattern?: [string | RegExp, string];
i18n?: boolean | 'translate' | 'duplicate' | 'none';
media_folder?: string;
public_folder?: string;
Expand Down Expand Up @@ -315,14 +315,14 @@ export interface CmsCollectionFile {
export interface ViewFilter {
label: string;
field: string;
pattern: string;
pattern: string | boolean;
id: string;
}

export interface ViewGroup {
label: string;
field: string;
pattern: string;
pattern?: string;
id: string;
}

Expand Down
Loading