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

chore: refactor homepage to if/else to preserve existing behaviour #1527

Merged

Conversation

alexanderleegs
Copy link
Contributor

Replaces behaviour in useDrag for homepage to allow for handling section subitems without changing the existing behaviour. This PR modifies the switch/cases to if/else instead to allow for types of the form <subitem name>-<number>.

@alexanderleegs alexanderleegs requested a review from a team September 27, 2023 01:33
@alexanderleegs alexanderleegs temporarily deployed to staging September 27, 2023 01:50 — with GitHub Actions Inactive
@alexanderleegs alexanderleegs force-pushed the refactor/homepage-usedrag-to-if-else branch from 52b424f to 199f675 Compare September 27, 2023 01:54
@alexanderleegs alexanderleegs temporarily deployed to staging September 27, 2023 02:07 — with GitHub Actions Inactive
if (typeof value === "string" && value.startsWith("textcardcard-")) {
const valArr = value.split("-")
const number = valArr[1]
return valArr.length === 2 && !Number.isNaN(Number(number))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think can just use isNaN directly without Number.isNaN?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is !Number.isNaN(Number(number)) to assert if its a number?

In the case where value is just textcardcard-, split gives ['textcardcard', '']

!Number.isNaN(Number(number)) evaluates to true here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eslint prefersNumber.isNaN because of the implicit coercion inside isNaN! I opted to use Number.isNan due to this

Good catch for the empty string, fixed in 4cf4b01

const number = valArr[1]
return valArr.length === 2 && !Number.isNaN(Number(number))
}
if (typeof value === "string") {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can be an else if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My linter is removing the else ifs here actually, since the if statement returns haha

@@ -184,6 +184,31 @@ export const useDrag: OnDragEndResponseWrapper = (
return updateHomepageState(result, homepageState)
Copy link
Contributor

Choose a reason for hiding this comment

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

this PR mainly changes the condiitonal logic from switch-case to if-else right? Why does switch-case not support
<subitem name>-<number>?

Copy link
Contributor

Choose a reason for hiding this comment

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

^switch case not as powerful as match sadly enough :/

src/hooks/useDrag.tsx Show resolved Hide resolved
const isUpdateHomepageType = (value: any): value is UpdateHomepageType => {
if (typeof value === "string" && value.startsWith("textcardcard-")) {
const valArr = value.split("-")
const number = valArr[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it might be confusing to see number = valArr[1] because the variable name number isn't describing its usage but rather its value.

could we use possibleCardIndex instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, e1e6969

src/hooks/useDrag.tsx Show resolved Hide resolved
src/hooks/useDrag.tsx Outdated Show resolved Hide resolved
src/hooks/useDrag.tsx Outdated Show resolved Hide resolved
@alexanderleegs alexanderleegs force-pushed the refactor/homepage-usedrag-to-if-else branch from 199f675 to 96d0ddd Compare September 27, 2023 09:34
@seaerchin seaerchin self-requested a review September 27, 2023 09:44
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

lgtm - i think we've accumulated quite abit of tech debt HAHA i think is a good time to relook at how we wanna handle dnd in these pages.

just adding on doesn't look to be sustainable :/

| `textCardItem-${number}`

const isUpdateHomepageType = (
value: any
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: chaneg to unknown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexanderleegs alexanderleegs temporarily deployed to staging September 27, 2023 09:49 — with GitHub Actions Inactive
@alexanderleegs alexanderleegs merged commit 0736282 into feat/text-cards-panel Sep 27, 2023
3 checks passed
@mergify mergify bot deleted the refactor/homepage-usedrag-to-if-else branch September 27, 2023 09:50
@alexanderleegs alexanderleegs temporarily deployed to staging September 27, 2023 10:07 — with GitHub Actions Inactive
alexanderleegs added a commit that referenced this pull request Sep 27, 2023
…1527)

* chore: refactor homepage to if/else to preserve existing behaviour

* fix: rebase errors

* fix: check for empty string

* fix: rename var

* fix: add type guards to create and delete and add comments

* chore: change to unknown
alexanderleegs added a commit that referenced this pull request Sep 27, 2023
* chore: add validators

* chore: add constants

* chore: add new textcard component types

* chore: add placeholder preview section

* chore: add new homepageDroppableZone type

* Feat: add textCards side panel

* feat: update useDrag to work with subtextcards

* feat: add text card parsing and change handler

* Fix: add button styles and restrict cards to 4

* fix: disable save on card error

* fix: rebase errors

* fix: remove comments

* fix: cast text cards once

* chore: remove unused updateElement

* fix: bug when attempting to create 2 textcard sections before adding text cards

Lodash behaviour here is buggy - _.set sets the fields in multiple array items for section data, which was causing errors

* chore: rename textcardcard

* feat: add help overlay and add feature flag (#1528)

* feat: add help overlay and add feature flag

* chore: rearrange resource position in add section

* IS-456: Text Cards Previews (#1516)

* wip: basic cms preview

* feat: refactor styles

Co-authored-by: Alexander Lee <[email protected]>

* feat: enable previews on text-cards

* fix: lint issues

* feat: update previews to match template

Co-authored-by: Alexander Lee <[email protected]>

---------

Co-authored-by: Alexander Lee <[email protected]>

* chore: refactor homepage to if/else to preserve existing behaviour (#1527)

* chore: refactor homepage to if/else to preserve existing behaviour

* fix: rebase errors

* fix: check for empty string

* fix: rename var

* fix: add type guards to create and delete and add comments

* chore: change to unknown

---------

Co-authored-by: Harish <[email protected]>
Co-authored-by: Alexander Lee <[email protected]>
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.

3 participants