Skip to content
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

Query for all tasks in the query's path, folder, filename etc does not work in canvas cards #2971

Open
4 of 7 tasks
psigurdsson opened this issue Jul 19, 2024 · 8 comments
Open
4 of 7 tasks
Labels
obsidian Requires an update from Obsidian scope: canvas Anything related to Obsidian .canvas files scope: filters Additions and modifications to the search filters scope: scripting Issues to do with custom filters, custom sorting and similar type: bug Something isn't working type: third-party change needed Would need changes in a library of code that Tasks uses - cannot be fixed in Tasks

Comments

@psigurdsson
Copy link

psigurdsson commented Jul 19, 2024

Please check that this issue hasn't been reported before.

  • I searched previous Bug Reports didn't find any similar reports.

Expected Behavior

Expected is that the following query will work when placed inside a canvas card, since it works inside a normal markdown note:

```tasks  
filter by function task.file.folder.includes(query.file.folder)
```

Current behaviour

Instead of showing the task contained inside the note in the subfolder, the canvas card containing this query shows the following error message:

Tasks query: Error: Search failed.
The error message was:
    "TypeError: Cannot read properties of null (reading 'file')"

Steps to reproduce

From @claremacrae: there is also a shorter reproduction in #2971 (comment)...

Full description of the steps to reproduce:

  1. Create a new Obsidian vault
    • Click the line with the name of your vault, at the bottom next to the gear icon
    • Select "Manage vaults"
    • Select Create new vault
    • Give the vault a name and click Create
  2. In the new vault, ensure that Canvas plugin is enabled
    • Click the gear icon
    • Select Core plugins
    • Verify that the slider next to Canvas is showing that it's active
  3. Get the tasks plugin
    • Click the gear icon again, if needed
    • Select Community plugins from the list
    • Click the "Turn on community plugins" button
    • Click the "Browse" button
    • Find and open "Tasks" by Martin Schenck and Clare Macrae
    • Click Install
    • Click Enable
  4. Create a two-level folder structure
    • Navigate back to the main window by closing the plugin and settings windows
    • Click the new folder icon on the left side of the interface
    • Give the folder a name, e.g. "My projects".
    • Right-click the folder and select "New folder" to create a subfolder
    • Give the subfolder a name, e.g. "Home projects".
  5. Create a new note with a task in the subfolder
    • Right-click the subfolder and click "New note"
    • Give the note a name, if desired, e.g. "Project A", by replacing "Untitled" with "Project A".
    • In the area below, a task, by entering "- [ ] First task"
  6. Create a note in the first level folder which shows all tasks in the folder and subfolders below
    • Right-click the first level folder ("My projects") and click "New note"
    • Give the note a name, if desired, e.g. "Projects list", by replacing "Untitled" with "Project list"
    • In the area below the title, enter the following
    filter by function task.file.folder.includes(query.file.folder)
    
    The note should now show the task contained inside the note in the subfolder and it does.
  7. Create a new canvas inside the first level folder with a card which shows all tasks in the folder and subfolders below
    • Right-click the first level folder ("My projects") and click "New canvas"
    • Right-click an empty area in the canvas and click "Add card"
    • Inside the card, enter the same task query as in step 6 above.

I expected this card now to show the task contained inside the note in the subfolder, but it didn't.

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version

1.6.7

Tasks Plugin Version

7.6.1

Checks

  • I have tried it with all other plugins disabled and the error still occurs

Possible solution

I don't know how to fix this but there is a workaround, which is to add the note which already contains the query to the canvas:

  • Right-click, an empty area in the canvas and click "Add note from vault"
  • Select the note that was created in step 6, above.
    This will now show a canvas card with the list of tasks.

Note from @claremacrae: there is a slightly simpler workaround in #2971 (comment)...

This workaround does not adequately achieve what I want. I want to copy the canvas into many different folders, which already exist, and utilize the same tasks query dynamically. If the functionality would work as expected, I would not need to change anything in the copies in the canvas whereas in the workaround I will have to recreate many of the cards for each copy of the canvas.

@psigurdsson psigurdsson added the type: bug Something isn't working label Jul 19, 2024
@claremacrae claremacrae added scope: canvas Anything related to Obsidian .canvas files scope: filters Additions and modifications to the search filters labels Jul 19, 2024
@claremacrae
Copy link
Collaborator

Thank you very much for finding and reporting the problem.

Having a list of reproduction steps is also very valuable, and much appreciated.

(For future reference, if you ever report another bug in this project, you can save yourself a lot of time by assuming knowledge of basic use of Obsidian, like in this example.)

@claremacrae
Copy link
Collaborator

I can reproduce the problem, and will write up what I've found.

I also note that dataview doesn't recognise the folder containing a query in a canvas file:

```dataview
TASK
WHERE file.folder = this.file.folder
```

@claremacrae
Copy link
Collaborator

The relevant code is the context.sourcePath value in line 48 here:

private async _addQueryRenderChild(source: string, element: HTMLElement, context: MarkdownPostProcessorContext) {
const queryRenderChild = new QueryRenderChild({
app: this.app,
plugin: this.plugin,
events: this.events,
container: element,
source,
tasksFile: new TasksFile(context.sourcePath),
});
context.addChild(queryRenderChild);
queryRenderChild.load();
}

When the Tasks query block is in an ordinary Markdown file, the sourcePath is supplied:

image

When the Tasks query block is in a card inside a Canvas file, the sourcePath is empty:

image

@claremacrae
Copy link
Collaborator

I have asked for help on Obsidian Discord.

@claremacrae
Copy link
Collaborator

I will have to wait and see if the Obsidian team offers a workaround. Currently Obsidian is just not giving plugins the file path of the canvas, so there's nothing I can see to do to fix this.

Possible solution

I don't know how to fix this but there is a workaround, which is to add the note which already contains the query to the canvas:

  • Right-click, an empty area in the canvas and click "Add note from vault"
  • Select the note that was created in step 6, above.
    This will now show a canvas card with the list of tasks.

@psigurdsson You can do that a lot more easily than the Right-click option...

  1. Open the canvas
  2. Drag the note from the Explorer into an empty area in the Canvas

@claremacrae
Copy link
Collaborator

claremacrae commented Jul 19, 2024

A simpler reproduction is:

  1. Create or open a vault with the Tasks plugin installed and enabled
  2. Create an empty test folder, called test folder
  3. Create a markdown note called test task, in that folder:
    • View it in Source or Live Preview mode
    • Run Tasks: Create or edit task
    • Enter any old data and click Apply
  4. Create a new Canvas called test canvas
  5. Add a card to the Canvas and paste in the following text:
```tasks
ignore global query
filter by function task.file.folder.includes(query.file.folder)
explain
```
  1. Click away from the card, so that it is rendered.

Actual result:

image

Expected result (when the same query is used in a Markdown file:

image

@psigurdsson
Copy link
Author

Clare, thanks for the super-quick responses and for the tips, especially on how I can report bugs more efficiently in the future. I'm happy that my bug-report helped develop the tasks plugin, which I'm a great fan of. I'm right now experimenting with creating dashboards for the various aspects of my life, including tasks that I've registered in notes inside folders which represent my areas of focus and that's where this came from. I should be able to use the workaround but there are also other ways to create dashboards than canvas and I might explore those also.

@claremacrae claremacrae added obsidian Requires an update from Obsidian scope: scripting Issues to do with custom filters, custom sorting and similar labels Jul 20, 2024
@claremacrae claremacrae changed the title Query for all tasks in a folder does not work in canvas cards Query for all tasks in the query's folder does not work in canvas cards Aug 16, 2024
@claremacrae
Copy link
Collaborator

I've renamed this to make it clear that the problem is specifically querying using the folder that the query is in, rather than any old folder...

@claremacrae claremacrae changed the title Query for all tasks in the query's folder does not work in canvas cards Query for all tasks in the query's path, folder, filename etc does not work in canvas cards Aug 16, 2024
@claremacrae claremacrae added the type: third-party change needed Would need changes in a library of code that Tasks uses - cannot be fixed in Tasks label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
obsidian Requires an update from Obsidian scope: canvas Anything related to Obsidian .canvas files scope: filters Additions and modifications to the search filters scope: scripting Issues to do with custom filters, custom sorting and similar type: bug Something isn't working type: third-party change needed Would need changes in a library of code that Tasks uses - cannot be fixed in Tasks
Projects
None yet
Development

No branches or pull requests

2 participants