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

DISCO-290 Set Rex heading levels for Assignable #2269

Merged
merged 87 commits into from
Oct 10, 2024
Merged

Conversation

Dantemss
Copy link
Member

@Dantemss Dantemss commented Jul 2, 2024

I can see like 10 different ways to do this so maybe it's best if you told me if you like this or not

@Dantemss Dantemss requested a review from TomWoodward July 2, 2024 22:06
@Dantemss Dantemss self-assigned this Jul 2, 2024
@TomWoodward TomWoodward temporarily deployed to rex-web-heading-levels-veafeua July 2, 2024 22:06 Inactive
@Dantemss Dantemss marked this pull request as ready for review July 26, 2024 14:56
@Dantemss Dantemss requested a review from a team as a code owner July 26, 2024 14:56
Copy link
Member

@TomWoodward TomWoodward left a comment

Choose a reason for hiding this comment

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

overall this is fine, just some comments on the actual mutation

function changeHeadingLevels(rootEl: HTMLElement, topHeadingLevel: number) {
let currentLevel = topHeadingLevel;

[ 1, 2, 3, 4, 5, 6 ].forEach((level) => {
Copy link
Member

Choose a reason for hiding this comment

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

i was thinking you'd query the highest level header in the content, take the difference from the desired topHeadingLevel, and then modify every heading by that delta

i think your current logic sort of attempts to "fix" an invalid heading structure that is missing levels, but i don't think we want to mess around with that


if (tags.length > 0) {
const newTagName = `h${currentLevel}`;
tags.forEach((el) => el.outerHTML = el.outerHTML.replace(RegExp(`<${origTagName}`, 'g'), `<${newTagName}`)
Copy link
Member

Choose a reason for hiding this comment

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

there is some risk of this regex replacing things it shouldn't.... i would iterate over tags and create a new tag element at the correct level, copy attributes over, and then use replaceWith to replace the element in the tree

@bethshook bethshook requested a review from TomWoodward October 4, 2024 18:36
@bethshook bethshook assigned bethshook and unassigned Dantemss Oct 4, 2024
Copy link
Member

@TomWoodward TomWoodward left a comment

Choose a reason for hiding this comment

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

would be nice to see a spec, but looks generally good to me

const headingLevels = [ 1, 2, 3, 4, 5, 6 ];
const currentTopHeading = headingLevels.find((level) => rootEl.querySelectorAll(`h${level}`)?.length);

if (!currentTopHeading || topHeadingLevel <= currentTopHeading) {
Copy link
Member

Choose a reason for hiding this comment

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

if desired topHeading level is 2, and the currentTopHeading is 3, we don't want to skip we want to bump them all up.

if they are equal we can return

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok, was confused on this point

@bethshook bethshook requested a review from TomWoodward October 9, 2024 15:22
Copy link
Member

@TomWoodward TomWoodward left a comment

Choose a reason for hiding this comment

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

looks good but hold off for a sec while we verify if the top level should be 2 or 3

@TomWoodward TomWoodward merged commit 522c322 into main Oct 10, 2024
8 of 9 checks passed
@TomWoodward TomWoodward deleted the heading-levels branch October 10, 2024 15:27
TomWoodward added a commit that referenced this pull request Oct 28, 2024
TomWoodward added a commit that referenced this pull request Nov 4, 2024
* transition textSize -> text_size

* return token as token data; conditionally assign json encoded sub fields to token data

* 👕

* Add tests back into ci file

* update launchToken specs

* update snapshot for #2269

* shut up test output

* fix keys on chapter filter loops

* reduce test output for invalid props on mock elements

* wrap act

* fix uuid import warning

* fix act warning

* fix leaky mocks in search result sidebar specs

* do not re-fetch book for content warning

* remove invalid test

* fix Page.spec

* fix search sidebar specs

* fix transform spec

* coverage for cdn gateway

* add thresholds to jest config

* coverage for search sidebar

* add coverage for textsize

* 👕

* fix effect dependency

* 👕

---------

Co-authored-by: staxly[bot] <35789409+staxly[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants