/** * Copyright (c) Cisco Systems, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import { LitElement, html, property } from "lit-element"; import { nothing } from "lit-html"; import { classMap } from "lit-html/directives/class-map"; import { DateTime } from "luxon"; import styles from "./scss/module.scss"; import { getIconData, getTimeStamp } from "./utils"; import { customElementWithCheck } from "@/mixins"; import { Timeline } from "./Timeline"; import * as iconData from "@/assets/defaultIcons.json"; import * as linkify from "linkifyjs"; export namespace TimelineItem { export type ShowcaseList = string[]; @customElementWithCheck("cjaas-timeline-item") export class ELEMENT extends LitElement { /** * @attr id */ @property({ type: String }) id = ""; /** * @attr eventTitle */ @property({ type: String, attribute: "event-title" }) eventTitle = ""; /** * @attr sub-title */ @property({ type: String, attribute: "sub-title" }) subTitle = ""; /** * @attr time */ @property({ type: String }) time = ""; /** * @prop data */ @property() data: any = null; /** * @attr person */ @property({ type: String }) person: string | null = null; /** * @attr expanded */ @property({ type: Boolean, reflect: true }) expanded = false; /** * @attr groupItem */ @property({ type: Boolean, attribute: "group-item" }) groupItem = false; /** * Property to pass in data template to set color and icon settings and showcased data * @prop eventIconTemplate */ @property({ attribute: false }) eventIconTemplate: Timeline.TimelineCustomizations = iconData; /** * @prop badgeKeyword * set badge icon based on declared keyword from dataset */ @property({ type: String, attribute: "badge-keyword" }) badgeKeyword = "channelType"; @property({ type: Boolean, attribute: "is-cluster" }) isCluster = false; @property({ type: Boolean, attribute: "is-date-cluster" }) isDateCluster = false; @property({ type: String, attribute: "group-icon-map-keyword" }) groupIconMapKeyword = ""; static get styles() { return styles; } /** * @method copyValue * @param {Event} e * Copies text to clipboard */ copyValue = (e: Event) => { /* Get the text field */ const copyText = (e.target as HTMLElement).innerText as string; /* Copy the text inside the text field */ navigator.clipboard.writeText(copyText); }; /** * @method createTableRecursive * @param data * @returns Template * Builds the timeline item's data table */ createTableRecursive(data: any): any { if (!data) { return nothing; } else { return html` ${Object.keys(data).map((x: string) => { if (typeof data[x] !== "object") { if (data[x]) { let renderValue = data[x] || "-"; if (typeof data[x] === "string" && linkify.test(data[x], "url")) { renderValue = html` ${renderValue} `; } /* eslint disable */ return html`
${dateAndTimeArray?.[0]}
${renderTimeRow}