Andrey Epifancev 8062dc7668 Веб: «Связи» на /app/jira/links, условные пункты меню (#108)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 19:41:32 +04:00

29 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// состояние окна карточки в записи истории (design 10–12): страница под окном, сколько записей заняли карточки
// поверх неё, открыто ли окно прямым адресом
export interface Background { pathname: string; search: string }
export interface CardState { background: Background; depth: number; direct: boolean }
export const ISSUES_PATH = "/jira/issues";
// список под окном карточки по прямому адресу: проект берётся из адреса карточки, чтобы список и закрытие остались в нём
export function listBackground(cardSearch: string): Background {
const project = new URLSearchParams(cardSearch).get("project");
return { pathname: ISSUES_PATH, search: project ? "?" + new URLSearchParams({ project }).toString() : "" };
}
// доска не хранит состояние в адресе: «ⓘ» всегда открывает окно поверх /jira/links
export const BOARD_CARD_STATE: CardState = { background: { pathname: "/jira/links", search: "" }, depth: 1, direct: false };
export function cardState(s: unknown): CardState | null {
const c = s as { background?: { pathname?: unknown; search?: unknown }; depth?: unknown; direct?: unknown } | null;
if (!c || typeof c !== "object" || !c.background || typeof c.background !== "object") return null;
const { pathname, search } = c.background;
if (typeof pathname !== "string" || typeof search !== "string" || typeof c.depth !== "number") return null;
const depth = Number.isInteger(c.depth) && c.depth >= 0 ? c.depth : 0; // NaN, дробные и отрицательные не доходят до navigate(-depth)
return { background: { pathname, search }, depth, direct: c.direct === true };
}
// state ссылки на карточку: со страницы — фон = её адрес, глубина 1; из окна — тот же фон, глубина + 1
export function openCardState(loc: { pathname: string; search: string; state: unknown }): CardState {
const cur = cardState(loc.state);
return cur ? { ...cur, depth: cur.depth + 1 } : { background: { pathname: loc.pathname, search: loc.search }, depth: 1, direct: false };
}