-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
build: support tsx components and storybook #1564
build: support tsx components and storybook #1564
Conversation
Add component story
[athens.views.right-sidebar :as right-sidebar] | ||
[devcards.core :refer [defcard-rg]] | ||
[re-frame.core :refer [dispatch]])) | ||
|
||
|
||
(defcard-rg Toggle | ||
[button {:primary true :on-click-fn #(dispatch [:right-sidebar/toggle])} "Toggle"]) | ||
[:> Button {:isPrimary true :on-click-fn #(dispatch [:right-sidebar/toggle])} "Toggle"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reagent will convert props in dash-chase into camelCase. So we can still keep using idiomatic property names in cljs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using :>
everywhere, we can also declare these components with reagent/adapt-react-class
somewhere. Not sure if it's worth the effort though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer dash-case.
I prefer :>
.
Reagent will convert it into camelCase automatically.
}, | ||
} | ||
|
||
const cssVars = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with Stuart how this is duplication of code in athens.style
, and how we could put it in a JS file and use it as the source of truth for both setups. Left it as is for now to reduce scope of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we want athens.style
to be CSS/JS in the future? Might be better for OSS devs and theme developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the whole of athens.style, but at least part of it yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah just the part that is all the CSS properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style generation for Storybook has been implemented in my current branch here, shanberg@dca0688, but is not yet used in the app.
Note for reviewers: most of the file changes in this PR are changing the require and usage of Button. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 question about build workflow.
@@ -238,6 +244,9 @@ jobs: | |||
mkdir -p ~/private_keys/ | |||
echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8 | |||
|
|||
- name: Compile components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason we compile components 3x?
Can't we cache the result of 1st complication and reuse in other 2 places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roughly the same reason we compile the app in those 3 places too: the are being used as a build step prior to the app build step, so whenever the app gets built the components should be built as well.
It should be possible to cache the results of the compilation, especially since the component compilation is simpler than the app compilation. But caching brings its own set of problems, like determining the cache invalidation policy (yarn.lock+all ts files for now, maybe different later), and I can't imagine it will bring any benefit since compiling the components is faster than restoring cache+storing cache for now.
So I don't really see a reason to use cache at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these components get served anywhere? Before, we could see devcards at contributor github pages at like username.github.io/athens/cards.html
. This is a great way to see contributor/PR components without building locally.
Our hypothetical athensresearch.github.io/athens/storybook.html
, could also host the official components/design system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They aren't served anywhere now, no. I think they can be built with yarn build-storybook
in this fashion. Afterwards they would need to be deployed.
For contributors to show them they'd also have to somehow deploy them to github pages though. How was that done before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another note: athensresearch.github.io is essentially a singleton for the master branch deployment, we can't deploy there until rtc is merged into master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For contributors to show them they'd also have to somehow deploy them to github pages though. How was that done before?
https://handbook.athensresearch.org/community/get-involved/setup#deploying-athens-and-devcards
Another note: athensresearch.github.io is essentially a singleton for the master branch deployment, we can't deploy there until rtc is merged into master.
That's a good point. Right now, Github pages are only updated when main is deployed via a tagged release.
In the past, I setup Actions so that contributors would update their GitHub pages whenever they pushed to any branch, not just when they pushed to their main. The problem here was that if they pushed to another branch, it would update. I even dynamically included their Git hash and linked to the GitHub commit in their GitHub pages Athens build. Actually, none of this worked out that well, and the easiest ended up being that I just added their fork as a remote and built it locally every time I was reviewing their PR. This should probably still be the workflow going forward for PR reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want a way to preview these changes via temporary deployment but not too sure how to do it now without involving some third party service.
Probably could deploy to GH pages under a branch name path. Then clean up that on merge? GH actions has a rich enough API to do that. Probably needs an ADR of it's own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with GH pages is it would only be able to serve one branch at a time. I feel like a service like Vercel could have a deploy for an arbitrary number of git hashes. This is too much overhead for most contributors, but I could seem it being more valuable when we have several people iterating on frontend code consistently.
For now, I think it's fine for all engineers to have remotes for one another. Building locally is another step of reproducibilty which can actually be helpful. Finally, modifying and hot-reloading code is something that a service deploy wouldn't allow for. Interacting with the code and application is gold for understanding it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WRT #1564 (comment), talked to Alex on standup and he prefer the faster build than the caching for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at questions.
Should we just get rid of devcards now?
Great work!
doc/adr/000x-js-components.md
Outdated
# X. JS Components | ||
|
||
Date: 2021-08-23 | ||
|
||
## Status | ||
|
||
Proposed. | ||
|
||
|
||
## Context | ||
|
||
Inspired by [David Nolen's ClojureScript in the Age of TypeScript](https://vouch.io/developing-mobile-digital-key-applications-with-clojurescript/) talk and post, we started thinking about how viable it would be to use JS (instead of CLJS) components. | ||
|
||
This change would provide design with a better and more familiar development environment for components and reduce their dependency on engineering to ship work. | ||
The separation also has several second order benefits related to organization and communication. | ||
|
||
Costs for this change are centered around the degree of separation between application and components, where cljs is the primary language on the former and js on the latter, and maintaining extra tooling. | ||
|
||
|
||
## Decision | ||
|
||
TBD | ||
|
||
|
||
## Consequences | ||
|
||
Negative consequences: | ||
* JS/CLJS context switching when working in the app and on components at the same time | ||
* Higher surface area for JS interop problems | ||
* More complex build step | ||
* More tooling to maintain | ||
* Harder for for CLJS engineers to develop and maintain components | ||
|
||
|
||
Positive consequences: | ||
* Better development and testing environment for components | ||
* Clearer defined deliverable scope and context for components | ||
* Component documentation | ||
* Smaller and simpler application codebase | ||
* Looser coupling between engineering and design | ||
* Design can deliver work on separate cadence, units, and timeline, from engineering | ||
* Easier to enforce discipline on components as pure functions | ||
* CLJS proficiency is not necessary for design work | ||
* Easier for contributors to contribute to components | ||
* Reduced bus factor in design |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating another pointer to our Hypotheses G Docs. ADRs capture the design of an architectural decision, some of the trade-offs, and some of the motivations, but could still be made more explicit in terms of the design of decision-making from an organizational point of view.
Perhaps we should link to the doc here? Fine if only privately accessible for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
}, | ||
} | ||
|
||
const cssVars = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we want athens.style
to be CSS/JS in the future? Might be better for OSS devs and theme developers.
@@ -238,6 +244,9 @@ jobs: | |||
mkdir -p ~/private_keys/ | |||
echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8 | |||
|
|||
- name: Compile components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these components get served anywhere? Before, we could see devcards at contributor github pages at like username.github.io/athens/cards.html
. This is a great way to see contributor/PR components without building locally.
Our hypothetical athensresearch.github.io/athens/storybook.html
, could also host the official components/design system.
.gitignore
Outdated
@@ -31,3 +31,6 @@ | |||
|
|||
# electron build | |||
dist | |||
|
|||
# design system ts output | |||
/src/js/components/**/*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, I my git is recognizing unstaged changes in /src/js/components/Button/Button.js
and /src/js/components/Button/Button.stories.js
. The diff is just different slightly differenent transpiled TS=>JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your version of git? Recursive glob support was only added in 1.8.2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.25.1. Can look into it and add my repro steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine now. But storybook-static/
code is being created. Do we want all these files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignored
21cf117
to
492f591
Compare
@tangjeff0 removed devcards, which removed a LOT of other stuff via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a project-level JS linter now that we are adding javascript, but in a separate PR. I'm noticing some inconsistencies regarding semi-colons and whitespace in the new JS files.
.gitignore
Outdated
@@ -31,3 +31,6 @@ | |||
|
|||
# electron build | |||
dist | |||
|
|||
# design system ts output | |||
/src/js/components/**/*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine now. But storybook-static/
code is being created. Do we want all these files?
@tangjeff0 we could add JS/TS linting, but that sounds like a non-blocking improvement. Do you agree, or do you think we need it from the get-go? |
[athens.views.modal :refer [modal-style]] | ||
[athens.views.textinput :as textinput] | ||
[cljsjs.react] | ||
[cljsjs.react.dom] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix in #1641, thanks for the catch!
No description provided.