main

mattermost/focalboard

Last updated at: 29/12/2023 09:40

card.ts

TLDR

This file card.ts contains code related to creating and exporting a Card object, along with a createCard function.

Methods

createCard

This method creates a Card object based on the provided block object. It initializes the contentOrder property of the Card object based on the contentOrder property of the block object. It sets the icon, properties, isTemplate properties of the Card object based on the corresponding properties of the block object. It finally returns the created Card object.

Classes

None

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Block, createBlock} from './block'

type CardFields = {
    icon?: string
    isTemplate?: boolean
    properties: Record<string, string | string[]>
    contentOrder: Array<string | string[]>
}

type Card = Block & {
    fields: CardFields
}

function createCard(block?: Block): Card {
    const contentOrder: Array<string|string[]> = []
    const contentIds = block?.fields?.contentOrder?.filter((id: any) => id !== null)

    if (contentIds?.length > 0) {
        for (const contentId of contentIds) {
            if (typeof contentId === 'string') {
                contentOrder.push(contentId)
            } else {
                contentOrder.push(contentId.slice())
            }
        }
    }
    return {
        ...createBlock(block),
        type: 'card',
        fields: {
            icon: block?.fields.icon || '',
            properties: {...(block?.fields.properties || {})},
            contentOrder,
            isTemplate: block?.fields.isTemplate || false,
        },
    }
}

export {Card, createCard}