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

build: support tsx components and storybook #1564

Merged
merged 22 commits into from
Sep 8, 2021

Conversation

filipesilva
Copy link
Collaborator

No description provided.

@filipesilva filipesilva requested review from neotyk and shanberg August 19, 2021 17:52
[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"])
Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.
@filipesilva filipesilva requested a review from tangjeff0 August 23, 2021 15:37
@filipesilva filipesilva marked this pull request as ready for review August 23, 2021 15:37
},
}

const cssVars = `
Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@shanberg shanberg Sep 4, 2021

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.

@filipesilva
Copy link
Collaborator Author

Note for reviewers: most of the file changes in this PR are changing the require and usage of Button.

Copy link
Collaborator

@neotyk neotyk left a 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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

@tangjeff0 tangjeff0 Sep 3, 2021

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!

Copy link
Collaborator Author

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.

Copy link
Collaborator

@tangjeff0 tangjeff0 left a 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!

Comment on lines 1 to 45
# 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

},
}

const cssVars = `
Copy link
Collaborator

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.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
project.clj Outdated Show resolved Hide resolved
@@ -238,6 +244,9 @@ jobs:
mkdir -p ~/private_keys/
echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8

- name: Compile components
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ignored

@filipesilva
Copy link
Collaborator Author

@tangjeff0 removed devcards, which removed a LOT of other stuff via carve.

Copy link
Collaborator

@tangjeff0 tangjeff0 left a 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.

src/cljs/athens/devcards.cljs Outdated Show resolved Hide resolved
src/cljs/athens/devcards/style_guide.cljs Show resolved Hide resolved
src/js/components/Button/Button.tsx Show resolved Hide resolved
src/cljsjs/create_react_class.cljs Show resolved Hide resolved
src/cljs/athens/views/buttons.cljs Show resolved Hide resolved
src/cljs/athens/views/filters.cljs Show resolved Hide resolved
.gitignore Outdated
@@ -31,3 +31,6 @@

# electron build
dist

# design system ts output
/src/js/components/**/*.js
Copy link
Collaborator

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?

@filipesilva
Copy link
Collaborator Author

@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?

@tangjeff0 tangjeff0 merged commit 925f7a4 into athensresearch:feature/rtc-v1 Sep 8, 2021
[athens.views.modal :refer [modal-style]]
[athens.views.textinput :as textinput]
[cljsjs.react]
[cljsjs.react.dom]
Copy link
Contributor

@juniusfree juniusfree Sep 9, 2021

Choose a reason for hiding this comment

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

The removal of cljsjs.react.dom resulted in error. This is when adding a new db.
image

Copy link
Collaborator Author

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!

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.

5 participants