Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 66 additions & 11 deletions src/app/components/settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -540,26 +540,44 @@ export default function SettingsPage() {

// Replace Jira API token panel
const [showReplaceJiraToken, setShowReplaceJiraToken] = createSignal(false);
const [highlightReplaceJiraToken, setHighlightReplaceJiraToken] = createSignal(false);
const [replaceJiraEmail, setReplaceJiraEmail] = createSignal("");
const [replaceJiraTokenInput, setReplaceJiraTokenInput] = createSignal("");
const [replaceJiraError, setReplaceJiraError] = createSignal<string | null>(null);
const [replaceJiraSubmitting, setReplaceJiraSubmitting] = createSignal(false);
let replaceJiraTokenInputRef: HTMLInputElement | undefined;
let replaceJiraButtonRef: HTMLButtonElement | undefined;
let replaceJiraAbortCtrl: AbortController | undefined;
let replaceJiraHighlightTimer: ReturnType<typeof setTimeout> | undefined;
let replaceJiraDeepLinkTimer: ReturnType<typeof setTimeout> | undefined;

function triggerReplaceJiraHighlight() {
clearTimeout(replaceJiraHighlightTimer);
setHighlightReplaceJiraToken(true);
replaceJiraHighlightTimer = setTimeout(() => {
setHighlightReplaceJiraToken(false);
}, 1500);
}

function openReplaceJiraTokenPanel(focusInput = true) {
setReplaceJiraEmail(jiraAuth()?.email ?? config.jira?.email ?? "");
setReplaceJiraTokenInput("");
setReplaceJiraError(null);
setShowReplaceJiraToken(true);
function openReplaceJiraTokenPanel(focusInput = true, pulse = false) {
if (!showReplaceJiraToken()) {
setReplaceJiraEmail(jiraAuth()?.email ?? config.jira?.email ?? "");
setReplaceJiraTokenInput("");
setReplaceJiraError(null);
setShowReplaceJiraToken(true);
}
if (pulse) {
triggerReplaceJiraHighlight();
}
if (focusInput) {
setTimeout(() => replaceJiraTokenInputRef?.focus(), 0);
}
}

function closeReplaceJiraTokenPanel(restoreFocus = false) {
replaceJiraAbortCtrl?.abort();
clearTimeout(replaceJiraHighlightTimer);
setHighlightReplaceJiraToken(false);
setShowReplaceJiraToken(false);
setReplaceJiraTokenInput("");
setReplaceJiraError(null);
Expand All @@ -571,7 +589,7 @@ export default function SettingsPage() {
const shouldOpenReplace =
config.jira?.authMethod === "token" && (isJiraAuthenticated() || Boolean(config.jira?.enabled));
if (shouldOpenReplace) {
openReplaceJiraTokenPanel(false);
openReplaceJiraTokenPanel(false, true);
}
setTimeout(() => {
document.getElementById("jira")?.scrollIntoView?.({ behavior: "smooth", block: "start" });
Expand All @@ -581,15 +599,31 @@ export default function SettingsPage() {
}, 0);
}

function handleJiraDeepLinkClick(e: MouseEvent) {
const target = e.target as Element | null;
if (target?.closest?.('a[href="/settings#jira"]')) {
clearTimeout(replaceJiraDeepLinkTimer);
replaceJiraDeepLinkTimer = setTimeout(handleJiraDeepLink, 0);
}
}

onMount(() => {
handleJiraDeepLink();
// @solidjs/router commits window.history.pushState in a .finally() microtask
// after mounting the route component on SPA link clicks (<a href="/settings#jira">),
// so re-check on the next macrotask once window.location.hash has settled.
replaceJiraDeepLinkTimer = setTimeout(handleJiraDeepLink, 0);
window.addEventListener("hashchange", handleJiraDeepLink);
document.addEventListener("click", handleJiraDeepLinkClick);
});

onCleanup(() => {
replaceJiraAbortCtrl?.abort();
clearTimeout(replaceJiraHighlightTimer);
clearTimeout(replaceJiraDeepLinkTimer);
if (typeof window !== "undefined") {
window.removeEventListener("hashchange", handleJiraDeepLink);
document.removeEventListener("click", handleJiraDeepLinkClick);
}
});

Expand Down Expand Up @@ -1572,6 +1606,15 @@ export default function SettingsPage() {
? "Your Jira API token has expired or is invalid. Replace your token below to resume syncing — all your Jira settings are preserved."
: "Your Jira OAuth session has expired. Reconnect below to resume syncing — all your Jira settings are preserved."}
</span>
<Show when={config.jira?.authMethod === "token" && !showReplaceJiraToken()}>
<button
type="button"
onClick={() => openReplaceJiraTokenPanel(true, true)}
class="btn btn-xs btn-neutral shrink-0"
>
Replace token
</button>
</Show>
<Show when={config.jira?.authMethod !== "token" && jiraEnabled}>
<button
type="button"
Expand Down Expand Up @@ -1601,12 +1644,12 @@ export default function SettingsPage() {
type="button"
onClick={() => {
if (!showReplaceJiraToken()) {
openReplaceJiraTokenPanel();
openReplaceJiraTokenPanel(true, true);
} else {
closeReplaceJiraTokenPanel(false);
}
}}
class="btn btn-xs btn-outline"
class={isJiraAuthenticated() ? "btn btn-xs btn-outline" : "btn btn-xs btn-warning"}
aria-expanded={showReplaceJiraToken()}
aria-controls="replace-jira-token-panel"
>
Expand All @@ -1616,14 +1659,26 @@ export default function SettingsPage() {
</div>
</SettingRow>
<Show when={showReplaceJiraToken()}>
<div id="replace-jira-token-panel" class="px-4 py-3 border-b border-base-300 flex flex-col gap-2">
<p class="text-xs text-base-content/60">
<div
id="replace-jira-token-panel"
class={`mx-4 my-3 p-4 rounded-lg border-2 shadow-sm flex flex-col gap-2.5 transition-shadow ${
isJiraAuthenticated()
? "border-primary/40 bg-primary/5"
: "border-warning/60 bg-warning/10"
}${highlightReplaceJiraToken() ? " animate-reorder-highlight ring-2 ring-warning" : ""}`}
>
<div class="flex items-center justify-between">
<span class="text-xs font-semibold text-base-content">
Replace Jira API Token
</span>
</div>
<p class="text-xs text-base-content/70">
Generate a new token at{" "}
<a
href="https://id.atlassian.com/manage-profile/security/api-tokens"
target="_blank"
rel="noopener noreferrer"
class="link link-primary"
class="link link-primary font-medium"
>
Atlassian API tokens
</a>{" "}
Expand Down
27 changes: 24 additions & 3 deletions tests/components/settings/JiraSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,20 @@ describe("SettingsPage Jira section — preserved settings when expired", () =>
const configureScopesBtn = screen.getByRole("button", { name: /Configure filter scopes/i }) as HTMLButtonElement;
expect(configureFieldsBtn.disabled).toBe(true);
expect(configureScopesBtn.disabled).toBe(true);

// Replace button on Auth method row uses warning highlight style when expired
const replaceBtn = screen.getByRole("button", { name: /^Replace$/i });
expect(replaceBtn.className).toContain("btn-warning");

// Expired banner also renders a direct "Replace token" CTA button while the panel is closed
const banner = screen.getByTestId("jira-settings-expired-banner");
const bannerReplaceBtn = banner.querySelector("button");
expect(bannerReplaceBtn?.textContent).toBe("Replace token");
fireEvent.click(bannerReplaceBtn!);

const panel = document.getElementById("replace-jira-token-panel");
expect(panel).not.toBeNull();
expect(panel?.className).toContain("ring-warning");
});

it("shows Reconnect button in expired banner when authMethod is oauth", async () => {
Expand Down Expand Up @@ -962,15 +976,22 @@ describe("SettingsPage Jira section — Replace API token flow & deep-linking",
expect(mockSetJiraAuth).not.toHaveBeenCalled();
});

it("auto-opens #replace-jira-token-panel and focuses New Atlassian API token input when window.location.hash is '#jira' on mount", async () => {
it("auto-opens #replace-jira-token-panel, applies highlight pulse, and focuses New Atlassian API token input when window.location.hash is '#jira' on mount (or settles on microtask after mount)", async () => {
mockIsJiraAuthenticated.mockReturnValue(false);
mockJiraAuth.mockReturnValue(null);
window.location.hash = "#jira";
// Simulate @solidjs/router committing history.pushState('#jira') in a microtask right after onMount
window.location.hash = "";

renderSettings();
queueMicrotask(() => {
window.location.hash = "#jira";
});

await waitFor(() => {
expect(document.getElementById("replace-jira-token-panel")).not.toBeNull();
const panel = document.getElementById("replace-jira-token-panel");
expect(panel).not.toBeNull();
expect(panel?.className).toContain("animate-reorder-highlight");
expect(panel?.className).toContain("ring-warning");
const tokenInput = screen.getByLabelText("New Atlassian API token");
expect(document.activeElement).toBe(tokenInput);
});
Expand Down
Loading