-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add find and replace for passport variable via cli prompts #9
feat: add find and replace for passport variable via cli prompts #9
Conversation
const currentFn = nodeData["data"][`${passportKey}`] | ||
const currentValueSegments = currentFn.split(".") | ||
const matchIndexPosition = currentValueSegments.indexOf(currentPassportVariable) | ||
if (matchIndexPosition !==-1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to this line the script will only ever replace the first instance of the exact match string.
I don't think there'd ever be cases of something like extend.outbuildings.shed.outbuildings
but if that's not the case I can review the logic here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we look at real ProjectTypes, we can see that there are edge cases where the same word can appear twice - eg https://github.com/theopensystemslab/digital-planning-data-schemas/blob/main/types/enums/ProjectTypes.ts#L98
Is it actually necessary to split(".")
the fn/val string here and then re-join, can we simply try a replaceAll()
on the full passport string - which would then also give us more flexibility if we want to use this script ot replace full passport variables (any number characters/segments) rather than only a single segment of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing the projectTypes
and checking the assumption I'd made!
I'll have another look at this functionality. I had been using .replace
the reason I was splitting was so I could do exact matches as I was worried about incorrectly replacing substrings so for something like alter → change
incorrectly leadings toalteration.openings → changeation.openings
I'll have another look at replaceAll
to see how whole sections can be updated 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here: 4bd0128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops sorry left this as a new comment rather than on this thread: #9 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good - a few small comments !
Happy to test locally again once those are resolved, then let's discuss which flows this should be run against on staging so that August & George can also test 👍
const currentFn = nodeData["data"][`${passportKey}`] | ||
const currentValueSegments = currentFn.split(".") | ||
const matchIndexPosition = currentValueSegments.indexOf(currentPassportVariable) | ||
if (matchIndexPosition !==-1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we look at real ProjectTypes, we can see that there are edge cases where the same word can appear twice - eg https://github.com/theopensystemslab/digital-planning-data-schemas/blob/main/types/enums/ProjectTypes.ts#L98
Is it actually necessary to split(".")
the fn/val string here and then re-join, can we simply try a replaceAll()
on the full passport string - which would then also give us more flexibility if we want to use this script ot replace full passport variables (any number characters/segments) rather than only a single segment of them?
passportValue/helpers.js
Outdated
|
||
function replaceAllOccurrences(fullPassportValue, currentPassportVariable, newPassportVariable) { | ||
const regex = new RegExp('\\b' + currentPassportVariable + '\\b', 'g'); | ||
return fullPassportValue.replace(regex, newPassportVariable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - still not personally convinced this regex that protects against partial matches is better approach than plain string replaceAll()
and I think is going to be ultimately limiting in use of this against "real" content examples!
In your example alter
→ change
(but not alteration
→ changeation
) that this regex protects against, I think you're overlooking the option to simply pass alter.
as the find variable then replaceAll()
as expected !!
In recent file naming, there were other examples of partial matches like councilTaxBill
(find = councilTax
) → councilBill
(replace = council
) that wouldn't be supported by this regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm maybe being too risk averse with this approach. As far as I understand the regex would approach would still allow all renaming but might require more runs as matches would need to be made explicitly councilTaxBill → councilBill
vs the freedom / risk of partial match renames.
Passing in variables with .
as in alter.
is definitely something I hadn't considered and does overcome the issue I'd outlined although I guess it does require protecting against edge cases at the time of running the code and a deeper familiarity with the project types versus having that edge case protection in the code?
Although, I'm happy to defer to your judgement though as you're much more familiar with this process and the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here: f073806
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ! My theory on these is: always start quick & flexible based on known content examples, and introduce strictness as future use cases necessitate. Because since these scripts are only manually run in very controlled scenarios right now (eg not exposed to editors), we don't need to get hung up anticipating uses beyond the task at hand!
- As per: #9 (comment) - Allows more flexibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for picking this one up! Happy for code to merge to main
whenever you're ready.
As it's already a bit late in the afternoon & George isn't back until tomorrow, I'd advise running the outbuilding find&replace against staging tomorrow morning for final review from August & George (will get overwritten by nightly sync).
We'll want to run it against all flows that ask questions about project type (in addition to any parent services that nest those flows as external portals) - which I expect will be a quite long list I haven't started to compile yet. I can take over testing from here if helpful?
Once content team reviews staging & confirms automations are working as expected, I'll make the schema changes and run against production after hours later this week.
Thanks for the review @jessicamcinchak and as advised I'll try running outbuilding find&replace against staging tomorrow morning 👍 Yeah I'm still not sure how best to go about forming that exhaustive list of flows to update so if you don't mind picking it up from there that would be great. |
What
Why
outbuildings
tooutbuilding
Testing
Local:
Staging:
Screenshots
outbuildings → outbuilding
outbuilding.shed → shed