Skip to content

Commit

Permalink
Add Prettier
Browse files Browse the repository at this point in the history
I haven't examined every single change. It's mostly single-quotes,
trailing commas, and indentation/linebreaking. A few places in
calculator.ts where parentheses were added:

```typescript
const c = something as string || '';
// becomes
const c = (something as string) || '';
```

This doesn't seem quite right to me -- I think it should just be
`something ?? ''`, or `(something ?? '') as OtherType` -- but I wanted
to keep this PR mechanical.

It turns out Prettier is also smart enough to prettify HTML and CSS
within template literals, which is very cool.
  • Loading branch information
oyamauchi committed Aug 3, 2023
1 parent d84e94c commit 82da305
Show file tree
Hide file tree
Showing 23 changed files with 1,063 additions and 740 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build products
build
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid",
"printWidth": 80
}
85 changes: 45 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
Takes functionality from our [public website calculator](https://www.rewiringamerica.org/app/ira-calculator) and packages it up in a custom web component built using `lit`. Lit's `Task` library takes care of watching the form parameters for changes
and fetching data from our API.

__Note:__ API keys are required, sign up on our [API homepage](https://www.rewiringamerica.org/api).
**Note:** API keys are required, sign up on our [API homepage](https://www.rewiringamerica.org/api).

# Documentation

* [Embed usage](https://api.rewiringamerica.org/docs/v0/embed)
* [Calculator examples](https://glitch.com/~rewiring-america-calculator-widget)
- [Embed usage](https://api.rewiringamerica.org/docs/v0/embed)
- [Calculator examples](https://glitch.com/~rewiring-america-calculator-widget)

# Development

* `yarn` to install dependencies
* `yarn serve:widget` and open `http://localhost:1234/` to start working - should refresh when files change
* Open `http://localhost:1234/working-copy.html` to test against the dev API service
* `yarn build:widget` to build the deployment artifacts (Vercel does this for production deploys)
- `yarn` to install dependencies
- `yarn serve:widget` and open `http://localhost:1234/` to start working - should refresh when files change
- Open `http://localhost:1234/working-copy.html` to test against the dev API service
- `yarn build:widget` to build the deployment artifacts (Vercel does this for production deploys)

# Styles

Expand All @@ -30,47 +30,52 @@ This site is deployed using the [embed-rewiring-america](https://vercel.com/rewi
# TODO

Features and content:
* [x] Add remaining guidance and disclaimer copy for <80% and >150% AMI.
* [ ] Add reset button to form?
* [ ] Switch order of incentives depending on whether credits/rebates are more useful.
* [x] Add currency formatting to the income input element. Using [autonumeric](http://autonumeric.org), which is large.
* [ ] Consider [Inputmask](https://robinherbots.github.io/Inputmask/#/documentation/numeric) in future.
* [x] Use a better tooltip component to ensure tooltips are readable at mobile breakpoints. Trying Shoelace's [tooltip](https://shoelace.style/components/tooltip).
* [ ] Think about how the 'back to calculator' links should work on RA's detail pages ([example](https://www.rewiringamerica.org/app/ira-calculator/information/electrical-panel))
* [ ] Add analytics support (Amplitude events?)
* [ ] Add support for Spanish translations.
* [ ] Send javascript events for calculate, results, project details clicks.

- [x] Add remaining guidance and disclaimer copy for <80% and >150% AMI.
- [ ] Add reset button to form?
- [ ] Switch order of incentives depending on whether credits/rebates are more useful.
- [x] Add currency formatting to the income input element. Using [autonumeric](http://autonumeric.org), which is large.
- [ ] Consider [Inputmask](https://robinherbots.github.io/Inputmask/#/documentation/numeric) in future.
- [x] Use a better tooltip component to ensure tooltips are readable at mobile breakpoints. Trying Shoelace's [tooltip](https://shoelace.style/components/tooltip).
- [ ] Think about how the 'back to calculator' links should work on RA's detail pages ([example](https://www.rewiringamerica.org/app/ira-calculator/information/electrical-panel))
- [ ] Add analytics support (Amplitude events?)
- [ ] Add support for Spanish translations.
- [ ] Send javascript events for calculate, results, project details clicks.

Robustness:
* [x] Take a copy of fonts and serve them from this domain.
* [ ] Port to API v1's calculator endpoint.
* [ ] Add slots to allow customizing the form intro text.
* [x] Add UI tests with Cypress, run in CI.
* [ ] Add unit tests, run in CI.
* [ ] How do we handle versioning?
* [ ] Work with Zuplo to add `origin` configs to API keys and prevent use of API keys outside specific hosts.
* [ ] Generate types (and API client?) automatically from OpenAPI file.
* [x] Protect main branch, require PRs.

- [x] Take a copy of fonts and serve them from this domain.
- [ ] Port to API v1's calculator endpoint.
- [ ] Add slots to allow customizing the form intro text.
- [x] Add UI tests with Cypress, run in CI.
- [ ] Add unit tests, run in CI.
- [ ] How do we handle versioning?
- [ ] Work with Zuplo to add `origin` configs to API keys and prevent use of API keys outside specific hosts.
- [ ] Generate types (and API client?) automatically from OpenAPI file.
- [x] Protect main branch, require PRs.

Optimizations:
* [ ] Add support for caching results in localStorage.
* [ ] Add support for showing default list of incentives (from `/api/v0/incentives`).
* [ ] Reuse microcopy from Rewiring America's CMS to avoid duplication between this repo and our website.

- [ ] Add support for caching results in localStorage.
- [ ] Add support for showing default list of incentives (from `/api/v0/incentives`).
- [ ] Reuse microcopy from Rewiring America's CMS to avoid duplication between this repo and our website.

Roadmap:
* [ ] Open source?
* [ ] Do we need a way to filter the kinds of incentives offered?
* [ ] Query by address for v1?
* [ ] Respond to customer requests for customization/functionality.

- [ ] Open source?
- [ ] Do we need a way to filter the kinds of incentives offered?
- [ ] Query by address for v1?
- [ ] Respond to customer requests for customization/functionality.

Bugs:
* [ ] Clicking the tooltip for Household Income should focus the input. Do we need `delegatesFocus` or do we need to refactor the input into a slot so it's light DOM?
* [ ] Tapping the tooltip on mobile probably shouldn't select the field. Move outside the label maybe?

- [ ] Clicking the tooltip for Household Income should focus the input. Do we need `delegatesFocus` or do we need to refactor the input into a slot so it's light DOM?
- [ ] Tapping the tooltip on mobile probably shouldn't select the field. Move outside the label maybe?

# References

* [Lit](https://lit.dev)
* [Lit Task](https://github.com/lit/lit/tree/main/packages/labs/task)
* [Rewiring America API](https://api.rewiringamerica.org/docs/)
* [BEM](https://getbem.com/introduction/)
* [Shoelace](https://shoelace.style)
- [Lit](https://lit.dev)
- [Lit Task](https://github.com/lit/lit/tree/main/packages/labs/task)
- [Rewiring America API](https://api.rewiringamerica.org/docs/)
- [BEM](https://getbem.com/introduction/)
- [Shoelace](https://shoelace.style)
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "cypress";
import { defineConfig } from 'cypress';

export default defineConfig({
projectId: "4uypg2",
projectId: '4uypg2',
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
Expand Down
7 changes: 4 additions & 3 deletions cypress/e2e/calculator.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ describe('template spec', () => {
cy.get('rewiring-america-calculator').should('exist');
// FIXME: is there a way to do this less repetitively?
// Doing const shadow = cy.get(...).shadow() didn't seem to work.
cy.get('rewiring-america-calculator').shadow()
cy.get('rewiring-america-calculator')
.shadow()
.contains('Upfront Discounts')
.siblings()
.contains('$14,000');
Expand All @@ -21,5 +22,5 @@ describe('template spec', () => {
cy.get('rewiring-america-calculator')
.shadow()
.contains('Covers up to 50% of costs');
})
})
});
});
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
// }
4 changes: 2 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:widget": "parcel build --target default",
"serve:widget": "parcel serve ./src/*.html --dist-dir build",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
"cypress:run": "cypress run",
"lint": "prettier --check ."
},
"browserslist": {
"production": [
Expand All @@ -33,6 +34,7 @@
"parcel": "v2.8.3",
"postcss": "^8.4.21",
"postcss-modules": "^6.0.0",
"prettier": "^2.8.8",
"typescript": "^4.9.5"
},
"main": "dist/calculator.js",
Expand Down
Loading

0 comments on commit 82da305

Please sign in to comment.