8.7 KiB · text History 905ae26
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC2
import org.kde.plasma.components as PlasmaComponents3
import org.kde.kirigami as Kirigami

import "Vigil.js" as Vigil

// One unresolved issue as the web's list row: level, title, culprit,
// events, users, last seen and project. Click to open its latest event
// (exception, top in-app frames, last breadcrumbs) and the triage row.
ColumnLayout {
    id: issueItem

    required property var store
    required property var issue

    readonly property string key: Vigil.issueKey(issue)
    readonly property bool expanded: store.expandedKey === key
    readonly property bool busy: store.pending[key] === true
    readonly property bool settled: issue.status !== "unresolved"
    readonly property bool showProject: store.watchedProjects.length !== 1
    readonly property bool regressed: !!store.regressedAt[key]
    readonly property bool fresh: !regressed && Vigil.within(issue.firstSeen, store.now, store.recentHours)

    spacing: 0

    PlasmaComponents3.ItemDelegate {
        id: header
        Layout.fillWidth: true
        topPadding: Kirigami.Units.smallSpacing
        bottomPadding: Kirigami.Units.smallSpacing
        highlighted: issueItem.expanded
        onClicked: issueItem.store.toggleIssue(issueItem.issue)

        TapHandler {
            acceptedButtons: Qt.RightButton
            onTapped: menu.popup()
        }

        PlasmaComponents3.Menu {
            id: menu

            PlasmaComponents3.MenuItem {
                icon.name: "internet-web-browser"
                text: i18n("Open in Browser")
                onClicked: Qt.openUrlExternally(issueItem.issue.permalink)
            }

            PlasmaComponents3.MenuItem {
                icon.name: "edit-copy"
                text: i18n("Copy Link")
                onClicked: {
                    clipHelper.text = issueItem.issue.permalink
                    clipHelper.selectAll()
                    clipHelper.copy()
                }
            }
        }

        // Clipboard by way of a hidden text field: QML has no clipboard API.
        TextEdit { id: clipHelper; visible: false }

        contentItem: ColumnLayout {
            spacing: 2

            RowLayout {
                Layout.fillWidth: true
                spacing: Kirigami.Units.smallSpacing

                Pill {
                    text: Vigil.levelLabel(issueItem.issue.level)
                    pillColor: Vigil.levelColor(issueItem.issue.level)
                }

                PlasmaComponents3.Label {
                    Layout.fillWidth: true
                    text: issueItem.issue.title
                    elide: Text.ElideRight
                    font.bold: true
                    opacity: issueItem.settled ? 0.6 : 1
                    font.strikeout: issueItem.issue.status === "resolved"
                }

                // How often, and how many people.
                PlasmaComponents3.Label {
                    text: Vigil.compactCount(issueItem.issue.count)
                    font: Kirigami.Theme.smallFont
                    opacity: 0.8
                    PlasmaComponents3.ToolTip.text: i18np("%1 event", "%1 events", parseInt(issueItem.issue.count, 10) || 0)
                    PlasmaComponents3.ToolTip.visible: countHover.hovered
                    HoverHandler { id: countHover }
                }

                Kirigami.Icon {
                    source: "view-statistics"
                    Layout.preferredWidth: Kirigami.Units.iconSizes.small * 0.8
                    Layout.preferredHeight: Layout.preferredWidth
                    opacity: 0.5
                }

                PlasmaComponents3.Label {
                    visible: issueItem.issue.userCount > 0
                    text: Vigil.compactCount(issueItem.issue.userCount)
                    font: Kirigami.Theme.smallFont
                    opacity: 0.8
                }

                Kirigami.Icon {
                    visible: issueItem.issue.userCount > 0
                    source: "im-user"
                    Layout.preferredWidth: Kirigami.Units.iconSizes.small * 0.8
                    Layout.preferredHeight: Layout.preferredWidth
                    opacity: 0.5
                }
            }

            RowLayout {
                Layout.fillWidth: true
                spacing: Kirigami.Units.smallSpacing

                PlasmaComponents3.Label {
                    Layout.fillWidth: true
                    text: issueItem.issue.culprit || ""
                    elide: Text.ElideMiddle
                    font: Kirigami.Theme.smallFont
                    opacity: 0.7
                }

                PlasmaComponents3.Label {
                    visible: issueItem.regressed || issueItem.fresh || issueItem.settled
                    text: issueItem.settled ? Vigil.statusLabel(issueItem.issue).toLowerCase()
                        : issueItem.regressed ? i18n("regressed") : i18n("new")
                    font.pixelSize: Kirigami.Theme.smallFont.pixelSize
                    font.bold: true
                    color: issueItem.settled ? Vigil.statusColor(issueItem.issue)
                         : issueItem.regressed ? Vigil.colors.error : Vigil.colors.warning
                }

                PlasmaComponents3.Label {
                    visible: !!issueItem.issue.assignedTo
                    text: issueItem.store.assignedToMe(issueItem.issue) ? i18n("you") : Vigil.assigneeLabel(issueItem.issue.assignedTo)
                    font: Kirigami.Theme.smallFont
                    opacity: 0.7
                    elide: Text.ElideRight
                    Layout.maximumWidth: Kirigami.Units.gridUnit * 5
                }

                PlasmaComponents3.Label {
                    text: [issueItem.showProject ? (issueItem.issue.project.name || issueItem.issue.project.slug) : "",
                           Vigil.relativeTime(issueItem.issue.lastSeen, issueItem.store.now)]
                          .filter(function(s) { return s !== "" }).join(" · ")
                    font: Kirigami.Theme.smallFont
                    opacity: 0.7
                    PlasmaComponents3.ToolTip.text: i18n("%1 · first seen %2", issueItem.issue.shortId, Vigil.relativeTime(issueItem.issue.firstSeen, issueItem.store.now))
                    PlasmaComponents3.ToolTip.visible: seenHover.hovered
                    HoverHandler { id: seenHover }
                }
            }
        }
    }

    // ── the latest event ────────────────────────────────────────────────

    Loader {
        Layout.fillWidth: true
        Layout.leftMargin: Kirigami.Units.largeSpacing
        Layout.rightMargin: Kirigami.Units.smallSpacing
        Layout.bottomMargin: Kirigami.Units.smallSpacing
        active: issueItem.expanded
        visible: active

        sourceComponent: ColumnLayout {
            spacing: Kirigami.Units.smallSpacing

            readonly property var cached: issueItem.store.events[issueItem.key] || null

            EventDetail {
                Layout.fillWidth: true
                cached: parent.cached
            }

            // Triage, only when the token has event:write.
            Flow {
                Layout.fillWidth: true
                spacing: Kirigami.Units.smallSpacing

                Repeater {
                    model: issueItem.store.canTriage ? Vigil.triageOptions(issueItem.issue) : []
                    PlasmaComponents3.Button {
                        required property var modelData
                        text: modelData.label
                        icon.name: modelData.icon
                        enabled: !issueItem.busy
                        onClicked: issueItem.store.setStatus(issueItem.issue, modelData)
                    }
                }

                PlasmaComponents3.Button {
                    visible: issueItem.store.canTriage && !!issueItem.store.me
                    text: issueItem.store.assignedToMe(issueItem.issue) ? i18n("Unassign Me") : i18n("Assign to Me")
                    icon.name: "im-user"
                    enabled: !issueItem.busy
                    onClicked: issueItem.store.toggleAssignMe(issueItem.issue)
                }

                PlasmaComponents3.Button {
                    text: i18n("Open in Browser")
                    icon.name: "internet-web-browser"
                    onClicked: Qt.openUrlExternally(issueItem.issue.permalink)
                }

                PlasmaComponents3.BusyIndicator {
                    visible: issueItem.busy
                    width: Kirigami.Units.iconSizes.smallMedium
                    height: width
                }
            }
        }
    }

    Kirigami.Separator {
        Layout.fillWidth: true
        opacity: 0.4
    }
}