mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-08 03:10:26 +00:00
refactor(run-files): extract commit picker options
This commit is contained in:
parent
010828ae7a
commit
705ea0268a
3 changed files with 42 additions and 37 deletions
|
|
@ -1,13 +1,15 @@
|
|||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import {
|
||||
buildRunCommitOptions,
|
||||
deepLinkToastMessage,
|
||||
emptyTransitionToastMessage,
|
||||
extractRequestId,
|
||||
fabroGeneratedCommitStage,
|
||||
normalizeRunFileScope,
|
||||
} from "./run-files";
|
||||
import {
|
||||
buildRunCommitOptions,
|
||||
fabroGeneratedCommitStage,
|
||||
} from "./run-files/commit-options";
|
||||
|
||||
function buildRunFilesPayload({
|
||||
files = [],
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import { useToast } from "../components/toast";
|
|||
import type {
|
||||
FileDiff as ApiFileDiff,
|
||||
PaginatedRunFileList,
|
||||
RunCommit,
|
||||
} from "@qltysh/fabro-api-client";
|
||||
import {
|
||||
DegradedBanner,
|
||||
|
|
@ -37,11 +36,11 @@ import {
|
|||
import { useFileKeyboardNav } from "./run-files/keyboard";
|
||||
import {
|
||||
Toolbar,
|
||||
type DiffCommitOption,
|
||||
type DiffPickerValue,
|
||||
type DiffStyle,
|
||||
} from "./run-files/toolbar";
|
||||
import { fileCacheKey, stringHash } from "./run-files/cache-keys";
|
||||
import { buildRunCommitOptions } from "./run-files/commit-options";
|
||||
import { VirtualizedDiffList } from "./run-files/virtualized-diff-list";
|
||||
import { ApiError, extractRequestId } from "../lib/api-client";
|
||||
import { useRun, useRunCommits, useRunFiles } from "../lib/queries";
|
||||
|
|
@ -77,39 +76,6 @@ export function normalizeRunFileScope(value: string | null): RunFileScope {
|
|||
return "committed";
|
||||
}
|
||||
|
||||
export function fabroGeneratedCommitStage(subject: string): string | null {
|
||||
const match = subject.match(/^fabro\([^)]+\):\s+(.+?)\s+\([^)]+\)$/);
|
||||
const stage = match?.[1]?.trim();
|
||||
return stage ? stage : null;
|
||||
}
|
||||
|
||||
export type RunCommitPickerOption = DiffCommitOption & {
|
||||
fromSha: string | null;
|
||||
toSha: string;
|
||||
};
|
||||
|
||||
export function buildRunCommitOptions(
|
||||
commits: Pick<RunCommit, "sha" | "short_sha" | "subject" | "parents">[],
|
||||
): RunCommitPickerOption[] {
|
||||
const generatedVisits = new Map<string, number>();
|
||||
return commits.map((commit) => {
|
||||
const stage = fabroGeneratedCommitStage(commit.subject);
|
||||
let label = commit.subject || commit.short_sha;
|
||||
if (stage) {
|
||||
const visit = (generatedVisits.get(stage) ?? 0) + 1;
|
||||
generatedVisits.set(stage, visit);
|
||||
label = `${stage}@${visit}`;
|
||||
}
|
||||
return {
|
||||
sha: commit.sha,
|
||||
fromSha: commit.parents[0]?.sha ?? null,
|
||||
toSha: commit.sha,
|
||||
label,
|
||||
title: `${commit.short_sha} ${commit.subject}`.trim(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function useNarrowViewport(): boolean {
|
||||
const [narrow, setNarrow] = useState(() => {
|
||||
if (typeof window === "undefined") return false;
|
||||
|
|
|
|||
37
apps/fabro-web/app/routes/run-files/commit-options.ts
Normal file
37
apps/fabro-web/app/routes/run-files/commit-options.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import type { RunCommit } from "@qltysh/fabro-api-client";
|
||||
|
||||
export type RunCommitPickerOption = {
|
||||
sha: string;
|
||||
label: string;
|
||||
title: string;
|
||||
fromSha: string | null;
|
||||
toSha: string;
|
||||
};
|
||||
|
||||
export function fabroGeneratedCommitStage(subject: string): string | null {
|
||||
const match = subject.match(/^fabro\([^)]+\):\s+(.+?)\s+\([^)]+\)$/);
|
||||
const stage = match?.[1]?.trim();
|
||||
return stage ? stage : null;
|
||||
}
|
||||
|
||||
export function buildRunCommitOptions(
|
||||
commits: Pick<RunCommit, "sha" | "short_sha" | "subject" | "parents">[],
|
||||
): RunCommitPickerOption[] {
|
||||
const generatedVisits = new Map<string, number>();
|
||||
return commits.map((commit) => {
|
||||
const stage = fabroGeneratedCommitStage(commit.subject);
|
||||
let label = commit.subject || commit.short_sha;
|
||||
if (stage) {
|
||||
const visit = (generatedVisits.get(stage) ?? 0) + 1;
|
||||
generatedVisits.set(stage, visit);
|
||||
label = `${stage}@${visit}`;
|
||||
}
|
||||
return {
|
||||
sha: commit.sha,
|
||||
fromSha: commit.parents[0]?.sha ?? null,
|
||||
toSha: commit.sha,
|
||||
label,
|
||||
title: `${commit.short_sha} ${commit.subject}`.trim(),
|
||||
};
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue