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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix: Add forward slash in generated url for ask-in-slack
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix: Remove ask-in-slack bubble on page navigation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix: Remove ask-in-slack `content-type` from `POST` request to simplify CORS
4 changes: 4 additions & 0 deletions znai-docs/znai/release-notes/2025.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.78.1

:include-markdowns: 1.78.1

# 1.78

:include-markdowns: 1.78
Expand Down
28 changes: 23 additions & 5 deletions znai-reactjs/src/doc-elements/text-selection/HighlightUrlText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import { useEffect, useRef } from "react";
import { TextHighlighter } from "./textHighlihter";
import { mainPanelClassName } from "../../layout/classNames";
import { extractHighlightParams } from "./highlightUrl";
import { documentationNavigation } from "../../structure/DocumentationNavigation";
import "./HighlightUrlText.css";

export function HighlightUrlText({ containerNode }: { containerNode: HTMLDivElement }) {
const bubbleRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const params = extractHighlightParams();
let highlighter: TextHighlighter | null = null;

if (params) {
const container = document.querySelector(mainPanelClassName) || document.body;
const highlighter = new TextHighlighter(container);
highlighter = new TextHighlighter(container);
const highlights = highlighter.highlight(params.selection, params.prefix, params.suffix);
const firstHighlightedElement = highlights[0];
if (!firstHighlightedElement) {
Expand All @@ -42,14 +44,16 @@ export function HighlightUrlText({ containerNode }: { containerNode: HTMLDivElem
range.setEnd(highlights[highlights.length - 1], highlights[highlights.length - 1].childNodes.length);
const selectionRect = range.getBoundingClientRect();

const bubbleText = params.question.endsWith("/")
? params.question.substring(0, params.question.length - 1)
: params.question;
const bubble = bubbleRef.current;
bubble.innerText = params.question;
bubble.innerText = bubbleText;
bubble.style.display = "block";

// Measure bubble dimensions after setting content

const bubbleRect = bubble.getBoundingClientRect();
const bubbleWidth = bubbleRect.width;

const top = selectionRect.top - containerRect.top + containerNode.scrollTop - 60;
const selectionCenter = selectionRect.left + selectionRect.width / 2.0;
const left = selectionCenter - bubbleWidth / 2.0 - containerRect.left;
Expand All @@ -64,6 +68,20 @@ export function HighlightUrlText({ containerNode }: { containerNode: HTMLDivElem
}
}, 100);
}

const urlChangeListener = () => {
if (bubbleRef.current) {
bubbleRef.current.style.display = "none";
}
if (highlighter) {
highlighter.clearHighlights();
}
};

documentationNavigation.addUrlChangeListener(urlChangeListener);
return () => {
documentationNavigation.removeUrlChangeListener(urlChangeListener);
};
}, []);

return <div ref={bubbleRef} className="znai-highlight-question-bubble" />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function TextSelectionMenu({ containerNode }: { containerNode: HTMLDivEle

async function generateLink() {
const comment = linkCommentInputRef.current?.value?.trim();
const pageUrl = buildHighlightUrl(location.toString(), panelData!.prefixSuffixMatch, comment);
const pageUrl = buildHighlightUrl(panelData!.prefixSuffixMatch, comment);
try {
await navigator.clipboard.writeText(pageUrl);
setNotification({ type: "success", message: "Link is generated and copied to clipboard" });
Expand All @@ -213,7 +213,7 @@ export function TextSelectionMenu({ containerNode }: { containerNode: HTMLDivEle
return;
}

const pageUrl = buildHighlightUrl(location.toString(), panelData!.prefixSuffixMatch, question);
const pageUrl = buildHighlightUrl(panelData!.prefixSuffixMatch, question);

const body = {
selectedText: panelData!.prefixSuffixMatch.selection,
Expand All @@ -227,9 +227,6 @@ export function TextSelectionMenu({ containerNode }: { containerNode: HTMLDivEle
try {
const response = await fetch(getDocMeta().sendToSlackUrl!, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify(body),
});
Expand Down
10 changes: 8 additions & 2 deletions znai-reactjs/src/doc-elements/text-selection/highlightUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ export function extractHighlightParams(): HighlightParams | null {
return null;
}

export function buildHighlightUrl(baseUrl: string, params: HighlightParams, question?: string): string {
const url = new URL(baseUrl);
export function buildHighlightUrl(params: HighlightParams, question?: string): string {
let builtUrl = location.origin + location.pathname;
if (!builtUrl.endsWith("/")) {
builtUrl += "/";
}

const url = new URL(builtUrl);
url.searchParams.set(HIGHLIGHT_PREFIX_PARAM, encodeURIComponent(params.prefix));
url.searchParams.set(HIGHLIGHT_SELECTION_PARAM, encodeURIComponent(params.selection));
url.searchParams.set(HIGHLIGHT_SUFFIX_PARAM, encodeURIComponent(params.suffix));
if (question) {
url.searchParams.set(HIGHLIGHT_QUESTION_PARAM, encodeURIComponent(question));
}

return url.toString();
}