Skip to content

Commit 98817a1

Browse files
benotternmetulev
authored andcommitted
[bugfix] tasks fix for target-id and initial-id (#78)
* Fix Tasks Documentation * Fixed initial-id and target-id for todo tasks * Removed console.logs * Update docs/components/tasks.md
1 parent fb7086b commit 98817a1

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

docs/components/tasks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: "Person Component"
2+
title: "Tasks Component"
33
description: "The Tasks Component enables the user to view, add, remove, complete, or edit tasks. It works with any tasks in Microsoft Planner or Microsoft To-Do."
44
localization_priority: Normal
5-
author: nmetulev
5+
author: benotter
66
---
77

88
# Tasks Component
@@ -23,7 +23,7 @@ The Tasks Component enables the user to view, add, remove, complete, or edit tas
2323

2424
| Property | Attribute | Description |
2525
| -- | -- | -- |
26-
| `dataSource` | `data-source="todo|planner"` | Sets the Data source for tasks, either Microsoft To-Do, or Microsoft Planner. Default is `planner` |
26+
| `dataSource` | `data-source="todo/planner"` | Sets the Data source for tasks, either Microsoft To-Do, or Microsoft Planner. Default is `planner` |
2727
| `readOnly` | `read-only` | Sets the task interface to be read only (no adding or removing tasks). Default is `false` |
2828
| `initialId` | `initial-id="planner_id/folder_id"` | Sets the initially displayed planner or folder to the provided ID |
2929
| `initialBucketId` | `initial-bucket-id="bucket_id"` | Sets the initially displayed bucket (Planner Data-Source Only) to the provided ID |

src/components/mgt-tasks/mgt-tasks.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,19 @@ export class MgtTasks extends LitElement {
9494

9595
protected firstUpdated() {
9696
if (this.initialId && (!this._currentTargetDresser || this.isDefault(this._currentTargetDresser))) {
97-
this._currentTargetDresser = this.initialId;
98-
this.initialId = null;
97+
if (this.dataSource === 'planner') {
98+
this._currentTargetDresser = this.initialId;
99+
} else if (this.dataSource === 'todo') {
100+
this._currentTargetDrawer = this.initialId;
101+
}
99102
}
100103

101-
if (this.initialBucketId && (!this._currentTargetDrawer || this.isDefault(this._currentTargetDrawer))) {
104+
if (
105+
this.dataSource === 'planner' &&
106+
this.initialBucketId &&
107+
(!this._currentTargetDrawer || this.isDefault(this._currentTargetDrawer))
108+
) {
102109
this._currentTargetDrawer = this.initialBucketId;
103-
this.initialBucketId = null;
104110
}
105111

106112
this.loadTasks();
@@ -109,17 +115,25 @@ export class MgtTasks extends LitElement {
109115
public attributeChangedCallback(name: string, oldVal: string, newVal: string) {
110116
super.attributeChangedCallback(name, oldVal, newVal);
111117
if (name === 'data-source') {
112-
this._currentTargetDresser = this.res.BASE_SELF_ASSIGNED;
113-
this._currentTargetDrawer = this.res.BUCKETS_SELF_ASSIGNED;
118+
if (this.dataSource === 'planner') {
119+
this._currentTargetDresser = this.initialId || this.res.BASE_SELF_ASSIGNED;
120+
this._currentTargetDrawer = this.initialBucketId || this.res.BUCKETS_SELF_ASSIGNED;
121+
} else if (this.dataSource === 'todo') {
122+
this._currentTargetDresser = this.res.BASE_SELF_ASSIGNED;
123+
this._currentTargetDrawer = this.initialId || this.res.BUCKETS_SELF_ASSIGNED;
124+
}
125+
114126
this._newTaskSelfAssigned = false;
115127
this._newTaskDrawerId = '';
116128
this._newTaskDresserId = '';
117129
this._newTaskDueDate = '';
118130
this._newTaskName = '';
119131
this._newTaskBeingAdded = false;
132+
120133
this._tasks = [];
121134
this._drawers = [];
122135
this._dressers = [];
136+
123137
this.loadTasks();
124138
}
125139
}
@@ -129,7 +143,7 @@ export class MgtTasks extends LitElement {
129143
Providers.onProviderUpdated(() => this.loadTasks());
130144
}
131145

132-
private async loadTasks() {
146+
public async loadTasks() {
133147
let ts = this.getTaskSource();
134148
if (!ts) return;
135149

@@ -150,7 +164,7 @@ export class MgtTasks extends LitElement {
150164
this._drawers = drawers;
151165
this._dressers = dressers;
152166

153-
this._currentTargetDresser = drawers[0].id;
167+
this._currentTargetDresser = this.res.BASE_SELF_ASSIGNED;
154168
this._currentTargetDrawer = this.targetId;
155169
} else {
156170
let dresser = await ts.getSingleDresser(this.targetId);
@@ -173,8 +187,10 @@ export class MgtTasks extends LitElement {
173187
[]
174188
);
175189

176-
let defaultDrawer = drawers.find(d => (d._raw as OutlookTaskFolder).isDefaultFolder);
177-
if (defaultDrawer) this._currentTargetDrawer = defaultDrawer.id;
190+
if (!this.initialId) {
191+
let defaultDrawer = drawers.find(d => (d._raw as OutlookTaskFolder).isDefaultFolder);
192+
if (defaultDrawer) this._currentTargetDrawer = defaultDrawer.id;
193+
}
178194

179195
let tasks = (await Promise.all(
180196
drawers.map(drawer => ts.getAllTasksForDrawer(drawer.id, drawer.parentId))

0 commit comments

Comments
 (0)