All files / apps/developer-portal/layers/workflows/app/components WorkflowActivityStrip.vue

93.54% Statements 29/31
80% Branches 12/15
91.66% Functions 11/12
96% Lines 24/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113  5x         3x 3x       3x 8x         8x                     8x                                     4x   4x     4x 4x     4x 4x 5x       4x 5x           4x 8x 8x   8x       4x 8x       16x   16x                                                        
<template>
    <figure class="flex max-w-sm flex-col gap-1">
        <figcaption
            class="flex flex-wrap items-baseline justify-between gap-x-4 text-xs text-dimmed"
            :title="$t('workflowActivityStrip.tooltip')"
        >
            <span class="font-semibold text-muted">{{ $t("workflowActivityStrip.title") }}</span>
            <span class="tabular-nums">{{ lastCommit }}</span>
        </figcaption>
 
        <div ref="track" class="overflow-x-auto">
            <ol class="flex h-6 w-max items-end gap-px">
                <li
                    v-for="column in columns"
                    :key="column.day"
                    class="flex h-full w-1.5 shrink-0 flex-col-reverse"
                >
                    <span
                        v-for="segment in column.segments"
                        :key="segment.stage"
                        class="segment w-full first:rounded-b-xs last:rounded-t-xs"
                        :style="{ height: `${segment.share}%`, background: segment.color }"
                        :title="segment.label"
                    />
                </li>
            </ol>
 
            <ol class="flex w-max gap-px pt-1 text-xs text-dimmed" aria-hidden="true">
                <li v-for="column in columns" :key="column.day" class="w-1.5 shrink-0">
                    <span v-if="column.month" class="whitespace-nowrap">{{ column.month }}</span>
                </li>
            </ol>
        </div>
    </figure>
</template>
 
<script setup lang="ts">
import type { ProjectActivity } from "#layers/workflows/app/utils/workflowActivity.ts";
import type { StageView } from "#layers/workflows/shared/workflows.ts";
 
interface Props {
    activity: ProjectActivity;
    stages: StageView[];
}
 
const { activity, stages } = defineProps<Props>();
 
const { t } = useI18n();
 
const track = useTemplateRef("track");
 
/** Days keep a fixed width, so a timeline longer than the strip scrolls and opens on its latest day. */
const showLatest = (): void => {
    Eif (track.value) track.value.scrollLeft = track.value.scrollWidth;
};
 
onMounted(showLatest);
watch(
    () => activity.days.length,
    () => nextTick(showLatest),
);
 
const lastCommit = computed(() =>
    activity.lastDay
        ? t("workflowActivityStrip.lastCommit", { day: calendarDay(activity.lastDay) })
        : t("workflowActivityStrip.noCommits"),
);
 
/** A month gets a label on its first day, or at the start when at least a week of it is shown. */
const labelsMonth = (day: string, index: number): boolean => {
    Iif (day.endsWith("-01")) return true;
    if (index !== 0) return false;
 
    return activity.days.slice(0, 7).every((next) => next.slice(0, 7) === day.slice(0, 7));
};
 
/** Segments stack bottom to top in stage order, so a day's colours run the way the stages do. */
const columns = computed(() =>
    activity.days.map((day, index) => ({
        day,
        month: labelsMonth(day, index) ? calendarDay(day, "only") : null,
        segments: stages.flatMap((stage, stageIndex) => {
            const moved = activity.byStage[index]?.[stageIndex] ?? 0;
 
            return moved === 0
                ? []
                : [
                      {
                          stage: stage.id,
                          color: stageColor(stageIndex),
                          share: (moved / activity.busiest) * 100,
                          label: t("workflowActivityStrip.segment", {
                              stage: stage.title,
                              day: calendarDay(day),
                              moved: t("workflowActivityStrip.moved", moved),
                          }),
                      },
                  ];
        }),
    })),
);
</script>
 
<style scoped>
.segment {
    transition: filter 0.15s;
}
 
.segment:hover {
    filter: brightness(1.2) saturate(1.2);
}
</style>