generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
feat: change names of groups from Priority Field and change the sort of order groups same as task sorting order #1966
Closed
ilandikov
wants to merge
21
commits into
obsidian-tasks-group:main
from
ilandikov:feat-more-readable-names-in-priority
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d7fc0dc
test: document current group sorting of PriorityField
ilandikov 1acce88
refactor: move localeCompare to groupSorter
ilandikov 1e7e92c
refactor: move groupSorter to Field
ilandikov edca28f
refactor: rename sorter to comparator
ilandikov 3f1cb45
refactor: move groupComparator() to the bottom
ilandikov 5e827e4
refactor: custom groupComparator() in PriorityField
ilandikov e9355f2
refactor: add Priority.toNumber()
ilandikov d0a078f
feat: make Priority group names shorter
ilandikov 090c195
refactor: rename types
ilandikov f61c819
fix: toNumber() default priority is 3
ilandikov 1d29d1d
refactor: remove temp variable
ilandikov bf597ea
refactor: shorter import type
ilandikov fefd7b2
test: fix test description
ilandikov 3180630
refactor: compare first tasks instead of group names
ilandikov 11c12be
docs: update group names in docs
ilandikov b7f9f20
test: test priority group sorting
ilandikov 67a5baf
docs: document updated urgency grouping behaviour
ilandikov 65d132c
refactor: add DescriptionLengthGroupingfield for testing
ilandikov 8c2adc3
fix: add defalt group comparator if Field does not support sorting
ilandikov 75e6cf7
test: test default group comparator
ilandikov a5c389c
test: fix date to fix urgency calculation
ilandikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Task } from 'Task'; | ||
import type { GrouperFunction } from 'Query/Grouper'; | ||
import { Field } from './Field'; | ||
import { FilterOrErrorMessage } from './Filter'; | ||
|
||
/** This is a class for test purposes of a Field that supports grouping but not sorting | ||
*/ | ||
export class DescriptionLengthGroupingfield extends Field { | ||
protected filterRegExp(): RegExp | null { | ||
throw new Error('No filtering for description length field'); | ||
} | ||
public fieldName(): string { | ||
return 'description length'; | ||
} | ||
|
||
public value(task: Task): number { | ||
return task.description.length; | ||
} | ||
|
||
public createFilterOrErrorMessage(line: string): FilterOrErrorMessage { | ||
return FilterOrErrorMessage.fromError(line, 'description length field does not support filtering'); | ||
} | ||
|
||
// ----------------------------------------------------------------------------------------------------------------- | ||
// Sorting | ||
// ----------------------------------------------------------------------------------------------------------------- | ||
|
||
// Doesn't support sorting by default as in Field.ts | ||
|
||
// ----------------------------------------------------------------------------------------------------------------- | ||
// Grouping | ||
// ----------------------------------------------------------------------------------------------------------------- | ||
|
||
public supportsGrouping(): boolean { | ||
return true; | ||
} | ||
|
||
public grouper(): GrouperFunction { | ||
return (task: Task) => { | ||
return [this.value(task).toString()]; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { DescriptionLengthGroupingfield } from '../../../src/Query/Filter/DescriptionLengthGroupingField'; | ||
import { fromLine } from '../../TestHelpers'; | ||
import { TaskGroups } from '../../../src/Query/TaskGroups'; | ||
|
||
describe('test a Field class that supports grouping without sorting', () => { | ||
it('should create the grouper', () => { | ||
const grouper = new DescriptionLengthGroupingfield().createNormalGrouper(); | ||
expect(grouper).toBeDefined(); | ||
}); | ||
|
||
it('should group in default (alphabetical) order', () => { | ||
const tasks = [ | ||
fromLine({ line: '- [ ] descrip' }), | ||
fromLine({ line: '- [ ] desc' }), | ||
fromLine({ line: '- [ ] description' }), | ||
fromLine({ line: '- [ ] d' }), | ||
]; | ||
const grouper = [new DescriptionLengthGroupingfield().createNormalGrouper()]; | ||
const groups = new TaskGroups(grouper, tasks); | ||
|
||
expect(groups.toString()).toMatchInlineSnapshot(` | ||
"Groupers (if any): | ||
- description length | ||
|
||
Group names: [1] | ||
#### [description length] 1 | ||
- [ ] d | ||
|
||
--- | ||
|
||
Group names: [4] | ||
#### [description length] 4 | ||
- [ ] desc | ||
|
||
--- | ||
|
||
Group names: [7] | ||
#### [description length] 7 | ||
- [ ] descrip | ||
|
||
--- | ||
|
||
Group names: [11] | ||
#### [description length] 11 | ||
- [ ] description | ||
|
||
--- | ||
|
||
4 tasks | ||
" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens with this code if the field does not implement sorting?
I expect that calling
this.comparator()
will then throw some kind of exception.If you look at the Quick Reference table you will find a few such cases - such as recurrence or recurring (I forget which).
And certainly the new
group by function
will create a grouper that does not sort.So... you could write a failing test using recurrence, but if it is taught to sort in future, that test will become useless.
So the testing trick here is to write a new test and have it use a simple implementation for Field that does grouping but not sorting. Perhaps
DescriptionLengthGroupingfield
. A field that is written purely to make testing easy and self-explanatory.Then line 67 can be changed to only use
this.comparator()
ifsupportsSorting()
is true, and if not, fall back on the old behaviour of sorting by group name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point, thanks.
Yup, I did that now, this seems to be a good trade-off.
On
Field
level I don't have access to the group names so I can't compare them in the fall back case. I'm not really sure how to solve this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I got this, but not sure whether it is a good solution. Something smells here, can't tell what exactly. Probably the whole direction of the development ㅠㅠ