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

created link button to new item #227

Conversation

aaleksa
Copy link

@aaleksa aaleksa commented May 27, 2024

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review on my code
  • I have made corresponding changes to the documentation (if any were needed)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and previously existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Description

Relates #[issue number] OR Closes #[issue number]
Include here a short description of what behaviour this Pull Request introduces.
Outline any new dependencies introduced.

Files changed

Include one to two lines on the necessary changes to each file.

  1. app/(dashboard)/add-item/page.tsx
    Added itemId to the path in router redirect
  2. app/(dashboard)/add-item/success/page.tsx
    Added Button
  3. components/buttons/ButtonGoToItem.tsx
    ButtonGoToItem implementation
  4. supabase/models/insertRow.ts
    Return created item record on api call "supabase.from(table).insert(InsertValues).select();" to create new item

UI changes

If this PR includes changes to the UI include a screengrab of the alterations in review.

Changes to Documentation

Include an outline of why Documentation needed to be updated with this PR

Tests

Include a description of any tests added - if none have been added explain why.

Copy link

netlify bot commented May 27, 2024

👷 Deploy request for cool-creponne-3e1272 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6dbd685

@aaleksa
Copy link
Author

aaleksa commented May 27, 2024

image

Added new button, 'GO TO YOUR ITEM'

@aaleksa aaleksa force-pushed the #192-Add-a-link-to-a-newly-created-item-on-add-item-success-page branch 2 times, most recently from 70cd473 to 2a2ade4 Compare May 27, 2024 18:12
Copy link
Contributor

@camelPhonso camelPhonso left a comment

Choose a reason for hiding this comment

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

Thanks @aaleksa - your implementation is working brilliantly 👍 but I'm requesting a few changes that should help us clean up the code base a little.

It's also just worth adding a reminder to please revisit our documentation on conventions - the conventional commit messages for example won't be a problem if they're missed but in a more complicated PR (and especially if we ever need to go back in the commit history and track an issue) it can help us greatly keeping track of what changes are happening throughout our commit history.

@@ -10,6 +17,9 @@ const SuccessPage = () => {
<Link href='/add-item'>
<ButtonRounded type='button'>ADD ANOTHER ITEM</ButtonRounded>
</Link>
<Link href={`/item/${idItem}`}>
<ButtonGoToItem type='button'>GO TO YOUR ITEM</ButtonGoToItem>
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need a new component here. The ButtonRounded.tsx component can be re-used for this situation by just passing the appropriate props - let's apply it instead 👍

Comment on lines +10 to 15
const response = await supabase.from(table).insert(InsertValues).select();
const [createdRecord] = response?.data ?? [];
return createdRecord as PartialItem;
} catch (error) {
// setSubmitting(false);
console.log('An unexpected error occurred');
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 response = await supabase.from(table).insert(InsertValues).select();
const [createdRecord] = response?.data ?? [];
return createdRecord as PartialItem;
} catch (error) {
// setSubmitting(false);
console.log('An unexpected error occurred');
const {data, error} = await supabase.from(table).insert(InsertValues).select();
return data as PartialIem;
} catch (error) {
throw error
console.error(`Error inserting rows to the database: ${error}`);

Using the nullish coalescing operator here will mean we always get an array even if there was an error - we definitely don't want that because it would hide any issues happening in our query to the database.

Instead, we can refactor the function to actually throw the error back up to be handled appropriately wherever we called this query.

Comment on lines +58 to +60
const response = await insertRow('items', dataItem);
if (response === false) {
throw 'InsertFailed';
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the refactor for insertRow suggested in this review let's also adapt this implementation of the function so we can handle the error it would throw in case of a failure. It should just be a case of replicating the same pattern.

💡 Also, I really liked the fact that you attempted to enforce our types in your refactor of insertRow but let's move that declaration up to here instead.

I'm suggesting this because I think it will be a better separation of concerns - it means we let our util return the data just as is and then we get TypeScript to evaluate if it matches the type we expected once it's been returned here. That way the static testing will be working for us and alerting us if anything changes in future and our Types need a review or there is an issue with the data returned.

Comment on lines +42 to +45
.button-stroke {
border-left: #54BB89 solid 8px;
border-right: #54BB89 solid 8px;
}
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 a little confused about the intention of this new class - I couldn't really make out the effect from looking at the UI, can you share what this is fixing in the button?

@camelPhonso
Copy link
Contributor

Relates #192

Just explicitly linking to Issue for traceability

@camelPhonso
Copy link
Contributor

Hi @aaleksa can you just confirm that you are still monitoring this PR?

@camelPhonso
Copy link
Contributor

Closing this PR as it's been stale and the issue is up for re-assignment

@camelPhonso camelPhonso closed this Jul 5, 2024
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.

None yet

2 participants