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: convert Dropdown components to TS #3608

Merged
merged 15 commits into from
Nov 27, 2022
Merged

chore: convert Dropdown components to TS #3608

merged 15 commits into from
Nov 27, 2022

Conversation

SychO9
Copy link
Member

@SychO9 SychO9 commented Aug 21, 2022

Changes proposed in this pull request:
Converts the Dropdown component and its descendants to TS.

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
@SychO9 SychO9 self-assigned this Aug 23, 2022
SychO9 and others added 5 commits August 31, 2022 18:35
Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
Co-authored-by: David Wheatley <hi@davwheat.dev>
@SychO9 SychO9 requested a review from davwheat August 31, 2022 17:40
disabled: this.isGroupDisabled(group.id()) && this.isGroupDisabled(Group.MEMBER_ID) && this.isGroupDisabled(Group.GUEST_ID),
const groupButtons = app.store
.all<Group>('groups')
.filter((group) => ![Group.ADMINISTRATOR_ID, Group.GUEST_ID, Group.MEMBER_ID].includes(group.id()!))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Can we break this array out into a constant? Also, is it just me, or did we have a groups selector component at one point?

Copy link
Member Author

Choose a reason for hiding this comment

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

This component itself is the selector you're referring to I believe. It doesn't just list groups though, but different times of items depending on the permission.

framework/core/js/src/common/components/Dropdown.tsx Outdated Show resolved Hide resolved
framework/core/js/src/common/components/Dropdown.tsx Outdated Show resolved Hide resolved
framework/core/js/src/common/components/SelectDropdown.tsx Outdated Show resolved Hide resolved

getButtonContent(children: Mithril.ChildArray): Mithril.ChildArray {
const activeChild = children.find(isActive);
let label = (activeChild && typeof activeChild === 'object' && 'children' in activeChild && activeChild.children) || this.attrs.defaultLabel;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

We should really consider investing in a util file full of these guards/

// these attrs to a new button, so that it has exactly the same behaviour as
// the first child.
const firstChild = this.getFirstChild(children);
const buttonAttrs = Object.assign({}, firstChild?.attrs);
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
const buttonAttrs = Object.assign({}, firstChild?.attrs);
const buttonAttrs = Object.assign({}, firstChild?.attrs ?? {});

Is this necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Why not

{ ...firstChild?.attrs ?? {} }

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this is necessary, the getFirstChild method is typed to explicitly return a Vnode. if somehow it returns a non Vnode then it should probably be fixed at that level?

framework/core/js/src/common/components/SplitDropdown.tsx Outdated Show resolved Hide resolved
@@ -126,7 +126,7 @@ export default class ForumApplication extends Application {
// Route the home link back home when clicked. We do not want it to register
// if the user is opening it in a new tab, however.
document.getElementById('home-link')!.addEventListener('click', (e) => {
if (e.ctrlKey || e.metaKey || e.which === 2) return;
if (e.ctrlKey || e.metaKey || e.button === 1) return;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Let's add a comment explaining this one

Copy link
Member Author

Choose a reason for hiding this comment

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

are you referring to the conditional statement or just the e.button part?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is quite self-explanatory?

The comment above explains everything this line does.

@SychO9 SychO9 added this to the 1.6 milestone Sep 6, 2022
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
@SychO9 SychO9 requested a review from a team as a code owner September 7, 2022 10:59
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Copy link
Member

@davwheat davwheat left a comment

Choose a reason for hiding this comment

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

Approved, tentative on #3608 (comment)

@SychO9 SychO9 modified the milestones: 1.6, 1.7 Nov 15, 2022
@SychO9 SychO9 requested a review from imorland November 26, 2022 15:13
@SychO9 SychO9 merged commit 5bc47c0 into main Nov 27, 2022
@SychO9 SychO9 deleted the sm/dropdown-typescript branch November 27, 2022 09:34
@SychO9 SychO9 added the javascript Pull requests that update Javascript code label Feb 11, 2023
@iPurpl3x
Copy link
Contributor

These changes seem to have broken implementations like LanguageDropdown. Seems like the label text can't be extracted from complex markup like the one used in LanguageDropdown...

cc @imorland, @SychO9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code type/cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants