Skip to content

Commit de1dd5f

Browse files
feat: Add option to export labels (#217)
1 parent 10a6e66 commit de1dd5f

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ export enum Options {
3131
SECTION = 'Section',
3232
ASSIGNEE = 'Assignee',
3333
CREATED_DATE = 'Created date',
34+
LABELS = 'Labels',
3435
}

src/services/adaptive-card.service.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
} from '@doist/ui-extensions-server'
3232

3333
import { Injectable } from '@nestjs/common'
34-
import { chunk } from 'lodash'
3534

3635
import { CardActions as SheetsCardActions } from '../constants/card-actions'
3736
import { Options, Sheets } from '../i18n/en'
@@ -66,6 +65,7 @@ const optionsTranslationKeys: OptionsKeys = {
6665
priority: Options.PRIORITY,
6766
parentTask: Options.PARENT_TASK,
6867
section: Options.SECTION,
68+
labels: Options.LABELS,
6969
}
7070

7171
@Injectable()
@@ -297,13 +297,15 @@ export class AdaptiveCardService extends AdaptiveCardServiceBase {
297297
}),
298298
)
299299

300-
const [leftColumnItems, rightColumnItems] = chunk(
301-
toggleSwitches,
302-
(toggleSwitches.length / 2) | 0,
303-
)
300+
// Calculate the midpoint
301+
const midIndex = Math.ceil(toggleSwitches.length / 2)
302+
303+
// Split into two approximately equal parts
304+
const leftColumnItems = toggleSwitches.slice(0, midIndex)
305+
const rightColumnItems = toggleSwitches.slice(midIndex)
304306

305-
leftColumnItems?.forEach((item) => leftColumn.addItem(item))
306-
rightColumnItems?.forEach((item) => rightColumn.addItem(item))
307+
leftColumnItems.forEach((item) => leftColumn.addItem(item))
308+
rightColumnItems.forEach((item) => rightColumn.addItem(item))
307309

308310
columns.addColumn(leftColumn)
309311
columns.addColumn(rightColumn)

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const ExportOptionsNames = [
1616
'section',
1717
'assignee',
1818
'createdDate',
19+
'labels',
1920
] as const
2021

2122
export const NonOptionalExportOptionsNames = [

src/utils/csv-helpers.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('CSV Helpers', () => {
1818

1919
expect(result).toEqual(
2020
toCustomCSV(
21-
'taskId,taskName,sectionId,parentTaskId,completed,due,priority,description,parentTask,section,assignee,createdDate',
21+
'taskId,taskName,sectionId,parentTaskId,completed,due,priority,description,parentTask,section,assignee,createdDate,labels',
2222
),
2323
)
2424
})
@@ -36,6 +36,7 @@ describe('CSV Helpers', () => {
3636
assignee: false,
3737
createdDate: false,
3838
includeCompleted: false,
39+
labels: false,
3940
},
4041
})
4142
expect(result).toEqual(toCustomCSV('taskId,taskName,sectionId,parentTaskId'))
@@ -54,6 +55,7 @@ describe('CSV Helpers', () => {
5455
assignee: false,
5556
createdDate: false,
5657
includeCompleted: false,
58+
labels: false,
5759
},
5860
})
5961

@@ -75,6 +77,7 @@ describe('CSV Helpers', () => {
7577
assignee: false,
7678
createdDate: false,
7779
includeCompleted: true,
80+
labels: false,
7881
},
7982
})
8083

@@ -102,6 +105,7 @@ describe('CSV Helpers', () => {
102105
description: 'This is a description',
103106
createdAt: new Date(2022, 7, 5).toISOString(),
104107
assigneeId: '12345',
108+
labels: ['label1', 'label2'],
105109
},
106110
}),
107111
completedAt: new Date(2022, 7, 6).toISOString(),
@@ -129,7 +133,7 @@ describe('CSV Helpers', () => {
129133

130134
expect(rows[1]).toEqual(
131135
toCustomCSV(
132-
'10000001,My awesome task,1234,,false,2022-08-09,1,This is a description,,My awesome section,Lukas Frito (12345),2022-08-05T00:00:00.000Z,2022-08-06T00:00:00.000Z',
136+
'10000001,My awesome task,1234,,false,2022-08-09,1,This is a description,,My awesome section,Lukas Frito (12345),2022-08-05T00:00:00.000Z,label1; label2,2022-08-06T00:00:00.000Z',
133137
),
134138
)
135139
})
@@ -170,7 +174,7 @@ describe('CSV Helpers', () => {
170174

171175
expect(rows[1]).toEqual(
172176
toCustomCSV(
173-
'10000001,My awesome task,1234,,false,2022-08-09,1,,Lukas Frito (12345),2022-08-05T00:00:00.000Z',
177+
'10000001,My awesome task,1234,,false,2022-08-09,1,,Lukas Frito (12345),2022-08-05T00:00:00.000Z,',
174178
),
175179
)
176180
})
@@ -213,7 +217,7 @@ describe('CSV Helpers', () => {
213217

214218
expect(rows[1]).toEqual(
215219
toCustomCSV(
216-
'10000001,My awesome task On two lines,1234,,false,2022-08-09,3,This is a description Also on two lines,,My awesome section,Lukas Frito (12345),2022-08-05T00:00:00.000Z',
220+
'10000001,My awesome task On two lines,1234,,false,2022-08-09,3,This is a description Also on two lines,,My awesome section,Lukas Frito (12345),2022-08-05T00:00:00.000Z,',
217221
),
218222
)
219223
})
@@ -255,7 +259,7 @@ describe('CSV Helpers', () => {
255259
const rows = result.split('\n')
256260

257261
expect(rows[1]).toEqual(
258-
'10000001...---...My awesome task, but with a comma...---...1234...---......---...false...---...2022-08-09...---...1...---...This is a description Also on two lines...---......---...My awesome section...---...Lukas Frito (12345)...---...2022-08-05T00:00:00.000Z',
262+
'10000001...---...My awesome task, but with a comma...---...1234...---......---...false...---...2022-08-09...---...1...---...This is a description Also on two lines...---......---...My awesome section...---...Lukas Frito (12345)...---...2022-08-05T00:00:00.000Z...---...',
259263
)
260264
})
261265
})

src/utils/csv-helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ function createTaskRow({ task, exportOptions, tasks, collaborators, sections }:
114114
case 'createdDate':
115115
items.push(task.createdAt)
116116
break
117+
case 'labels':
118+
items.push(task.labels.join('; '))
119+
break
117120
}
118121
})
119122

test/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const buildOptions = build<ExportOptionsToUse>('ExportOptionsToUse', {
3131
section: true,
3232
createdDate: true,
3333
includeCompleted: false,
34+
labels: true,
3435
},
3536
})
3637

0 commit comments

Comments
 (0)