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

add support for optional salesforce ids in csv upload #1034

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

muhammad-ammar
Copy link
Contributor

@muhammad-ammar muhammad-ammar commented Sep 19, 2023

JIRA: https://2u-internal.atlassian.net/browse/ENT-7642

For all changes

  • Ensure adequate tests are in place (or reviewed existing tests cover changes)

Only if submitting a visual change

  • Ensure to attach screenshots
  • Ensure to have UX team confirm screenshots

@muhammad-ammar muhammad-ammar marked this pull request as draft September 19, 2023 14:01
@muhammad-ammar muhammad-ammar marked this pull request as ready for review September 20, 2023 05:30
@muhammad-ammar muhammad-ammar force-pushed the ammar/extract-and-use-sfids branch 2 times, most recently from bdd0ae0 to 1c20eb8 Compare September 20, 2023 05:39
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

❗ No coverage uploaded for pull request base (master@5cb3eeb). Click here to learn what that means.
Patch coverage: 91.42% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1034   +/-   ##
=========================================
  Coverage          ?   82.90%           
=========================================
  Files             ?      412           
  Lines             ?     8902           
  Branches          ?     1825           
=========================================
  Hits              ?     7380           
  Misses            ?     1482           
  Partials          ?       40           
Files Changed Coverage Δ
src/components/InviteLearnersModal/index.jsx 39.21% <0.00%> (ø)
src/data/validation/email.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@muhammad-ammar muhammad-ammar force-pushed the ammar/extract-and-use-sfids branch 7 times, most recently from 26b8765 to 894ff12 Compare September 22, 2023 10:22
Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

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

Seems reasonable, couple of small suggestions!

};

// Combine all the rows from textarea and CSV and then make a map of email to salesforce id
const parseData = (formData) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe name this getSalesforceIdsByEmail

'[email protected],000000000000YYYYYY',
'[email protected],000000000000ZZZZZZ',
'[email protected],000000000000ABCDDD',
'[email protected],',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: consider adding one more test email in here without a trailing comma, like "[email protected]" to make sure the splitting/parsing still works as expected.

Comment on lines 221 to 222
const allFalse = ids.every(item => !item);
return allFalse ? undefined : ids;
Copy link
Member

@adamstankiewicz adamstankiewicz Sep 22, 2023

Choose a reason for hiding this comment

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

nit: perhaps add a comment and/or rename this variable to explain this logic a bit more explicitly? It's not clear to me what allFalse really means in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this check ensure that if there are no salesforce ids present then do not send an empty array to backend.

src/components/InviteLearnersModal/index.jsx Show resolved Hide resolved
return validateEmailAddresses(emails).validEmails;

rows.forEach((row) => {
const [email, id] = row.split(',').map(item => item.trim());
Copy link
Member

Choose a reason for hiding this comment

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

nit: is it perhaps worth renaming id to salesforceId or similar, so reading the code has a bit more context added to what type of id it is (Salesforce).

Comment on lines 186 to 187
let emails = extractEmails(formData).allEmails;
emails = _.union(emails); // Dedup emails
Copy link
Member

Choose a reason for hiding this comment

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

nit: would const emails = _.union(extractEmails(formData.allEmails)) // Extract and dedup emails be logically equivalent without needing to define and then re-define emails?

// allEmails: Concatenation of `textEmails` and `CSVEmails`
const extractEmails = (formData) => {
let textEmails = [];
let CSVEmails = [];
Copy link
Member

Choose a reason for hiding this comment

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

nit: csvEmails

return {
textEmails: textEmails.length ? textEmails : undefined,
CSVEmails: CSVEmails.length ? CSVEmails : undefined,
allEmails,
Copy link
Member

Choose a reason for hiding this comment

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

[suggestion] Given allEmails will always return an array, even when empty, I'm wondering if all the properties should follow that convention for consistency, which might simplify this logic a bit.

return {
  textEmails,
  csvEmails,
  allEmails,
}

Copy link
Contributor Author

@muhammad-ammar muhammad-ammar Sep 22, 2023

Choose a reason for hiding this comment

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

Initially I was returning the exact same object as you suggested but this line fails when textEmails is [] and csvEmails have some emails. For example the below code evaluates to [] which is not what is expected.

This test fails if we just return the below object

return {
  textEmails,
  csvEmails,
  allEmails,
}

const csvEmails = formData[EMAIL_ADDRESS_CSV_FORM_DATA];
const extractedEmails = extractEmails(formData);
const textAreaEmails = extractedEmails.textEmails;
const csvEmails = extractedEmails.CSVEmails;
let {
invalidEmailIndices,
} = validateEmailAddresses(textAreaEmails || csvEmails);
Copy link
Member

Choose a reason for hiding this comment

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

[curious/clarification] Do we only support textarea OR CSV upload? Aka, you can't provide textarea input AND CSV upload together? This logic here would imply that it's one or the other, but I wonder if that's actually what we should be doing as a product requirement. Might be worth clarifying (not blocking/related to this PR, though!).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In existing logic, On the UI we say that either input emails in textarea or upload csv but in reality we pick all the emails from both textarea and csv and then send them to backend for license assignment.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying!

@muhammad-ammar muhammad-ammar merged commit e12f09a into master Sep 25, 2023
6 checks passed
@muhammad-ammar muhammad-ammar deleted the ammar/extract-and-use-sfids branch September 25, 2023 17:35
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.

4 participants