Skip to content

Commit

Permalink
Fixes query-related fields not having a "hidden" class:
Browse files Browse the repository at this point in the history
  • Loading branch information
esm7 committed Apr 23, 2023
1 parent 88a519f commit fc26e1b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
background-color: aqua;
}

ul.contains-task-list.tasks-layout-hide-priority {
ul.contains-task-list.tasks-layout-hide-priority.tasks-layout-hide-backlinks.tasks-layout-hide-urgency.tasks-layout-hide-edit-button {
color: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ short mode
```tasks
path includes Styling of Queries
hide priority
hide backlinks
hide urgency
hide edit button
```

- [ ] 6. Open the Obsidian settings of the Demo vault and under Appearance | CSS Snippets, turn **off** `tasks-plugin-smoke-test-query-styling`.
Expand Down
14 changes: 14 additions & 0 deletions src/TaskLayout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Various rendering options for a query.
* See applyOptions below when adding options here.
*/
export class LayoutOptions {
hideTaskCount: boolean = false;
Expand Down Expand Up @@ -84,6 +85,11 @@ export class TaskLayout {
return taskComponents;
}
};
const markHiddenQueryComponent = (hidden: boolean, hiddenComponentName: string) => {
if (hidden) {
this.specificClasses.push(`tasks-layout-hide-${hiddenComponentName}`);
}
};
// Remove components from the layout according to the task options. These represent the existing task options,
// so some components (e.g. the description) are not here because there are no layout options to remove them.
let newComponents = this.layoutComponents;
Expand All @@ -94,6 +100,14 @@ export class TaskLayout {
newComponents = removeIf(newComponents, layoutOptions.hideScheduledDate, 'scheduledDate');
newComponents = removeIf(newComponents, layoutOptions.hideDueDate, 'dueDate');
newComponents = removeIf(newComponents, layoutOptions.hideDoneDate, 'doneDate');
// The following components are handled in QueryRenderer.ts and thus are not part of the same flow that
// hides TaskLayoutComponent items. However, we still want to have 'tasks-layout-hide' items for them
// (see https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1866).
// This can benefit from some refactoring, i.e. render these components in a similar flow rather than
// separately.
markHiddenQueryComponent(layoutOptions.hideUrgency, 'urgency');
markHiddenQueryComponent(layoutOptions.hideBacklinks, 'backlinks');
markHiddenQueryComponent(layoutOptions.hideEditButton, 'edit-button');
if (layoutOptions.shortMode) this.specificClasses.push('tasks-layout-short-mode');
return newComponents;
}
Expand Down

0 comments on commit fc26e1b

Please sign in to comment.