Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update text editor link preview story to prevent previews being added on focus #6387

Merged
merged 2 commits into from
Oct 26, 2023
Merged
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
25 changes: 14 additions & 11 deletions src/components/text-editor/text-editor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,25 @@ export const WithLinkPreviews = () => {
const [value, setValue] = useState(
EditorState.createWithContent(ContentState.createFromText("www.sage.com"))
);
const firstRender = useRef(false);
const previews = useRef<React.JSX.Element[]>([]);
const removeUrl = (reportedUrl: string | undefined) => {
previews.current = previews.current.filter(
(preview) => reportedUrl !== preview.props.url
);
};
previews.current.push(
<EditorLinkPreview
onClose={(urlString) => removeUrl(urlString)}
title="This is an example of a title"
url="https://www.sage.com"
description="Captain, why are we out here chasing comets? I'd like to think that I haven't changed those things, sir. Computer, lights up! Not if I weaken first. Damage report! Yesterday I did not know how to eat gagh. The Federation's gone; the Borg is everywhere! We know you're dealing in stolen ore. But I wanna talk about the assassination attempt on Lieutenant Worf. Our neural pathways have become accustomed to your sensory input patterns. Wouldn't that bring about chaos?"
key="key - 1"
/>
);
if (!firstRender.current) {
firstRender.current = true;
previews.current.push(
<EditorLinkPreview
onClose={(urlString) => removeUrl(urlString)}
title="This is an example of a title"
url="https://www.sage.com"
description="Captain, why are we out here chasing comets? I'd like to think that I haven't changed those things, sir. Computer, lights up! Not if I weaken first. Damage report! Yesterday I did not know how to eat gagh. The Federation's gone; the Borg is everywhere! We know you're dealing in stolen ore. But I wanna talk about the assassination attempt on Lieutenant Worf. Our neural pathways have become accustomed to your sensory input patterns. Wouldn't that bring about chaos?"
key="key - 1"
/>
);
}
const checkValidDomain = (url: string) => {
const domainsWhitelist = [".com", ".co.uk", ".org", ".net"];
const result = domainsWhitelist.filter((domain) => url.endsWith(domain))
Expand All @@ -228,8 +232,7 @@ export const WithLinkPreviews = () => {
};
const addUrl = (reportedUrl: string) => {
if (
!previews.current.filter((preview) => reportedUrl === preview.props.url)
.length &&
!previews.current.some((preview) => reportedUrl === preview.props.url) &&
checkValidDomain(reportedUrl)
) {
const previewConfig = {
Expand Down