-
-
Notifications
You must be signed in to change notification settings - Fork 590
add: include and exclude filters for pagination #3103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
7d8000b
e4025d2
d0afc09
f11bb2c
9e0a9cb
804470e
8095b27
933eb12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,28 @@ class Pagination { | |
| } | ||
|
|
||
| isFiltered(value) { | ||
| const hasInclude = "include" in this.data.pagination; | ||
| const hasExclude = "exclude" in this.data.pagination; | ||
| if (hasInclude && hasExclude) { | ||
| throw new Error("Pagination cannot have both `include` and `exclude` filters."); | ||
| } | ||
| if (hasInclude) { | ||
| let included = this.data.pagination.include; | ||
| if (Array.isArray(included)) { | ||
| return included.indexOf(value) === -1; | ||
|
Snapstromegon marked this conversation as resolved.
Outdated
|
||
| } | ||
| return included !== value; | ||
| } | ||
| if (hasExclude) { | ||
| let excluded = this.data.pagination.exclude; | ||
| if (Array.isArray(excluded)) { | ||
| return excluded.indexOf(value) !== -1; | ||
|
Snapstromegon marked this conversation as resolved.
Outdated
|
||
| } | ||
| return excluded === value; | ||
| } | ||
|
|
||
| // Let's keep this code for backwards compatibility to V2. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this old
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be happy to do so, but I think this should be communicated, since it affects the public API of this plugin. Is there a way to log warnings if someone still uses filters?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we add a warning when someone uses
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly. My question is, if there is a better way than throwing an error or using console.warn for this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see anywhere else where we are throwing an error or console.warn-ing for a deprecation. Seems like those just get tagged as deprecated with JSDoc but aren't removed or changed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @zachleat, how would you want me to handle this here? |
||
| // TODO remove in 3.0 | ||
| if ("filter" in this.data.pagination) { | ||
| let filtered = this.data.pagination.filter; | ||
| if (Array.isArray(filtered)) { | ||
|
|
@@ -162,7 +184,11 @@ class Pagination { | |
| result = result.reverse(); | ||
| } | ||
|
|
||
| if (this.data.pagination.filter) { | ||
| if ( | ||
| this.data.pagination.filter || | ||
| this.data.pagination.include || | ||
| this.data.pagination.exclude | ||
| ) { | ||
| result = result.filter((value) => !this.isFiltered(value)); | ||
|
Snapstromegon marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| pagination: | ||
| data: testdata | ||
| size: 4 | ||
| exclude: | ||
| - item4 | ||
| testdata: | ||
| item1: itemvalue1 | ||
| item2: itemvalue2 | ||
| item3: itemvalue3 | ||
| item4: itemvalue4 | ||
| item5: itemvalue5 | ||
| item6: itemvalue6 | ||
| item7: itemvalue7 | ||
| item8: itemvalue8 | ||
| item9: itemvalue9 | ||
| --- | ||
| <ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| pagination: | ||
| data: testdata | ||
| size: 4 | ||
| exclude: item4 | ||
| testdata: | ||
| item1: itemvalue1 | ||
| item2: itemvalue2 | ||
| item3: itemvalue3 | ||
| item4: itemvalue4 | ||
| item5: itemvalue5 | ||
| item6: itemvalue6 | ||
| item7: itemvalue7 | ||
| item8: itemvalue8 | ||
| item9: itemvalue9 | ||
| --- | ||
| <ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| pagination: | ||
| data: testdata | ||
| size: 4 | ||
| include: | ||
| - item3 | ||
| - item4 | ||
| testdata: | ||
| item1: itemvalue1 | ||
| item2: itemvalue2 | ||
| item3: itemvalue3 | ||
| item4: itemvalue4 | ||
| item5: itemvalue5 | ||
| item6: itemvalue6 | ||
| item7: itemvalue7 | ||
| item8: itemvalue8 | ||
| item9: itemvalue9 | ||
| --- | ||
| <ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| pagination: | ||
| data: testdata | ||
| size: 4 | ||
| include: item4 | ||
| exclude: item5 | ||
| testdata: | ||
| item1: itemvalue1 | ||
| item2: itemvalue2 | ||
| item3: itemvalue3 | ||
| item4: itemvalue4 | ||
| item5: itemvalue5 | ||
| item6: itemvalue6 | ||
| item7: itemvalue7 | ||
| item8: itemvalue8 | ||
| item9: itemvalue9 | ||
| --- | ||
| <ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| pagination: | ||
| data: testdata | ||
| size: 4 | ||
| include: item4 | ||
| testdata: | ||
| item1: itemvalue1 | ||
| item2: itemvalue2 | ||
| item3: itemvalue3 | ||
| item4: itemvalue4 | ||
| item5: itemvalue5 | ||
| item6: itemvalue6 | ||
| item7: itemvalue7 | ||
| item8: itemvalue8 | ||
| item9: itemvalue9 | ||
| --- | ||
| <ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol> |
Uh oh!
There was an error while loading. Please reload this page.