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

Script to Upload SDR Shipments Sheet #93

Merged
merged 9 commits into from
Nov 23, 2024

Conversation

jtfairbank
Copy link
Collaborator

What changed?

Added a new script to manage the upload.

Resolves #89 and #90

How can you test this?

Add the attached shipments.csv export to the src/scripts/import-sdr-shipments-sheet folder, setup the src/scripts/.env file, then run the dev server in one terminal and yarn script:import-sdr-shipments-sheet in another. The logs at the end should show you that most of the shipments were created (or already exists), and it's ok if there are a few data error cases. If you see a lot of "Other" or "Error" results.

@@ -7,6 +7,10 @@
src/extensions/documentation/documentation/1.0.0/full_documentation.json
src/extensions/documentation/public/index.html

# Explicitly gnore data import csv files so we don't accidentally commit them.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: typo, should be "ignore"

Authorization: `Bearer ${STRAPI_ENV.KEY}`,
},
});
const body = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to wrap this in a try/catch so you can add more information to the error if we can't parse the response body.

},
body: JSON.stringify({ data }),
});
const body = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here for the try/catch

value: PromiseSettledResult<T>,
): value is PromiseRejectedResult => {
return value.status === "rejected";
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I love, love, love to see type guard functions 🤩

resultsMap[UploadWorkflowStatus.OTHER].push(workflowResult);
}
return resultsMap;
}, resultsMap);
Copy link
Contributor

@corasaurus-hex corasaurus-hex Aug 18, 2024

Choose a reason for hiding this comment

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

I think my lodash suggestion would apply here as well.

value: PromiseSettledResult<T>,
): value is PromiseRejectedResult => {
return value.status === "rejected";
};
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably pull this out into a shared utility?

Authorization: `Bearer ${STRAPI_ENV.KEY}`,
},
});
const body = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

try/catch would probably be a good idea here

},
body: JSON.stringify({ data }),
});
const body = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto here

Copy link
Contributor

@corasaurus-hex corasaurus-hex left a comment

Choose a reason for hiding this comment

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

I had some suggestions but nothing show-stopping. nicely done!

Copy link
Contributor

@ll-zerr ll-zerr left a comment

Choose a reason for hiding this comment

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

I ran the code to test if I could get the anticipated desired results and, after resolving a "country-code-lookup" error, it worked well. 👍🏻

Copy link
Collaborator Author

@jtfairbank jtfairbank left a comment

Choose a reason for hiding this comment

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

praise: @corasaurus-hex really great work! Love how Lodash simplifies a lot of those longer / more complex native JS functions. Really appreciate you stepping in to make the refactoring happen in this PR!

Found a few minor things and had a few questions on more meta comments like code readability / naming conventions. If you're at the tech hang I think we can run through them together to make some quick decisions and get this one merged in!

src/scripts/import-sdr-shipments-sheet/add-countries.ts Outdated Show resolved Hide resolved
return new Set(
shipments.flatMap((s) =>
[s.sendingCountry, s.receivingCountry].filter((v) => v !== ""),
),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@corasaurus-hex

question: Should we set some variable naming conventions? Personally I prefer to avoid shorthand variable names (clarity for other devs, code searchability, etc). For example in this case I'd use shipment or country instead of s and v. But I don't really care as long as we're consistent in how we approach it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I usually scale the length of my variable names with the complexity and length of the function, so for simple and smaller functions I use smaller variables because it's trivial to see where the value comes from. Does that seem fair? It's a subtle thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@corasaurus-hex that certainly sounds reasonable to me! Do you think this would be a good one to kick back to the wider team on slack to see if anyone has strong preferences? The we can note it as a convention in the readme or something, which will help folks who are new to our codebase (Hacktoberfest, etc).

Copy link
Contributor

Choose a reason for hiding this comment

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

A style guide?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm reluctant to be very prescriptive on styles, given how subjective style is, and less prescriptive when it comes to folks with less experience, but we could certainly add a style guide as a task leading up to hacktoberfest so that folks can have some guidance.

I wonder how many of these things could be made linter rules, too?

src/scripts/import-sdr-shipments-sheet/add-countries.ts Outdated Show resolved Hide resolved
src/scripts/import-sdr-shipments-sheet/add-shipments.ts Outdated Show resolved Hide resolved
src/scripts/import-sdr-shipments-sheet/add-shipments.ts Outdated Show resolved Hide resolved
return value.status === "fulfilled";
};

export const _isRejected = <T>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nitpick: Should remove the _ in the function name. That was originally included since we weren't using the function but it seemed useful to have around as a pairing with isFulfilled. Now that it's refactored out and exported we don't need to indicate that it's not being used.

@ll-zerr
Copy link
Contributor

ll-zerr commented Aug 24, 2024

question (blocking): Something in the last two commits may need investigation. The code is no longer working as expected when I double-checked it before basing my new feature branch from Taylor's. I have all the recent changes pulled down and both countries and shipments appear affected. See the attached image for my results when I run yarn script:import-sdr-shipments-sheet in a different terminal.

sdr-screenshot-results-mu

@jtfairbank jtfairbank force-pushed the feat/89-90/rebase/upload-sdr-shipments-sheet branch from 5c35871 to 6107d38 Compare November 23, 2024 05:18
@jtfairbank
Copy link
Collaborator Author

Gonna merge this one in to keep things moving. Probably still needs work (@corasaurus-hex had good suggestions and @veryeli did good stuff on another script which should be ported back here) but I'll set those up as issues to iterate on.

@jtfairbank jtfairbank merged commit 5915fd8 into saga Nov 23, 2024
1 check passed
@jtfairbank jtfairbank deleted the feat/89-90/rebase/upload-sdr-shipments-sheet branch November 23, 2024 05:29
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.

Fix: Create a Component For DA Shipment Roles
3 participants