card.ts
TLDR
This file defines a card type that extends the Block
type. It provides a function to create a card object.
Methods
createCard
This method creates a Card
object based on a provided Block
object. It initializes the contentOrder
field, merging the input Block
's contentOrder
with an empty array. It also sets the icon
, properties
, and isTemplate
fields based on the input Block
. The resulting Card
object is returned.
Classes
// 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}