Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

feat: add defaults to view filter and view group #883

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
2 changes: 2 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
View Filters config structure changed
View Groups config structure changed
35 changes: 21 additions & 14 deletions packages/core/dev-test/backends/bitbucket/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,28 @@ collections:
field: title
create: true
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
pattern: true
filters:
- name: posts-with-index
label: Posts With Index
field: title
pattern: 'This is post #'
- name: posts-without-index
label: Posts Without Index
field: title
pattern: front matter post
- name: drafts
label: Drafts
field: draft
pattern: true
view_groups:
- label: Year
field: date
pattern: '\d{4}'
- label: Drafts
field: draft
groups:
- name: by-year
label: Year
field: date
pattern: '\d{4}'
- name: drafts
label: Drafts
field: draft
fields:
- label: Title
name: title
Expand Down
35 changes: 21 additions & 14 deletions packages/core/dev-test/backends/git-gateway/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@ collections:
field: title
create: true
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
pattern: true
filters:
- name: posts-with-index
label: Posts With Index
field: title
pattern: 'This is post #'
- name: posts-without-index
label: Posts Without Index
field: title
pattern: front matter post
- name: drafts
label: Drafts
field: draft
pattern: true
view_groups:
- label: Year
field: date
pattern: '\d{4}'
- label: Drafts
field: draft
groups:
- name: by-year
label: Year
field: date
pattern: '\d{4}'
- name: drafts
label: Drafts
field: draft
fields:
- label: Title
name: title
Expand Down
35 changes: 21 additions & 14 deletions packages/core/dev-test/backends/github/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,28 @@ collections:
field: title
create: true
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
pattern: true
filters:
- name: posts-with-index
label: Posts With Index
field: title
pattern: 'This is post #'
- name: posts-without-index
label: Posts Without Index
field: title
pattern: front matter post
- name: drafts
label: Drafts
field: draft
pattern: true
view_groups:
- label: Year
field: date
pattern: '\d{4}'
- label: Drafts
field: draft
groups:
- name: by-year
label: Year
field: date
pattern: '\d{4}'
- name: drafts
label: Drafts
field: draft
fields:
- label: Title
name: title
Expand Down
35 changes: 21 additions & 14 deletions packages/core/dev-test/backends/gitlab/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,28 @@ collections:
- date
create: true
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
pattern: true
filters:
- name: posts-with-index
label: Posts With Index
field: title
pattern: 'This is post #'
- name: posts-without-index
label: Posts Without Index
field: title
pattern: front matter post
- name: drafts
label: Drafts
field: draft
pattern: true
view_groups:
- label: Year
field: date
pattern: '\d{4}'
- label: Drafts
field: draft
groups:
- name: by-year
label: Year
field: date
pattern: '\d{4}'
- name: drafts
label: Drafts
field: draft
fields:
- label: Title
name: title
Expand Down
35 changes: 21 additions & 14 deletions packages/core/dev-test/backends/proxy/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,28 @@ collections:
field: title
create: true
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
pattern: true
filters:
- name: posts-with-index
label: Posts With Index
field: title
pattern: 'This is post #'
- name: posts-without-index
label: Posts Without Index
field: title
pattern: front matter post
- name: drafts
label: Drafts
field: draft
pattern: true
view_groups:
- label: Year
field: date
pattern: '\d{4}'
- label: Drafts
field: draft
groups:
- name: by-year
label: Year
field: date
pattern: '\d{4}'
- name: drafts
label: Drafts
field: draft
fields:
- label: Title
name: title
Expand Down
35 changes: 21 additions & 14 deletions packages/core/dev-test/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,28 @@ collections:
field: title
create: true
view_filters:
- label: Posts With Index
field: title
pattern: 'This is post #'
- label: Posts Without Index
field: title
pattern: front matter post
- label: Drafts
field: draft
pattern: true
filters:
- name: posts-with-index
label: Posts With Index
field: title
pattern: 'This is post #'
- name: posts-without-index
label: Posts Without Index
field: title
pattern: front matter post
- name: drafts
label: Drafts
field: draft
pattern: true
view_groups:
- label: Year
field: date
pattern: '\d{4}'
- label: Drafts
field: draft
groups:
- name: by-year
label: Year
field: date
pattern: '\d{4}'
- name: drafts
label: Drafts
field: draft
fields:
- label: Title
name: title
Expand Down
66 changes: 38 additions & 28 deletions packages/core/src/__tests__/testConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,44 @@ const testConfig: Config<RelationKitchenSinkPostField> = {
},
},
create: true,
view_filters: [
{
label: 'Posts With Index',
field: 'title',
pattern: 'This is post #',
},
{
label: 'Posts Without Index',
field: 'title',
pattern: 'front matter post',
},
{
label: 'Drafts',
field: 'draft',
pattern: true,
},
],
view_groups: [
{
label: 'Year',
field: 'date',
pattern: '\\d{4}',
},
{
label: 'Drafts',
field: 'draft',
},
],
view_filters: {
default: 'posts-without-index',
filters: [
{
name: 'posts-with-index',
label: 'Posts With Index',
field: 'title',
pattern: 'This is post #',
},
{
name: 'posts-without-index',
label: 'Posts Without Index',
field: 'title',
pattern: 'front matter post',
},
{
name: 'draft',
label: 'Drafts',
field: 'draft',
pattern: true,
},
],
},
view_groups: {
groups: [
{
name: 'by-year',
label: 'Year',
field: 'date',
pattern: '\\d{4}',
},
{
name: 'draft',
label: 'Drafts',
field: 'draft',
},
],
},
fields: [
{
label: 'Title',
Expand Down
30 changes: 18 additions & 12 deletions packages/core/src/actions/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,25 @@ export function applyDefaults<EF extends BaseField = UnknownField>(
};
}

collection.view_filters = (view_filters || []).map(filter => {
return {
...filter,
id: `${filter.field}__${filter.pattern}`,
};
});
collection.view_filters = {
default: collection.view_filters?.default,
filters: (view_filters?.filters ?? []).map(filter => {
return {
...filter,
id: `${filter.field}__${filter.pattern}`,
};
}),
};

collection.view_groups = (view_groups || []).map(group => {
return {
...group,
id: `${group.field}__${group.pattern}`,
};
});
collection.view_groups = {
default: collection.view_groups?.default,
groups: (view_groups?.groups ?? []).map(group => {
return {
...group,
id: `${group.field}__${group.pattern}`,
};
}),
};
}
});
}
Expand Down
Loading