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

Ddfbra 294 hent paragraph data fra cms og vis i go fe #94

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ThomasGross
Copy link
Contributor

Link to issue

https://reload.atlassian.net/browse/DDFBRA-278

Description

This PR introduces:

  • The video paragraph and related stories
  • Typesafe way of dynamically rendering paragraphs
  • Go page rendering

@spaceo spaceo self-requested a review January 20, 2025 16:29
Copy link
Contributor

@spaceo spaceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some change requests and some areas to discuss


if (routeType === "RouteRedirect") {
// TODO: implement redirect
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when you return nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will return 'undefined' which is a falsy statement and therefore not render anything. But lets return null instead to keep consistency.

Comment on lines 9 to 13
return (
<div className="flex flex-col gap-y-paragraph-spacing">
<ParagraphResolver paragraphs={paragraphs ?? []} />
</div>
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we beforehand know that there is no data, in this case paragraphs I think we should not to to resolve pragraphs.
So it would be:

  if (!paragraphs) {
    // Null or something else default.
    return nulll;
 }
  return (
    <div className="flex flex-col gap-y-paragraph-spacing">
      <ParagraphResolver paragraphs={paragraphs} />
    </div>
  )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of rendering do we want if there are no paragraphs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, If theres no paragraphs we dont want to show anything.

const [mounted, setMounted] = React.useState(false)

useEffect(() => {
setMounted(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? Please document why you need to keep in a state if the compoment is mounted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im pretty sure I implemented it because it had some buggy behavior on the demo site. But lets try to remove it and se if the bug is still present.

Comment on lines 28 to 31
if (routeType === "RouteExternal") {
// TODO: implement external route redirect
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I am not fan of code stubs if they are not needed. Could we maybe just write one todo where we write that we need to take care of these two cases?
Consider creating a Jira task for it too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript is complaining if im not checking for each routeType coming from the cms

codegen.ts Outdated
@@ -6,6 +6,7 @@ const { loadEnvConfig } = require("@next/env")

loadEnvConfig(process.cwd())

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write a comment why this is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im removing this line 😊

Comment on lines +24 to +25
{/* @ts-ignore TODO: figure out how to type dynamically imported components */}
<DynamicComponentType key={index} {...paragraph} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think it is ok, for now, to ignore the ts error, I really think we should be able to handle case like this. And it is definetely possible.
If you choose to ignore this I think we should have a jira task for it, otherwise it will will be forgotten in eternity ....eternity ... eternity (weird echo)

if (DynamicComponentType === null) return null

return (
<ParagraphErrorBoundary key={index}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that you introduce a Paragraph Error boundary.
Is we talked about earlier we should have a clear defined way of treating errors throughout the application.
Please write an ADR about what the idea is behind treating errors in paragraphs. Or if you have a general idea of handling errrors in components with error boundaries the ADR can contain information about that too.

Comment on lines 11 to 13
<Button className="mt-4" onClick={resetErrorBoundary}>
Genindlæs
</Button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a button for reloading failed content?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if there's a onClick method on the element it should be a button. Maybe we could remove the button entirely?

The resetErrorBoundary is in case you want to try reloading the element. Maybe a connection timeout or something happend and the paragraph did not load in time.

package.json Outdated
"format:check": "prettier --check .",
"format:write": "prettier --write .",
"lint": "next lint",
"start:with-server-source-maps": "NODE_OPTIONS='--enable-source-maps=true' next start",
"start": "next start",
"start": "NODE_EXTRA_CA_CERTS=\"$(mkcert -CAROOT)/rootCA.pem\" next start",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be inserted here, since we use start in. production

@spaceo spaceo removed their assignment Jan 20, 2025
@ThomasGross ThomasGross requested a review from spaceo January 21, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants