Skip to content

chore: remove Notice component and migrate mocks and tests to new Content styling - #1110

Merged
augustlindemer merged 4 commits into
mainfrom
augustlindemer-remove-notice-component
Oct 29, 2026
Merged

augustlindemer merged 4 commits into
mainfrom
augustlindemer-remove-notice-component

Conversation

@augustlindemer

Copy link
Copy Markdown
Collaborator

Removes retired Notice component and cleans up associated mocks and tests. Mirrors flow migrations:

  • type 8 to type 250
  • insert "styleAsNotice": true,
  • description to content
  • insert title
  • leading h1/h2 in content to title
  • promote remaining h2 to h1
  • retain leading paragraph elements

Component types migrated via

for (const file of process.argv.slice(2)) {
  const flow = JSON.parse(fs.readFileSync(file, "utf8"));
  const nodes = flow.data?._root ? flow.data : flow;
  const notices = Object.values(nodes).filter((node) => node?.type === 8);
  if (!notices.length) continue;

  for (const node of notices) {
    node.type = 250;
    const data = Object.entries(node.data ?? {}).map(([key, value]) => [
      key === "description" ? "content" : key,
      value,
    ]);
    node.data = { styleAsNotice: true, ...Object.fromEntries(data) };
  }
  fs.writeFileSync(file, JSON.stringify(flow, null, 2) + "\n");
}

Content titles migrated via (see also respective flow migration here where this is copied from, minus tag insertion)

const contentType = 250;

const removeHtmlTags = (str) => {
  if (!str) return '';
  // Repeat until stable so tags can't reassemble
  let previous;
  do {
    previous = str;
    str = str.replace(/<[^>]*>/g, '');
  } while (str !== previous);
  return str;
};

const decodeHtmlEntities = (str) => {
  if (!str) return '';
  return str
    .replace(/&nbsp;/g, ' ')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&quot;/g, '"')
    .replace(/&#39;/g, "'")
    .replace(/&apos;/g, "'")
    .replace(/&amp;/g, '&');
};

for (const file of process.argv.slice(2)) {
  const flow = JSON.parse(fs.readFileSync(file, "utf8"));
  const flowData = flow.data?._root ? flow.data : flow;
  let changed = false;

  Object.values(flowData).forEach((nodeData) => {
    if (nodeData?.type !== contentType) return;

    const currentData = nodeData["data"];
    const content = currentData?.["content"];

    // Skip nodes without rich text content, or which have already been migrated
    if (!content || typeof content !== "string" || currentData["title"]) return;

    // Set the leading H1 (or H2, in older content) as the component title
    const leadingHeading = content.match(/^\s*<h([12])\b[^>]*>([\s\S]*?)<\/h\1>/i);
    if (!leadingHeading) return;

    const title = decodeHtmlEntities(removeHtmlTags(leadingHeading[2])).trim();
    if (!title) return;

    // Remove the leading heading from content, then promote H2s to H1s
    const newContent = content
      .slice(leadingHeading[0].length)
      .replace(/<h2\b/gi, "<h1")
      .replace(/<\/h2>/gi, "</h1>");

    currentData["title"] = title;
    currentData["content"] = newContent;
    changed = true;
  });

  if (changed) fs.writeFileSync(file, JSON.stringify(flow, null, 2) + "\n");
}

@jessicamcinchak jessicamcinchak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great !

Clever approach to script all these .json updates as it's not a staightforward find+replace but actually required various prop/value changes !! Giving me ideas for how to better update all the mock breadcrumbs to have seq to for some outstanding sort/cloning work next 🌱

Comment thread src/types/component.ts Outdated
Result = 3,
TaskList = 7,
Notice = 8,
// We retired Notice type 8, migrated in flow consent but retained in logs and flow history

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: content not consent ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Woops, yes! Considering bumping, before I fix this, is there any clean way to get around the Wales PR #1094? planx-new bump fails CI because of it. Maybe only way is to rebase this onto an old commit?

@augustlindemer augustlindemer Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Seeing the -new PR 7752 here for the above, can just leave this cleanup PR until Wales work is merged!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah sorry that's an annoying sequencing thing.

  • Best option is to just rebase/merge the planx-new Wales counterpart I think chore: Pick up previous Bannau Brycheiniog / DataMapWales work planx-new#7752 (I can take this branch over quick since looks like Daf is out for afternoon and update shortly)
  • Rebasing onto an older commit should work while both sides still on branches, but don't think it'll really solve anything once you want to merge this one to planx-core main !

@augustlindemer
augustlindemer force-pushed the augustlindemer-remove-notice-component branch from 162e66b to e888162 Compare October 29, 2026 14:08
@augustlindemer
augustlindemer merged commit 255cfd6 into main Oct 29, 2026
4 checks passed
@augustlindemer
augustlindemer deleted the augustlindemer-remove-notice-component branch October 29, 2026 14:59
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.

2 participants