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

feat(KNO-4367): Add pull email layout command #233

Merged
merged 45 commits into from
Oct 4, 2023

Conversation

francoborr
Copy link
Contributor

@francoborr francoborr commented Sep 27, 2023

Description

Adds a layout pull command for pulling a given email layout into a directory. It also allows to pull all email layouts from a given environment using the --all flag along with the --layout-dir.

It allows the following flags:

  • --environment
  • --all
  • --layout-dir
  • --hide-uncommitted-changes
  • --force

This PR also abstract some logic we use for reading external field contents. Before we used this logic when pulling workflows, but now we use the same logic for pulling layouts.

Tasks

KNO-4367

Video

https://www.loom.com/share/d0035467d1cf48a999536b466d5dd1df

Copy link
Contributor

@thomaswhyyou thomaswhyyou left a comment

Choose a reason for hiding this comment

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

Left a handful of comments/questions!

try {
if (indexDirCtx.exists) {
await fs.copy(indexDirCtx.abspath, backupDirPath);
await fs.emptyDir(indexDirCtx.abspath);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we always blow out everything in the index directory, then we won't be able to preserve the extracted file paths used in the existing email layout dirs. Could we take the approach similar to workflows where we selectively remove any email layouts that aren't found in emailLayouts?

Copy link
Contributor

@thomaswhyyou thomaswhyyou left a comment

Choose a reason for hiding this comment

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

Thanks for turning this around @Francobor2001! Overall this looks good, I left a handful of small comments, but this looks almost ready to go.

};

/*
* Validate the extracted file path based on its format and uniqueness (but not
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now I don't see we are doing a uniqueness check here, and I think we should replicate that here as well?

And in that case, we might be able to abstract out the validateExtractedFilePath function also as a shared helper? Instead of EmailLayoutDirContext or WorkflowDirContext, it could take a sourceFileAbspath string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea, here's the abstraction: ce50327

// If not marked with the @suffix, there's nothing to do.
if (!FILEPATH_MARKED_RE.test(key)) return;

const objPathStr = key.replace(FILEPATH_MARKED_RE, "");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const objPathStr = key.replace(FILEPATH_MARKED_RE, "");
const inlineObjPathStr = ObjPath.stringify(parts).replace(FILEPATH_MARKED_RE, "");

I know a layout json object is currently a flat object (i.e. 1 depth), but I think it'd be good to consistently use the ObjPath helper here so we can extend to support a nested layout object in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the commit where I improves this part of the code with all the nits you said: #233

Copy link
Contributor

@thomaswhyyou thomaswhyyou left a comment

Choose a reason for hiding this comment

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

One last thing on the validateExtractedFilePath function signature, but otherwise this looks good to go - thanks @francoborr!

export const validateExtractedFilePath = (
val: unknown,
sourceFileAbspath: string,
sourceJson: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sourceJson: string,

In checkIfValidExtractedFilePathFormat, we refer to sourceFileAbspath as the abspath to the json file, so I would say we match that here as well?

Taking the directory context abspath and the json file name separately like you've done here works also, but in that case we probably should name change sourceFileAbspath arg above to something different like, dirContextAbspath. Otherwise we have the same name vars that hold/mean something different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! 48743fa

@francoborr francoborr merged commit 47e1f60 into main Oct 4, 2023
@francoborr francoborr deleted the franco-kno-4367-cli-add-pull-email-layout-command branch October 4, 2023 20:28
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