Skip to content

feat: Allow additional tasks states and filtering by states #675 #670

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

Closed
wants to merge 29 commits into from

Conversation

sytone
Copy link
Contributor

@sytone sytone commented May 19, 2022

Description

When toggling a task, it should be able to move through more states than Todo (- [ ]) or Done (- [x]). This new feature will allow users to provide additional states with - [-] and - [/] being available by default.

The users will also be able to add their own status types and transistions between them to allow further customization.

Changes

  • Add new script to generate a development build with sourcemap included for debugging in Obsidian.
  • Add / Update tests for new Status types.
  • Update settings UI to allow users to add custom types.
  • Update the Task UI to allow user to select new status types.
  • Add / Update query to handle any Status changes and update unit tests.
  • Update Sort to handle new status options.

Motivation and Context

There have been multiple asks to have additional staus types in the discussions and other plugins now support this. To ensure the Tasks plugin can support all these requests and features the new status model has been created.

How has this been tested?

This has been tested via the new unit tests for the status and status registry. This will cover the existing functionality as well as the new ability to add new status types and transisii0ons. Currently there is no automated UI testing. That is being done manually.

As this change also impacts the Task object, UI and settings all related tests have been validated and updated as needed.

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project and passes yarn run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • My change has adequate Unit Test coverage.

By creating a Pull Request you agree to our Code of Conduct. For further guidance on contributing please see contributing guide

sytone added 18 commits May 2, 2022 23:36
Add dev setup to contributing
Add tags as a property of task
Add query by tag in query language
Add sort by tag
Added unit tests for coverage
Implement feedback on filter and tag sorting, ready for next release obsidian-tasks-group#632
docs: add documentation on tag sorting
fix: handle lack of tag in the comparison for tag sorting
test: add increased test coverage to tags
@sytone
Copy link
Contributor Author

sytone commented May 19, 2022

@schemar & @claremacrae here is the draft of adding new status types, will make the task management and tracking more flexible. I am using it locally and working fine.

sytone added 7 commits May 19, 2022 20:01
A task with a character between the square brackets
should be marked as checked and have the is-checked
class on the parent LI
Allows optional or features in development to be enabled conditionally,
there is a second commit coming to move the new functionality
under the relevant flags which will make the PR review and
check in simpler as code can go in but not be used until the flag is set.
@schemar
Copy link
Collaborator

schemar commented May 22, 2022

Thank you, @sytone. It appears this PR includs changes that are not relevant to this PR, or am I seeing that wrong? Does this PR depend on earlier PRs?

@sytone
Copy link
Contributor Author

sytone commented May 22, 2022

It was only dependent on the tags pr. I have added the features capabilities as I am planning on adding the menu option which will be in a preview based mode to see how other users would want to use it.

What extra did you see.

@sytone
Copy link
Contributor Author

sytone commented May 22, 2022

oh it is the append global filter. I meant to push that to a separate branch on top of this and forgot to run command. Will pull it out

@sytone sytone changed the title feat: Allow additional tasks states and filtering by states #666 feat: Allow additional tasks states and filtering by states #675 May 22, 2022
@sytone sytone marked this pull request as ready for review May 23, 2022 00:48
Copy link
Collaborator

@claremacrae claremacrae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for doing this. I know the functionality will be greatly appreciated.

Some initial comments.


const banner =
`/*
import process from 'process';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has been reformatted, which makes it impossible to see if or where the content has changed.

And also, not possible to know whether any change was related to the topic of this PR, or something independent that could/should have been in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill reset the structure, ironically this is now formatted using the same settings as lint 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #683

.gitattributes Outdated
@@ -0,0 +1,2 @@
*.js text eol=lf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does changing line endings relate to "feat: Allow additional tasks states and filtering by states"?

Could this be a separate PR, with a statement about motivation?

What impact will this have on anyone who already has a clone of this repo on Windows? In the past, when these attributes have changed, I think I have struggled to get a clean repo, because it sees any local CRLF as differences. I seem to recall being confused, in any case.

From my own experience, I feel that mixing (seemingly) unrelated changes inside one PR generally makes it harder for reviews. The more focussed a PR is, the quicker it can be reviewed, and the quicker separate PRs for later features can be started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reduces noise in windows, if you have CRLF and then add them in the file will just go away as git is smart enough to know that they are the same on commit/push. However in a IDE they will be different as CRLF <> LF and you will get reg conflicts.

Adding this in just lets the IDE/git know they should always be LF on all operating systems and to ignore the git config settings for LF/CRLF for these files.

I can add this to a very small PR if needed, typically we would not make a separate PR for something like this and place it in a change going in as it is small and easily identified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made #682, so when it goes in an I merge with main this file will go away from this PR.

package.json Outdated
"lint": "eslint ./src --fix && eslint ./tests --fix && tsc --noEmit --pretty && svelte-check",
"test": "jest --ci",
"test:dev": "jest --watch"
"test:dev": "jest --watch",
"test:obsidian": "pwsh -ExecutionPolicy Unrestricted -NoProfile -File ./scripts/Test-TasksInLocalObsidian.ps1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, using PowerShell to drive Obsidian. This is very intriguing!

Will it work on Linux and Mac? (I know that PowerShell has been released on those platforms, but I don't know whether it can drive Obsidian on those platforms.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later: it doesn't drive obsidian, it copies a distribution in to a vault.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works across platforms. I use it on my linux machine and in WSL on windows. I am using it as bash sends me around the twist these days with string manipulation. Being able to work with objects in the shell is much better.

I am slowly playing with a PowerShell module that will work with obsidian and the shell plugin also supports running PowerShell scripts. This will setup synlinks to the vault you specify in a environment variable or via the command line and then start the build watch process. Makes the dev cycle faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #683

@@ -0,0 +1,53 @@
[CmdletBinding()]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, based on the file name, I misunderstood the purpose of this file. I though it was actually testing Obsidian, but it is copying the built plugin in to an Obsidian vault.

That's still very useful, but also a candidate for being in a separate PR please (alongside the associated change to package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using it to help me work on this PR. So there will be a chicken egg scenario. Ill make a separate PR and if it goes in first then this will disappear from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #683

@@ -64,11 +66,10 @@ const taskFromLine = ({ line, path }: { line: string; path: string }): Task => {
// Should never happen; everything in the regex is optional.
console.error('Tasks: Cannot create task on line:', line);
return new Task({
status: Status.Todo,
status: Status.TODO,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education, I'm curious as to why Todo -> TODO?

Asking as it increases the number of changes to review, not because I want to change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency in code, as these are constants I have seen they should be upper case in TS/JS. Also makes it super easy to see when reading code that these are not a normal variable.

* Compare to the fromString() method, which deserializes the object.
*/
public toJSON() {
return this.internalName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is internalName?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the string name or key that is used to identify the feature. This makes sense now, seeing how Feature is used in the settings code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the key, separate to the nicer one that users see.

@@ -1,18 +1,31 @@
import { Feature, FeatureFlag } from './Feature';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing the feature flag code mixed in here makes me wonder if it would be possible for the feature flag feature to be pulled out and implemented as its own PR first?

I realised it may be too late for that now, but them being combined does mean a full review is going to take a while.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, see how much of a issue it is.

};

let settings: Settings = { ...defaultSettings };

export const getSettings = (): Settings => {
// Check to see if there is a new flag and if so add it to the users settings.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that if this code is released, users who look at their settings will see the feature flag and be inclined to turn it on, not realising that the feature is not fully tested, and so initially disabled by default for a good reason?

I think that's probably fine, but it would still be helpful to understand....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the settings at the bottom with indicators to its stability.

@@ -21,3 +34,15 @@ export const updateSettings = (newSettings: Partial<Settings>): Settings => {

return getSettings();
};

export const isFeatureEnabled = (internalName: string): boolean => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting - I had looked for this kind of convenience method in the Feature code, not realising it would be in the Settings code.

Totally happy for it to be here... If there isn't a comment in the Feature code mentioning these accessors, it would probably be worth adding one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will updated comments, the settings is responsible for what is on and off, feature just lets the plugin in know about a feature and its internal state.

Comment on lines +702 to +707
const defaultTasksWithStatus = [
'- [ ] Something to do',
'- [/] Something I am doing',
'- [x] Something I have done',
'- [-] Something I will no longer do',
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the thinking behind changing the default statuses?
Will there be any change in behaviour from the current?
Oh, this is test code. I was confused by the variable name...

@claremacrae
Copy link
Collaborator

Closing. As well as containing unrelated changes, this is superseded by #799.

@cmprmsd
Copy link

cmprmsd commented Dec 23, 2022

In #2 (comment) @sytone proposed some changes that made it possible to have more than two state values and toggle them with clicks.

image

Was this pull request that change? I think after all the closed PRs the user got demotivated to further tackle this feature merge 😰

It was a great idea though!

@rinogo
Copy link

rinogo commented Jan 20, 2023

Bummer this was closed. It's exactly what I'm looking for. Maybe I'll create a standalone plugin to accomplish this.

@claremacrae
Copy link
Collaborator

Yes, this PR was closed for good reasons at the time.

BUT I have been spending 3 weeks working approximately full time on incorporating the code from this PR in to the latest Tasks code base, fixing bugs and usability and backwards compatibility issues.

I still have lots of work to do on the documentation.

Then it will be released soon.

Feel free to create another plugin if you wish @rinogo - but to get it releasable quality you will find it is a lot of work.

@rinogo
Copy link

rinogo commented Jan 20, 2023

That's great news! I was actually referring to specifically being able to cycle through each valid state (i.e. more than just unchecked/checked) of a checkbox onclick without any extra functionality. (which is a much more straightforward use case)

Certainly, it's a lot more work incorporating changes like this into a larger codebase!

Need any help testing? Happy to help out.

@claremacrae
Copy link
Collaborator

Need any help testing? Happy to help out.

Feel free: #1530

Do read the last two comments before spending ages setting up lots of custom statuses.

@claremacrae
Copy link
Collaborator

A heavily modified, fixed and documented version of this PR was released in Tasks 1.24.0 - with major credit given to the author of this PR both in the docs and the announcement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants