From cdeb02f1175bcf4dce4df6dc1d3540eea2ab9de8 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Mon, 18 Sep 2023 16:09:14 +0200 Subject: [PATCH 01/13] add functionality to share faq item --- src/components/Accordion/Item.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 1d84e1d5..d2ef2a38 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -1,5 +1,6 @@ import clsx from "clsx"; -import React, { useRef } from "react"; +import { useLocation } from "@docusaurus/router"; +import React, { useEffect, useRef } from "react"; type AccordionItemProps = { children: React.ReactNode; @@ -32,6 +33,7 @@ const classNames = [ const AccordionItem = ({ summary, open, children }: AccordionItemProps) => { const detailsRef = useRef(null); + const location = useLocation(); const handleItemClick = () => { document.querySelectorAll("details.accordion-item").forEach((item) => { @@ -39,8 +41,22 @@ const AccordionItem = ({ summary, open, children }: AccordionItemProps) => { item.removeAttribute("open"); } }); + + window.location.replace(`${location.pathname}#${encodeURI(summary)}`); }; + useEffect(() => { + if (decodeURI(location.hash) === `#${summary}`) { + document.querySelectorAll("details.accordion-item").forEach((item) => { + if (item !== detailsRef.current) { + item.removeAttribute("open"); + } else { + item.setAttribute("open", "true"); + } + }); + } + }, []); + return (
Date: Mon, 18 Sep 2023 16:15:35 +0200 Subject: [PATCH 02/13] clean hash from url after close of faq item --- src/components/Accordion/Item.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index d2ef2a38..0a8fe0ae 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -42,7 +42,12 @@ const AccordionItem = ({ summary, open, children }: AccordionItemProps) => { } }); - window.location.replace(`${location.pathname}#${encodeURI(summary)}`); + if (decodeURI(location.hash) === `#${summary}`) { + // Hash at the end disables ability to open automaticaly first FAQ item + window.location.replace(`${location.pathname}#`); + } else { + window.location.replace(`${location.pathname}#${encodeURI(summary)}`); + } }; useEffect(() => { From 6e7870c9dacc6c6d648b1041ffcda6b6afc675f1 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Mon, 18 Sep 2023 16:55:00 +0200 Subject: [PATCH 03/13] simplify hashes --- faq.mdx | 10 +++++----- src/components/Accordion/Item.tsx | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/faq.mdx b/faq.mdx index 650bb1ce..99012077 100644 --- a/faq.mdx +++ b/faq.mdx @@ -1,10 +1,10 @@ - + OpenTofu is a Terraform fork, created as an initiative of Gruntwork, Spacelift, Harness, Env0, Scalr, and others, in response to HashiCorp’s switch from an open-source license to the BUSL. The initiative has many supporters, all of whom are listed [here](/supporters). - + The BUSL and the additional use grant outlined by the HashiCorp team are ambiguous, which makes it challenging for companies, vendors, and developers using Terraform to decide whether their actions could be interpreted as being outside the permitted scope of use. @@ -14,13 +14,13 @@ We firmly believe that Terraform should remain open-source because it is a proje - + There will be no differences between Terraform (versions prior to 1.5.x) and OpenTofu. As new versions are released, this will change. - + #### Personal use @@ -36,7 +36,7 @@ Companies will encounter more difficulties with the situation. Switching to a ne - + The community will decide what features OpenTofu will have. Some long-awaited Terraform features will be publicly available soon. diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 0a8fe0ae..1f0b2c31 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -7,6 +7,7 @@ type AccordionItemProps = { summary: string; open?: boolean; highlight?: boolean; + id: string; }; const classNames = [ @@ -31,10 +32,10 @@ const classNames = [ "font-normal", ]; -const AccordionItem = ({ summary, open, children }: AccordionItemProps) => { +const AccordionItem = ({ summary, open, children, id }: AccordionItemProps) => { const detailsRef = useRef(null); const location = useLocation(); - + const hashEnabled = location.pathname === "/faq"; const handleItemClick = () => { document.querySelectorAll("details.accordion-item").forEach((item) => { if (item !== detailsRef.current) { @@ -42,16 +43,20 @@ const AccordionItem = ({ summary, open, children }: AccordionItemProps) => { } }); + if (!hashEnabled) { + return; + } + if (decodeURI(location.hash) === `#${summary}`) { // Hash at the end disables ability to open automaticaly first FAQ item window.location.replace(`${location.pathname}#`); } else { - window.location.replace(`${location.pathname}#${encodeURI(summary)}`); + window.location.replace(`${location.pathname}#${encodeURI(id)}`); } }; useEffect(() => { - if (decodeURI(location.hash) === `#${summary}`) { + if (decodeURI(location.hash) === `#${id}` && hashEnabled) { document.querySelectorAll("details.accordion-item").forEach((item) => { if (item !== detailsRef.current) { item.removeAttribute("open"); From 471902a90e7ad065c417ade7a0ed163bf2cfd789 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 09:20:57 +0200 Subject: [PATCH 04/13] refactor --- src/components/Accordion/Item.tsx | 15 +++++++++++---- src/pages/faq.tsx | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 1f0b2c31..f5b7b814 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -8,6 +8,7 @@ type AccordionItemProps = { open?: boolean; highlight?: boolean; id: string; + isHashEnabled?: boolean; }; const classNames = [ @@ -32,10 +33,16 @@ const classNames = [ "font-normal", ]; -const AccordionItem = ({ summary, open, children, id }: AccordionItemProps) => { +const AccordionItem = ({ + summary, + open, + children, + id, + isHashEnabled, +}: AccordionItemProps) => { const detailsRef = useRef(null); const location = useLocation(); - const hashEnabled = location.pathname === "/faq"; + const handleItemClick = () => { document.querySelectorAll("details.accordion-item").forEach((item) => { if (item !== detailsRef.current) { @@ -43,7 +50,7 @@ const AccordionItem = ({ summary, open, children, id }: AccordionItemProps) => { } }); - if (!hashEnabled) { + if (!isHashEnabled) { return; } @@ -56,7 +63,7 @@ const AccordionItem = ({ summary, open, children, id }: AccordionItemProps) => { }; useEffect(() => { - if (decodeURI(location.hash) === `#${id}` && hashEnabled) { + if (decodeURI(location.hash) === `#${id}` && isHashEnabled) { document.querySelectorAll("details.accordion-item").forEach((item) => { if (item !== detailsRef.current) { item.removeAttribute("open"); diff --git a/src/pages/faq.tsx b/src/pages/faq.tsx index b013b4cd..fdbc236a 100644 --- a/src/pages/faq.tsx +++ b/src/pages/faq.tsx @@ -19,7 +19,9 @@ export default function FAQ() { ( + + ), a: (props) => ( ), From 7aec5d38261da0a66d0958e9160f0e4e4f2fb0ec Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 10:46:56 +0200 Subject: [PATCH 05/13] use id instead of summary --- src/components/Accordion/Item.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index f5b7b814..0a6ee0d8 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -54,7 +54,7 @@ const AccordionItem = ({ return; } - if (decodeURI(location.hash) === `#${summary}`) { + if (decodeURI(location.hash) === `#${id}`) { // Hash at the end disables ability to open automaticaly first FAQ item window.location.replace(`${location.pathname}#`); } else { From 91d4a1e0320ae2c4a8276a2d1381010b5cfb4bc0 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 12:00:10 +0200 Subject: [PATCH 06/13] stop unnecessary rerendering --- src/components/Accordion/Item.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 0a6ee0d8..32f23a7e 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -1,5 +1,6 @@ import clsx from "clsx"; import { useLocation } from "@docusaurus/router"; + import React, { useEffect, useRef } from "react"; type AccordionItemProps = { @@ -55,10 +56,13 @@ const AccordionItem = ({ } if (decodeURI(location.hash) === `#${id}`) { - // Hash at the end disables ability to open automaticaly first FAQ item - window.location.replace(`${location.pathname}#`); + window.history.replaceState({}, "", location.pathname); } else { - window.location.replace(`${location.pathname}#${encodeURI(id)}`); + window.history.replaceState( + {}, + "", + `${location.pathname}#${encodeURI(id)}` + ); } }; From 5d1f3b487ab925cc57f7bee71f8357b56bc56d60 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 12:06:42 +0200 Subject: [PATCH 07/13] use hash --- src/components/Accordion/Item.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 32f23a7e..41319623 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -55,11 +55,15 @@ const AccordionItem = ({ return; } - if (decodeURI(location.hash) === `#${id}`) { - window.history.replaceState({}, "", location.pathname); + if (window.location.hash === `#${id}`) { + window.history.replaceState( + { hash: undefined }, + "", + `${location.pathname}#` + ); } else { window.history.replaceState( - {}, + { hash: id }, "", `${location.pathname}#${encodeURI(id)}` ); From dff5b432b0e3eb147cc40b5af01364b38e5effed Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 12:19:11 +0200 Subject: [PATCH 08/13] update condition to set/remove hash --- src/components/Accordion/Item.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 41319623..4cc85ed7 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -55,12 +55,11 @@ const AccordionItem = ({ return; } - if (window.location.hash === `#${id}`) { - window.history.replaceState( - { hash: undefined }, - "", - `${location.pathname}#` - ); + if ( + detailsRef.current.hasAttribute("open") && + detailsRef.current.getAttribute("open") !== false + ) { + window.history.replaceState({ hash: undefined }, "", location.pathname); } else { window.history.replaceState( { hash: id }, From 96f8ef63220d7a977354ec5e989f8a463b700a5c Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 13:04:20 +0200 Subject: [PATCH 09/13] remove unused condition --- src/components/Accordion/Item.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 4cc85ed7..70644325 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -55,10 +55,7 @@ const AccordionItem = ({ return; } - if ( - detailsRef.current.hasAttribute("open") && - detailsRef.current.getAttribute("open") !== false - ) { + if (detailsRef.current.hasAttribute("open")) { window.history.replaceState({ hash: undefined }, "", location.pathname); } else { window.history.replaceState( From a7a72500504641b7fa2c391c2b45a455d066d0a2 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 14:05:30 +0200 Subject: [PATCH 10/13] rebase improvements --- faq.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/faq.mdx b/faq.mdx index 99012077..0058dfb0 100644 --- a/faq.mdx +++ b/faq.mdx @@ -14,7 +14,7 @@ We firmly believe that Terraform should remain open-source because it is a proje - + There will be no differences between Terraform (versions prior to 1.5.x) and OpenTofu. As new versions are released, this will change. @@ -36,7 +36,7 @@ Companies will encounter more difficulties with the situation. Switching to a ne - + The community will decide what features OpenTofu will have. Some long-awaited Terraform features will be publicly available soon. @@ -44,32 +44,32 @@ Some companies have pledged to pay for full-time engineers to work on OpenTofu. - + Initially, OpenTofu will be a drop-in replacement for Terraform, as it will be compatible with Terraform versions 1.5.x. You won’t need to make any changes to your code to ensure compatibility. OpenTofu is suitable for production use cases without any exception. - + OpenTofu will work with existing state files up to those created with a version prior to Terraform’s 1.5.x. - + OpenTofu will not have its own providers. Terraform providers have not altered their licenses, and the potential for such a change is virtually zero. OpenTofu will work with the current Terraform providers, but it will use a separate registry. - + The steering committee and the community determine the most important features and bug fixes. The large number of developers pledging their resources to help develop OpenTofu will speed up the development of features and enable faster releases than Terraform managed previously. - + The best way to show practical support for the OpenTofu initiative is to contribute. We recommend you start by [opening an issue](https://github.com/opentofu/opentofu/blob/main/CONTRIBUTING.md) for bug reports, broken compatibility reports, feature requests, old issue reposts, and quality RFCs. @@ -79,7 +79,7 @@ This [contribution guide](https://github.com/opentofu/opentofu/blob/main/CONTRIB - + The pledge is open to all individuals and companies who care about the future of Terraform. You can also support this initiative by starring the manifesto repository on GitHub and spreading the word via share buttons. From 9dc9d2e01441a7df393bc47fc83eebbb256a5183 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 14:05:44 +0200 Subject: [PATCH 11/13] scroll to opened faq --- src/components/Accordion/Item.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 70644325..7d244b77 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -72,6 +72,10 @@ const AccordionItem = ({ if (item !== detailsRef.current) { item.removeAttribute("open"); } else { + window.scrollTo({ + top: detailsRef.current.offsetTop, + behavior: "smooth", + }); item.setAttribute("open", "true"); } }); From 17f46a5d4eba310bbeeed313f6161a7c8a0249e9 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 14:28:15 +0200 Subject: [PATCH 12/13] on click scroll to --- src/components/Accordion/Item.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 7d244b77..22061eeb 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -58,6 +58,10 @@ const AccordionItem = ({ if (detailsRef.current.hasAttribute("open")) { window.history.replaceState({ hash: undefined }, "", location.pathname); } else { + // Push to end of queue to read updated position and scroll to it + setTimeout(() => { + detailsRef.current.scrollIntoView({ behavior: "smooth" }); + }); window.history.replaceState( { hash: id }, "", From f804e7cd5b10841f9b29d994de309abe4ac79145 Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Tue, 19 Sep 2023 14:43:53 +0200 Subject: [PATCH 13/13] apply faq scroll to every page --- src/components/Accordion/Item.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index 22061eeb..356f0c40 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -51,6 +51,13 @@ const AccordionItem = ({ } }); + if (!detailsRef.current.hasAttribute("open")) { + // Push to end of queue to read updated position and scroll to it + setTimeout(() => { + detailsRef.current.scrollIntoView({ behavior: "smooth" }); + }); + } + if (!isHashEnabled) { return; } @@ -58,10 +65,6 @@ const AccordionItem = ({ if (detailsRef.current.hasAttribute("open")) { window.history.replaceState({ hash: undefined }, "", location.pathname); } else { - // Push to end of queue to read updated position and scroll to it - setTimeout(() => { - detailsRef.current.scrollIntoView({ behavior: "smooth" }); - }); window.history.replaceState( { hash: id }, "",