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

feat: typed events #1981

Merged
merged 15 commits into from
Feb 6, 2023
Merged

feat: typed events #1981

merged 15 commits into from
Feb 6, 2023

Conversation

gavinbarron
Copy link
Member

@gavinbarron gavinbarron commented Dec 9, 2022

Closes #1689

PR Type

  • Feature

Description of the changes

Changes the package use to generate the custom-elements.json file used to build React components and tell Storybook about the web-components definitions.

A couple of thing to consider here. the format being used for the custom-elements.json is very different in v1.0 vs the experimental output we were previously using. The lit support is there, but currently there's no way to differentiate between properties of a class vs those properties which are decorated so that lit tracks them as reactive properties to trigger re-renders.

I've made a guess at how we should be doing this by settings conditions in the new version of generate.js which writes our react.ts file. The result now is that we see two new properties being added to the Get React component and the config property being removed from the Person component. IMO as the config is a static property it doesn't make much sense to have this exposed via a React Component as changing it on one component is changing it globally,

I'll need to test if React devs still have access to the static property on the MgtPerson class to ensure this is still usable.
WRT the response and error properties on Get, IMO these should probably be internal properties and private as I don't see them needing to be accessible from outside of the component.

PR checklist

  • Project builds (yarn build) and changes have been tested in at least two supported browsers (Edge + non-Chromium based browser)
  • All public APIs (classes, methods, etc) have been documented following the jsdoc syntax
  • Stories have been added and existing stories have been tested
  • Added appropriate documentation. Docs PR:
  • License header has been added to all new source files (yarn setLicense)
  • Contains NO breaking changes

Other information

Storybook still works. We should evaluate the data on the docs page between the current version and what this change provides.
If we decide that this is a useful feature the other fires jsdoc comments will need to be updated with typings

@ghost
Copy link

ghost commented Dec 9, 2022

Thank you for creating a Pull Request @gavinbarron.

This is a checklist for the PR reviewer(s) to complete before approving and merging this PR:

  • I have verified a documentation PR has been linked and is approved (or not applicable)
  • I have ran this PR locally and have tested the fix/feature
  • I have verified that stories have been added to storybook (or not applicable)
  • I have tested existing stories in storybook to verify no regression has occured
  • I have tested the solution in at least two browsers (Edge + 1 non-Chromium based browser)

Changes the package use to generate the custom-elements.json file used to build React components
and tell Storybook about the web-components definitions.
@github-actions
Copy link

The updated storybook is available here

@sebastienlevert
Copy link
Contributor

This is great! There is a lot of noise between attributes and properties (some are there twice), there are also private members that seem to be documented. CSS properties are amazing to be documented, I think if we could add some context (especially when it uses another css property as its default value) would be appreciated. Events are great and help a lot.

This also makes me thinks... Could we use this approach to document our permissions matrix? We do it on our docs, but it's not part of the code... Maybe it could be useful?

I feel this requires a LOT of comments changes but would allow our documentation to always be up-to-date. One thought : How do we make sure we don't duplicate work with what we have on https://aka.ms/mgt/docs? If we could identify ways to get the content and produce a Markdown table that we could automatically PR to the docs, it would be great.

@github-actions
Copy link

The updated storybook is available here

@gavinbarron
Copy link
Member Author

This is great! There is a lot of noise between attributes and properties (some are there twice), there are also private members that seem to be documented. CSS properties are amazing to be documented, I think if we could add some context (especially when it uses another css property as its default value) would be appreciated. Events are great and help a lot.

Attributes are the string inputs which map to properties, some of which convert from strings to other types, so the "duplication" is not unexpected or incorrect. Think of it this way, a developer working HTML + JavaScript can pass data via the attribute as a string, or if they get a reference to the DOM element, they can directly set the properties themselves. Developers using the React wrappers are directly setting the properties, so both have distinct value propositions.

Re: private and protected items, that's something I think I can address by processing the data when we pass it to Storybook. The underlying cause here is that Storybook takes the opinion that only genuinely private members, i.e. those starting with at #, should be excluded. storybookjs/storybook#15436

Good idea on the CSS properties, let me see what we can do.

This also makes me thinks... Could we use this approach to document our permissions matrix? We do it on our docs, but it's not part of the code... Maybe it could be useful?

This is an interesting idea. One that we should explore if we move forward with this tooling and restore the docs page to operation. I suspect it might need us to build a plugin for the custom elements manifest analyser

I feel this requires a LOT of comments changes but would allow our documentation to always be up-to-date. One thought : How do we make sure we don't duplicate work with what we have on https://aka.ms/mgt/docs? If we could identify ways to get the content and produce a Markdown table that we could automatically PR to the docs, it would be great.

For the events side of things it's work we 100% should do so that our event handlers have proper typings, not having those types available correctly in TypeScript is a miss on our part IMO.

We can use this tooling to generate markdown too! https://github.com/open-wc/custom-elements-manifest/tree/master/packages/to-markdown

@github-actions
Copy link

The updated storybook is available here

@github-actions
Copy link

The updated storybook is available here

@github-actions
Copy link

The updated storybook is available here

@github-actions
Copy link

The updated storybook is available here

@sebastienlevert
Copy link
Contributor

LGTM!

BREAKING CHANGE: moves event from a property of e.detail to be the value of e.detail
@gavinbarron gavinbarron changed the base branch from main to next/fluentui January 26, 2023 20:31
@gavinbarron gavinbarron dismissed sebastienlevert’s stale review January 26, 2023 20:31

The base branch was changed.

@gavinbarron
Copy link
Member Author

gavinbarron commented Jan 26, 2023

As there will be breaking changes in this it is being re-targeted to next/fluentui

#2005 will bring next/fluentui up to date with main and thus this PR is dependent on 2005

BREAKING CHANGE: all events for mgt-task now emit a CustomEvent<ITask>
@github-actions
Copy link

The updated storybook is available here

@github-actions
Copy link

The updated storybook is available here

@sebastienlevert
Copy link
Contributor

@gavinbarron should we bring back the Docs tab from Storybook as part of this PR?

@gavinbarron
Copy link
Member Author

@sebastienlevert YES! I thought it was in here, but I guess not, fixing that now.

@github-actions
Copy link

The updated storybook is available here

@sebastienlevert
Copy link
Contributor

I can't find the Docs with typed information on mgt-file-list (haven't check others) and we will need to hide the "Show code" option as it show the code for the monaco editor vs. MGT component. Also we had some Accessibility issues with the Docs tab, so let's make sure we factor those in (probably why we have hidden the tab at first).

@gavinbarron
Copy link
Member Author

Looks like there's an interaction between the disambiguation changes and the generation of the custom-elements.json file that is not working in our favor now...

@github-actions
Copy link

github-actions bot commented Feb 1, 2023

The updated storybook is available here

@gavinbarron
Copy link
Member Author

@sebastienlevert given the number of challenges with the docs page, I'm going to suggest that we leave it disabled in this PR and introduce another separate change to review that improvement separately as there are a lot of issues to resolve before we're ready for showtime with that feature

disable docs page again
set code pane content on agenda
disable ArgsTable on docs pages by default
show ArgsTable on base agenda stories
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

The updated storybook is available here

@gavinbarron gavinbarron enabled auto-merge (squash) February 2, 2023 21:04
@github-actions
Copy link

github-actions bot commented Feb 2, 2023

The updated storybook is available here

@gavinbarron gavinbarron enabled auto-merge (squash) February 6, 2023 16:30
@gavinbarron gavinbarron merged commit bbd5da4 into next/fluentui Feb 6, 2023
@gavinbarron gavinbarron deleted the feat/typed-events branch February 6, 2023 16:35
@github-actions
Copy link

github-actions bot commented Feb 6, 2023

The updated storybook is available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] Typing incomplete on Templates (TypeScript, React)
2 participants