Skip to content

Commit

Permalink
fixed asana import
Browse files Browse the repository at this point in the history
  • Loading branch information
wiggin77 committed Apr 1, 2022
1 parent 2d356c6 commit 9f2cf67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
21 changes: 11 additions & 10 deletions import/asana/importAsana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import minimist from 'minimist'
import {exit} from 'process'
import {ArchiveUtils} from '../util/archive'
import {Block} from '../../webapp/src/blocks/block'
import {Board} from '../../webapp/src/blocks/board'
import {IPropertyOption, IPropertyTemplate, createBoard} from '../../webapp/src/blocks/board'
import {createBoardView} from '../../webapp/src/blocks/boardView'
import {createCard} from '../../webapp/src/blocks/card'
Expand Down Expand Up @@ -49,11 +50,11 @@ function main() {
const input = JSON.parse(inputData) as Asana

// Convert
const blocks = convert(input)
const [boards, blocks] = convert(input)

// Save output
// TODO: Stream output
const outputData = ArchiveUtils.buildBlockArchive(blocks)
const outputData = ArchiveUtils.buildBlockArchive(boards, blocks)
fs.writeFileSync(outputFile, outputData)

console.log(`Exported to ${outputFile}`)
Expand Down Expand Up @@ -88,22 +89,22 @@ function getSections(input: Asana, projectId: string): Workspace[] {
return [...sectionMap.values()]
}

function convert(input: Asana): Block[] {
function convert(input: Asana): [Board[], Block[]] {
const projects = getProjects(input)
if (projects.length < 1) {
console.error('No projects found')
return []
return [[],[]]
}

// TODO: Handle multiple projects
const project = projects[0]

const boards: Board[] = []
const blocks: Block[] = []

// Board
const board = createBoard()
console.log(`Board: ${project.name}`)
board.rootId = board.id
board.title = project.name

// Convert sections (columns) to a Select property
Expand All @@ -130,14 +131,14 @@ function convert(input: Asana): Block[] {
options
}
board.cardProperties = [cardProperty]
blocks.push(board)
boards.push(board)

// Board view
const view = createBoardView()
view.title = 'Board View'
view.fields.viewType = 'board'
view.rootId = board.id
view.parentId = board.id
view.boardId = board.id
blocks.push(view)

// Cards
Expand All @@ -146,7 +147,7 @@ function convert(input: Asana): Block[] {

const outCard = createCard()
outCard.title = card.name
outCard.rootId = board.id
outCard.boardId = board.id
outCard.parentId = board.id

// Map lists to Select property options
Expand All @@ -168,8 +169,8 @@ function convert(input: Asana): Block[] {
// console.log(`\t${card.notes}`)
const text = createTextBlock()
text.title = card.notes
text.rootId = board.id
text.parentId = outCard.id
text.boardId = board.id
blocks.push(text)

outCard.fields.contentOrder = [text.id]
Expand All @@ -179,7 +180,7 @@ function convert(input: Asana): Block[] {
console.log('')
console.log(`Found ${input.data.length} card(s).`)

return blocks
return [boards, blocks]
}

function showHelp() {
Expand Down
21 changes: 19 additions & 2 deletions import/util/archive.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Block} from '../../webapp/src/blocks/block'
import {Board} from '../../webapp/src/blocks/board'

interface ArchiveHeader {
version: number
date: number
}

// This schema allows the expansion of additional line types in the future
interface ArchiveLine {
type: string,
data: unknown,
}

// This schema allows the expansion of additional line types in the future
interface BlockArchiveLine extends ArchiveLine {
type: 'block',
data: Block
}

interface BoardArchiveLine extends ArchiveLine {
type: 'board',
data: Board
}

class ArchiveUtils {
static buildBlockArchive(blocks: readonly Block[]): string {
static buildBlockArchive(boards: readonly Board[], blocks: readonly Block[]): string {
const header: ArchiveHeader = {
version: 1,
date: Date.now(),
}

const headerString = JSON.stringify(header)
let content = headerString + '\n'

for (const board of boards) {
const line: BoardArchiveLine = {
type: 'board',
data: board,
}
const lineString = JSON.stringify(line)
content += lineString
content += '\n'
}

for (const block of blocks) {
const line: BlockArchiveLine = {
type: 'block',
Expand Down

0 comments on commit 9f2cf67

Please sign in to comment.