All files / apps/developer-portal/layers/workflows/app/composables useWorkflowProject.ts

91.89% Statements 34/37
59.09% Branches 13/22
82.35% Functions 14/17
90.62% Lines 29/32

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        2x 9x 9x   9x 9x 9x   17x 9x 7x         9x 9x 9x 9x 8x         9x 8x   9x 10x 14x       9x 9x   9x                   9x 9x 1x 1x     9x                   8x 9x              
import type { SettledState } from "#layers/workflows/shared/workflows.ts";
import { projectActivity } from "#layers/workflows/app/utils/workflowActivity.ts";
 
/** One workflow project, replayable to any synced day, with the block picked across the page. */
export const useWorkflowProject = () => {
    const route = useRoute();
    const id = computed(() => String(route.params.id));
 
    const read = useWorkflows();
    const { data } = read;
    const { editable, edit } = useWorkflowEdit();
 
    const base = computed(() => data.value.projects.find(({ project }) => project.id === id.value));
    const problems = computed(() =>
        data.value.problems
            .filter(({ file }) => file.startsWith(`projects/${id.value}.`))
            .map(({ file, message }) => `${file}: ${message}`),
    );
 
    const replay = useProjectReplay(base);
    const { view, isLatest } = replay;
    const syncedActivity = computed(() => (base.value ? projectActivity(base.value) : null));
    const activity = computed(() =>
        view.value && syncedActivity.value
            ? projectActivity(view.value, syncedActivity.value)
            : null,
    );
 
    const blank = computed(
        () => view.value?.capabilities.every(({ enabled }) => !enabled) ?? false,
    );
    const titles = computed(() =>
        Object.fromEntries(
            (view.value?.capabilities ?? []).map((capability) => [capability.id, capability.title]),
        ),
    );
 
    const selection = useCapabilitySelection(view);
    const { selected, select } = selection;
 
    const settle = (settlement: { status: SettledState; note: string } | null) =>
        selected.value &&
        edit({
            action: "settle",
            project: id.value,
            block: selected.value.id,
            status: settlement?.status ?? null,
            note: settlement?.note ?? "",
        });
 
    const detailsOpen = ref(false);
    const openDetails = (capabilityId: string) => {
        select(capabilityId);
        detailsOpen.value = true;
    };
 
    return {
        id,
        base,
        problems,
        replay,
        view,
        activity,
        blank,
        titles,
        selection,
        unsorted: computed(() => (isLatest.value ? (view.value?.unsorted ?? []) : [])),
        canSettle: computed(() => editable && isLatest.value),
        settle,
        detailsOpen,
        openDetails,
        ready: read,
    };
};