sdlc-hub/web/src/issues/IssueLink.tsx

19 lines
1.1 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.

import type { ReactNode } from "react";
import { Link, useLocation, useNavigate } from "react-router";
import { openCardState } from "./modal.ts";
const cardPath = (key: string) => `/issues/${encodeURIComponent(key)}`;
// переход к карточке задачи: окно поверх текущей страницы (или смена содержимого открытого окна) — как у ссылки-ключа
export function useOpenIssue(): (key: string) => void {
const loc = useLocation();
const navigate = useNavigate();
return (key) => void navigate(cardPath(key), { state: openCardState(loc) });
}
// ссылка на карточку задачи: открывает окно поверх текущей страницы (или меняет содержимое открытого окна)
export function IssueLink({ issueKey, className, children }: { issueKey: string; className?: string; children?: ReactNode }) {
const loc = useLocation();
return <Link className={className} to={cardPath(issueKey)} state={openCardState(loc)}>{children ?? issueKey}</Link>;
}