Skip to content

Conversation

clairep94
Copy link
Collaborator

@clairep94 clairep94 commented Sep 1, 2025

pr05 Typescript Migration 7: Migrate the client/components folder

Context:

  1. git mv someComponent.jsx someComponent.tsx. If possible, commit without the no-verify flag, otherwise with no-verify.
  2. Check for all instances of useage for the common component to determine props types
  3. Add props types & unit test update
  4. Add JSDocs
  • did not refactor or add many unit tests.

Changes:

Client/components:

  • Dropdown
    • Saw that only the styled components wrapper was being used and only used once, so migrated the wrapper to Dropdown/DropdownMenu & deleted the file
  • Dropdown/DropdownMenu
  • Dropdown/MenuItem
  • Dropdown/TableDropdown
  • Menubar/Menubar
  • Menubar/MenubarItem
  • Menubar/MenubarSubmenu -- was not able to figure out the logic of this file. Got stuck on previous PR attempt and abandonned. Will take a look again on a separate PR.
  • Menubar/contexts
  • PreviewNav
  • RootPage
  • useAsModal -- deleted as this is unused

Client/common:

  • useModalClose
    • update to support generic typing
  • usePrevious
    • update to support generic typing

Other:

  • any updates to use named exports

Notes:

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

clairep94 and others added 30 commits August 3, 2025 10:41
…omponents, remove react/require-default-props rule
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

@clairep94 clairep94 Sep 1, 2025

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

@clairep94 clairep94 Sep 1, 2025

Choose a reason for hiding this comment

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

updated this to use generic <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.

ignore, repeat from /common

Copy link
Collaborator Author

@clairep94 clairep94 Sep 1, 2025

Choose a reason for hiding this comment

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

updated this to use generic <T>

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, good idea!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ignore, repeat from /common

Comment on lines -7 to -71
export const DropdownWrapper = styled.ul`
background-color: ${prop('Modal.background')};
border: 1px solid ${prop('Modal.border')};
box-shadow: 0 0 18px 0 ${prop('shadowColor')};
color: ${prop('primaryTextColor')};

position: absolute;
right: ${(props) => (props.right ? 0 : 'initial')};
left: ${(props) => (props.left ? 0 : 'initial')};

${(props) => props.align === 'right' && 'right: 0;'}
${(props) => props.align === 'left' && 'left: 0;'}


text-align: left;
width: ${remSize(180)};
display: flex;
flex-direction: column;
height: auto;
z-index: 2;
border-radius: ${remSize(6)};

& li:first-child {
border-radius: ${remSize(5)} ${remSize(5)} 0 0;
}
& li:last-child {
border-radius: 0 0 ${remSize(5)} ${remSize(5)};
}

& li:hover {
background-color: ${prop('Button.primary.hover.background')};
color: ${prop('Button.primary.hover.foreground')};

* {
color: ${prop('Button.primary.hover.foreground')};
}
}

li {
height: ${remSize(36)};
cursor: pointer;
display: flex;
align-items: center;

& button,
& button span,
& a {
padding: ${remSize(8)} ${remSize(16)};
font-size: ${remSize(12)};
}

* {
text-align: left;
justify-content: left;

color: ${prop('primaryTextColor')};
width: 100%;
justify-content: flex-start;
}

& button span {
padding: 0px;
}
}
`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was the only portion of the code being used so i moved it into /DropdownMenu/DropdownMenu directly

Comment on lines 23 to 29
right: ${(props) =>
props.align === DropdownMenuAlignment.RIGHT ? 0 : 'initial'};
left: ${(props) =>
props.align === DropdownMenuAlignment.LEFT ? 0 : 'initial'};

${(props) => props.align === DropdownMenuAlignment.RIGHT && 'right: 0;'}
${(props) => props.align === DropdownMenuAlignment.LEFT && 'left: 0;'}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right: ${(props) => (props.right ? 0 : 'initial')};
  left: ${(props) => (props.left ? 0 : 'initial')};
  ${(props) => props.align === 'right' && 'right: 0;'}
  ${(props) => props.align === 'left' && 'left: 0;'}

this is the previous code from /Dropdown for reference

Other parts of the DropdownWrapper are unchanged

Comment on lines +23 to +26
right: ${(props) =>
props.align === DropdownMenuAlignment.RIGHT ? 0 : 'initial'};
left: ${(props) =>
props.align === DropdownMenuAlignment.LEFT ? 0 : 'initial'};
Copy link
Collaborator Author

@clairep94 clairep94 Sep 1, 2025

Choose a reason for hiding this comment

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

 right: ${(props) => (props.right ? 0 : 'initial')};
  left: ${(props) => (props.left ? 0 : 'initial')};
  ${(props) => props.align === 'right' && 'right: 0;'}
  ${(props) => props.align === 'left' && 'left: 0;'}

this is the previous code from /Dropdown for reference

I think this is a typo where props.right and props.left would never exist, as we use props.align, so we would have right:initial and left:initial, then update to right: 0 or left: 0 based on props.align

So I tried to simplify

Other parts of the DropdownWrapper are unchanged

khanniie
khanniie previously approved these changes Sep 2, 2025
Copy link
Collaborator

@khanniie khanniie left a comment

Choose a reason for hiding this comment

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

Looking great!! thank you so much!

@@ -20,8 +24,10 @@ const TableDropdownIcon = () => {
);
};

const TableDropdown = styled(DropdownMenu).attrs({
align: 'right',
export interface TableDropdownProps extends DropdownMenuProps {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

you might be able to alias it as

export type TableDropdown = DropdownMenuProps

https://github.com/processing/p5.js-web-editor/pull/3619/files

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I thought maybe we could do this as an extended interface so we can extend with TableDropdown-specific props in the future, but happy to change to a type if preferred! I might have overthought this haha maybe TableDropdown is just a styled DropdownMenu

createMenuHandlers: (
id: string
) => {
onMouseOver: (e: React.MouseEvent) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not strongly opinionated about this so feel free to just acknowledge and ignore, but I noticed that the logic changes a bit in this file where the factory methods (e.g. createMenuHandlers) previously would return an empty dict {} but now return dicts where the value is a function that doesn't do anything. I think if there's logic further down the line that checks somehting like menuHandlers.onMouseOver, the return would be different. in the past where it would be undefined now it would return () => {}. if you added the null functions to avoid type errors, we could just make the handlers optional? just wanted to flag it in case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@khanniie good point! updated

might need a re-approve as the change would dismiss the previous approval

@khanniie khanniie requested a review from raclim September 2, 2025 01:33
@clairep94 clairep94 changed the title Pr05/migrate client components pr05 Typescript Migration #7: migrate client components Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr05 Grant Projects pr05 Grant Projects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants