diff --git a/titleBoundary/helpers.js b/titleBoundary/helpers.js index 2bbfa16..67b2f27 100644 --- a/titleBoundary/helpers.js +++ b/titleBoundary/helpers.js @@ -1,11 +1,17 @@ /** * Find each DrawBoundary node in a flow (live or published) and update its' content if not already matching default */ -const updateDrawBoundaryNodeData = (flowData) => { +const updateDrawBoundaryNodeData = (flowData, slug) => { let newFlowData = flowData; Object.entries(flowData) .filter(([_nodeId, nodeData]) => nodeData["type"] === 10) - .forEach(([drawBoundaryNodeId, _drawBoundaryNodeData]) => newFlowData[drawBoundaryNodeId]["data"] = defaultDrawBoundaryNodeData); + .forEach(([drawBoundaryNodeId, _drawBoundaryNodeData]) => { + if (slug.startsWith("apply-for")) { + newFlowData[drawBoundaryNodeId]["data"] = defaultSubmissionDrawBoundaryNodeData; + } else { + newFlowData[drawBoundaryNodeId]["data"] = defaultGuidanceDrawBoundaryNodeData; + } + }); return newFlowData; } @@ -17,6 +23,8 @@ const updatePropertyInformationNodeData = (flowData) => { return newFlowData; } +const delay = (ms) => new Promise(res => setTimeout(res, ms)); + /** * Default DrawBoundary & PropertyInformation content as of 23 Jan 2024 * This isn't an ideal way to store or edit HTML. A nicer way to generate and update the content of this file is to: @@ -25,7 +33,7 @@ const updatePropertyInformationNodeData = (flowData) => { * 3. Paste formatted content here * 4. Run migration script to bulk update existing nodes across all applicable flows */ -const defaultDrawBoundaryNodeData = { +const defaultSubmissionDrawBoundaryNodeData = { title: "Check or amend the outline of your property and works", description: "

The red line shown below should include:

If the red line already includes all these, tap continue. If it does not, tap More information for guidance on how to amend or redraw the outline.

", @@ -42,10 +50,21 @@ const defaultDrawBoundaryNodeData = { '

We have pre-populated the map with a red outline that includes the entire property, using information from Land Registry.

In some cases, this outline might not include all the works or the areas that will be closed off. This could be the case if you are proposing works to a public highway (such as a dropped kerb), doing works that involve multiple properties, or works to a building that is part of a larger estate.

In these cases, you should amend the red outline by dragging the edges, or erase it by clicking the 🗑-icon on the map and draw a new outline.

How to draw and amend the outline

  1. Move the cursor to the corner you want to start with and click or tap once.

  2. Move the cursor to the next corner and click or tap.

  3. Repeat until you have the shape you need.

  4. Click or tap the last corner again to stop drawing.

  5. To amend the outline, click or tap on a line and drag it into a new position.

', }; +const defaultGuidanceDrawBoundaryNodeData = { + title: "Check or amend the outline of your property and works", + description: "

The red line shown below should include:

If the red line already includes all these, tap continue. If it does not, tap More information for guidance on how to amend or redraw the outline.

", + dataFieldBoundary: "property.boundary.site", + dataFieldArea: "property.boundary.area", + hideFileUpload: true, + info: "

This outline identifies the location of the proposed changes on a map. It helps us tell you if there are any planning constraints that might affect your project. It is sometimes called a 'red line drawing' or 'location plan'.

", + policyRef: "

The Town and Country Planning (Development Management Procedure) (England) Order 2015,

Planning Practice Guidance (PPG)

", + howMeasured: "

We have pre-populated the map with a red outline that includes the entire property, using information from Land Registry.

In some cases, this outline might not include all the works or the areas that will be closed off. This could be the case if you are proposing works to a public highway (such as a dropped kerb), doing works that involve multiple properties, or works to a building that is part of a larger estate.

In these cases, you should amend the red outline by dragging the edges, or erase it by clicking the :wastebasket:-icon on the map and draw a new outline.

How to draw and amend the outline

  1. Move the cursor to the corner you want to start with and click or tap once.

  2. Move the cursor to the next corner and click or tap.

  3. Repeat until you have the shape you need.

  4. Click or tap the last corner again to stop drawing.

  5. To amend the outline, click or tap on a line and drag it into a new position.

", +}; + const defaultPropertyInformationNodeData = { "title": "About the property", "description": "

This is the information we currently have about the property, including its title boundary shown in blue from the Land Registry

", "showPropertyTypeOverride": true }; -module.exports = { updateDrawBoundaryNodeData, updatePropertyInformationNodeData }; +module.exports = { updateDrawBoundaryNodeData, updatePropertyInformationNodeData, delay }; diff --git a/titleBoundary/index.js b/titleBoundary/index.js index ae3baa3..0934d83 100644 --- a/titleBoundary/index.js +++ b/titleBoundary/index.js @@ -52,11 +52,11 @@ ask.start(); // Find DrawBoundary & PropertyInformation nodes in live flow data, update them // This does NOT require a corresponding operation because we are not creating the flow for the first time - liveFlowData = updateDrawBoundaryNodeData(flow.data); + liveFlowData = updateDrawBoundaryNodeData(flow.data, flow.slug); liveFlowData = updatePropertyInformationNodeData(liveFlowData); // Find DrawBoundary & PropertyInformation nodes in published flow data, update them directly too - publishedFlowData = updateDrawBoundaryNodeData(flow.publishedFlows?.[0]?.data); + publishedFlowData = updateDrawBoundaryNodeData(flow.publishedFlows?.[0]?.data, flow.slug); publishedFlowData = updatePropertyInformationNodeData(publishedFlowData); // Write update in a single mutation block for postgres transaction-like rollback behavior on error @@ -79,6 +79,9 @@ ask.start(); } catch (error) { console.log(chalk.red(error)); } + + // wait 5 seconds before proceeding through next item in loop to avoid Hasura timeouts + await delay(5000); }); } else { console.log(chalk.red(`Cannot find any flows matching slug: ${formattedSlug}. Exiting migration script`));