Skip to content

Commit

Permalink
Fred/Generators and Paperwork Refactor
Browse files Browse the repository at this point in the history
Added generator for React components, refactored Paperwork components
  • Loading branch information
kwfk authored and adowski committed Nov 25, 2019
1 parent 024a2a1 commit 4926e7d
Show file tree
Hide file tree
Showing 52 changed files with 6,027 additions and 973 deletions.
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const prettierOptions = JSON.parse(
module.exports = {
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/react'],
plugins: ['prettier', 'redux-saga', 'react', 'react-hooks', 'jsx-a11y'],
plugins: ['prettier', 'react', 'react-hooks', 'jsx-a11y'],
env: {
jest: true,
browser: true,
Expand Down Expand Up @@ -71,18 +71,18 @@ module.exports = {
'react/jsx-filename-extension': 0,
'react/jsx-no-target-blank': 0,
'react/jsx-uses-vars': 2,
'react/jsx-props-no-spreading': 0,
'react/prefer-stateless-function': 0,
'react/require-default-props': 0,
'react/require-extension': 0,
'react/self-closing-comp': 0,
'react/sort-comp': 0,
'redux-saga/no-yield-in-race': 2,
'redux-saga/yield-effects': 2,
'require-yield': 0,
},
settings: {
'import/resolver': {
webpack: {
config: './internals/webpack/webpack.prod.babel.js',
config: 'config/webpack/production.js',
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-debug.log*

# Ignore database.yml because it differs between OS
/config/database.yml

# Ignore vscode settings
.vscode/
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ internals/scripts/
package-lock.json
yarn.lock
package.json
vendor/
tmp/
storage/
spec/
public/
log/
lib/
db/
config/
bin/
.github/
2 changes: 0 additions & 2 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"processors": ["stylelint-processor-styled-components"],
"extends": [
"stylelint-config-recommended",
"stylelint-config-styled-components"
]
}
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Ruby syntax formatter
gem 'rubocop'
gem 'solargraph'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ GEM
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
backport (1.1.2)
bcrypt (3.1.13)
bindex (0.8.1)
bootsnap (1.4.5)
Expand Down Expand Up @@ -102,6 +103,7 @@ GEM
temple (>= 0.8.0)
tilt
hashie (3.6.0)
htmlentities (4.3.4)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.3)
Expand Down Expand Up @@ -242,6 +244,8 @@ GEM
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
reverse_markdown (1.3.0)
nokogiri
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-expectations (3.9.0)
Expand Down Expand Up @@ -287,6 +291,18 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
solargraph (0.37.2)
backport (~> 1.1)
bundler (>= 1.17.2)
htmlentities (~> 4.3, >= 4.3.4)
jaro_winkler (~> 1.5)
nokogiri (~> 1.9, >= 1.9.1)
parser (~> 2.3)
reverse_markdown (~> 1.0, >= 1.0.5)
rubocop (~> 0.52)
thor (~> 0.19, >= 0.19.4)
tilt (~> 2.0)
yard (~> 0.9)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -322,6 +338,7 @@ GEM
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
yard (0.9.20)
zeitwerk (2.2.0)

PLATFORMS
Expand All @@ -346,6 +363,7 @@ DEPENDENCIES
rspec-rails
rubocop
sass-rails (~> 5)
solargraph
spring
spring-watcher-listen (~> 2.0.0)
turbolinks (~> 5)
Expand Down
70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
# Unloop

## Technologies
* Ruby 2.5.6
* Rails 6.0.0
* Postgresql

## Installation
### Local Development
1. Clone the repo
```bash
git clone https://github.com/calblueprint/unloop.git
cd unloop
```
2. Install dependencies
```bash
bundle install
yarn install
```
3. Setup database
```bash
rails db:setup
# This runs db:create, db:schema:load, and db:seed
```

## Create React Components
### Generate Components
Functional components are components that are made of a function. You need to use hooks in order to use state or lifecycle methods. Most frequently used for components that are stateless but not always. Class components are components that use a class structure. This has been the standard format for React components.
```bash
yarn generate
```
You can also attach `functional` or `class` after generate to quickly specify which component to generate.
1. Do you want to wrap your component in React.memo?
* This adds memoization to the component. A rule of thumb to think about whether or not your component needs `memo` is if it
1. Renders the same thing given the same props
2. Renders often
3. Re-renders with the same props
4. Medium to big size
2. Do you want headers? (Only for containers)
* This changes the title tag and the meta tag for this page.
3. Do you want styles?
* This uses `withStyles` higher order component to add styles from `styles.js` to override Material UI default styles. Use `classes` in `className` to assign properties.
4. Do you want to load resources asynchronously?
* This adds React lazy and Suspense before importing. In order to use this, you need to import the Loadable file rather than the index file. This only works with importing on an existing React component, and doesn't work in Rails.
### After Generating
If your component is not a root for a page or shared component, move your component to the folder that matches the page or shared component that it will live under.
4 changes: 2 additions & 2 deletions app/javascript/channels/consumer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.

import { createConsumer } from "@rails/actioncable"
import { createConsumer } from '@rails/actioncable';

export default createConsumer()
export default createConsumer();
4 changes: 2 additions & 2 deletions app/javascript/channels/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.

const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
const channels = require.context('.', true, /_channel\.js$/);
channels.keys().forEach(channels);
152 changes: 81 additions & 71 deletions app/javascript/components/CaseNoteContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,80 +1,90 @@
import React from "react";
import { makeStyles } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import Typography from '@material-ui/core/Typography';
import Container from '@material-ui/core/Container';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import NewCaseNote from 'components/NewCaseNote';
import CaseNoteCard from 'components/CaseNoteCard';
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import Typography from '@material-ui/core/Typography';
import Container from '@material-ui/core/Container';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import NewCaseNote from 'components/NewCaseNote';
import CaseNoteCard from 'components/CaseNoteCard';

const styles = {
headerStyle: {
marginLeft: '20px',
marginTop: '0px',
fontSize: '24px',
}
}
headerStyle: {
marginLeft: '20px',
marginTop: '0px',
fontSize: '24px',
},
};

const classes = makeStyles(theme => ({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
},
const classes = makeStyles(theme => ({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
},
}));

class CaseNoteContainer extends React.Component {
constructor(props) {
super(props);
this.state = { 
case_notes: this.props.case_notes,
participant: this.props.participant
};
    }
class CaseNoteContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
case_notes: this.props.caseNotes,
participant: this.props.participant,
};
}

render() {
let participant_id = 1;
let case_note_cards = this.state.case_notes.map((case_note, index) => {
return (
<div key={index}>
<CaseNoteCard
title={case_note.title}
description={case_note.description}
internal={case_note.internal}
/>
</div>
);
});

    render () {
let participant_id = 1;
let case_note_cards = this.state.case_notes.map((case_note, index) => {
return <div key={index}>
<CaseNoteCard
title={case_note.title}
description={case_note.description}
internal = {case_note.internal}
/>
return (
<>
<CssBaseline />
<Container maxWidth="sm">
<Grid>
<Typography
component="div"
style={{ height: '100vh', maxHeight: '700px' }}
>
<div className={classes.root} style={{ paddingTop: '20px' }}>
<Grid container spacing={3}>
<Grid item xs={6}>
<h2 style={styles.headerStyle}>Casenotes</h2>
</Grid>
<Grid item xs={5}>
<NewCaseNote participantId={this.state.participant.id} />
</Grid>
</Grid>
<div
style={{
maxHeight: '80vh',
overflowX: 'hidden',
overflowY: 'auto',
height: '100vh',
}}
>
{case_note_cards}
</div>
}
);

return (
<React.Fragment>
<CssBaseline />
<Container maxWidth="sm">
<Grid>
<Typography component="div" style={{ backgroundColor'#F4F4F4', height'100vh', maxHeight: '700px'}}>
<div className={classes.root} style={{paddingTop: '20px'}}>
<Grid container spacing={3}>
<Grid item xs={6}>
<h2 style={styles.headerStyle}>Casenotes</h2>
</Grid>
<Grid item xs={5}>
<NewCaseNote participant_id={this.state.participant.id}/>
</Grid>
</Grid>
<div style={{ maxHeight: '80vh', overflowX: 'hidden', overflowY: 'auto', height: '100vh'}}>
{case_note_cards}
</div>
</div>
</Typography>
</Grid>
</Container>
</React.Fragment>
);
}
</div>
</Typography>
</Grid>
</Container>
</>
);
}
}

export default CaseNoteContainer;

export default CaseNoteContainer;
Loading

0 comments on commit 4926e7d

Please sign in to comment.