Skip to content

Commit

Permalink
Merge pull request #2 from aviemet/prod_ready
Browse files Browse the repository at this point in the history
Prod ready
  • Loading branch information
aviemet authored Jun 11, 2024
2 parents 29fe522 + 6ecf7e4 commit f0ca699
Show file tree
Hide file tree
Showing 271 changed files with 5,283 additions and 3,476 deletions.
107 changes: 61 additions & 46 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,94 +1,109 @@
module.exports = {
'env': {
'browser': true,
'node': true,
env: {
browser: true,
node: true,
},
'extends': [
extends: [
'plugin:react/recommended',
'plugin:import/typescript',
'plugin:@tanstack/eslint-plugin-query/recommended',
'plugin:storybook/recommended',
'plugin:react-hooks/recommended',
],
'plugins': ['react', '@typescript-eslint', 'import'],
'settings': {
plugins: ['react', '@typescript-eslint', 'import'],
settings: {
react: {
version: 'detect',
},
'import/resolver': {
'typescript': {},
},
},
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaFeatures': {
'jsx': true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
'ecmaVersion': 'latest',
'requireConfigFile': false,
ecmaVersion: 'latest',
sourceType: 'module',
requireConfigFile: false,
},
'ignorePatterns': ['app/frontend/types/**/*', 'app/javascript/**/*'],
'rules': {
'indent': 'off',
ignorePatterns: ['app/javascript/**/*'],
rules: {
indent: 'off',
'@typescript-eslint/indent': ['error', 'tab', {
'SwitchCase': 1,
'VariableDeclarator': 'first',
'MemberExpression': 1,
'ArrayExpression': 1,
SwitchCase: 1,
VariableDeclarator: 'first',
MemberExpression: 1,
ArrayExpression: 1,
ignoredNodes: ['TSTypeParameterInstantiation'],
}],
'@typescript-eslint/member-delimiter-style': ['error', {
'multiline': {
'delimiter': 'none',
multiline: {
delimiter: 'none',
},
'singleline': {
'delimiter': 'comma',
singleline: {
delimiter: 'comma',
},
'multilineDetection': 'brackets',
multilineDetection: 'brackets',
}],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'never'],
quotes: ['error', 'single'],
semi: ['error', 'never'],
'no-unused-vars': ['warn', {
'vars': 'all',
'args': 'none',
vars: 'all',
args: 'none',
}],
'no-prototype-builtins': [0],
'space-infix-ops': ['error'],
'no-trailing-spaces': 'error',
'object-curly-spacing': [2, 'always', {
'objectsInObjects': true,
objectsInObjects: true,
}],
'computed-property-spacing': 2,
'array-bracket-spacing': 0,
'brace-style': ['error', '1tbs', {
'allowSingleLine': true,
allowSingleLine: true,
}],
'react/boolean-prop-naming': ['error'],
'react/no-typos': ['error'],
'react/jsx-curly-spacing': ['error', {
'when': 'always',
'children': true,
when: 'always',
children: true,
}],
// 'react/jsx-space-before-closing': 2,
'react/jsx-tag-spacing': ['error', {
'closingSlash': 'never',
'beforeSelfClosing': 'always',
'afterOpening': 'never',
'beforeClosing': 'allow',
closingSlash: 'never',
beforeSelfClosing: 'always',
afterOpening: 'never',
beforeClosing: 'allow',
}],
'react/display-name': ['off'],
'react/prop-types': 0,
'eqeqeq': 'error',
eqeqeq: 'error',
'no-console': 'warn',
'eol-last': ['error', 'always'],
'@typescript-eslint/keyword-spacing': [2, {
'after': true,
'before': true,
'overrides': {
'if': { 'after': false },
'for': { 'after': false },
'while': { 'after': false },
'switch': { 'after': false },
'catch': { 'after': false },
after: true,
before: true,
overrides: {
if: { after: false },
for: { after: false },
while: { after: false },
switch: { after: false },
catch: { after: false },
},
}],
'comma-dangle': ['error', 'always-multiline'],
'react-hooks/exhaustive-deps': 0,
},
overrides: [
{
files: ['*.d.ts'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/indent': 'off',
},
},
],
}
4 changes: 2 additions & 2 deletions app/controllers/api/controls_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def create
end
end

# @route PATCH /api/controls/:slug (api_control)
# @route PUT /api/controls/:slug (api_control)
# @route PATCH /api/controls/:id (api_control)
# @route PUT /api/controls/:id (api_control)
def update
if control.save
render json: control.render, status: :created
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/api/protocols_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
class Api::ProtocolsController < ApplicationController
expose :protocols, -> { Protocol.includes_associated.all }
expose :protocol
expose :protocols, -> { Protocol.all }

# @route GET /api/protocols/:slug (api_protocol)
def show
authorize protocol
render json: protocol.render(view: :show), status: :ok
end

# @route GET /api/options/protocols (api_protocols_options)
def options
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/controls_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class ControlsController < ApplicationController
# @route POST /controls (controls)
def create
authorize Control.new
ap({ control: })
if control.save
redirect_to control, notice: "Control was successfully created."
redirect_to edit_screen_path(control.screen), notice: "Control was successfully created."
else
redirect_to new_control_path, inertia: { errors: control.errors }
end
Expand All @@ -18,8 +19,9 @@ def create
# @route PUT /controls/:id (control)
def update
authorize control

if control.update(control_params)
redirect_to control, notice: "Control was successfully updated."
redirect_to edit_screen_path(control.screen), inertia: { method: :get }, notice: "Control was successfully updated."
else
redirect_to edit_control_path, inertia: { errors: control.errors }
end
Expand All @@ -35,10 +37,10 @@ def destroy
private

def sortable_fields
%w(title type screen_id position min_value max_value value protocol_id).freeze
%w(title type screen_id min_value max_value value protocol_id).freeze
end

def control_params
params.require(:control).permit(:title, :type, :screen_id, :position, :min_value, :max_value, :value, :protocol_id)
params.require(:control).permit(:title, :control_type, :order, :color, :screen_id, :min_value, :max_value, :value, :protocol_id)
end
end
13 changes: 7 additions & 6 deletions app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class ProtocolsController < ApplicationController
include Searchable

expose :protocols, -> { search(Protocol.includes_associated, sortable_fields) }
expose :protocols, -> { search(Protocol, sortable_fields) }
expose :protocol, id: -> { params[:slug] }, scope: -> { Protocol.includes_associated }, find_by: :slug

# @route GET /protocols (protocols)
def index
authorize protocols

paginated_protocols = protocols.page(params[:page] || 1)

render inertia: "Protocols/Index", props: {
Expand All @@ -18,7 +19,7 @@ def index
}
end

# @route GET /protocols/:id (protocol)
# @route GET /protocols/:slug (protocol)
def show
authorize protocol
render inertia: "Protocols/Show", props: {
Expand All @@ -34,7 +35,7 @@ def new
}
end

# @route GET /protocols/:id/edit (edit_protocol)
# @route GET /protocols/:slug/edit (edit_protocol)
def edit
authorize protocol

Expand All @@ -53,8 +54,8 @@ def create
end
end

# @route PATCH /protocols/:id (protocol)
# @route PUT /protocols/:id (protocol)
# @route PATCH /protocols/:slug (protocol)
# @route PUT /protocols/:slug (protocol)
def update
authorize protocol

Expand All @@ -72,7 +73,7 @@ def update
end
end

# @route DELETE /protocols/:id (protocol)
# @route DELETE /protocols/:slug (protocol)
def destroy
authorize protocol
protocol.destroy!
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/screens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def edit
authorize screen

render inertia: "Screens/Edit", props: {
screen: -> { screen.render(view: :edit) },
screen: screen.render(view: :edit),
screens: -> { Screen.all.render(view: :options) },
}
end
Expand All @@ -49,10 +49,12 @@ def create
# @route PATCH /screens/:slug (screen)
# @route PUT /screens/:slug (screen)
def update
ap({ params:, screen_params: })
authorize screen
if screen.update(screen_params)
redirect_to screen, notice: "Screen was successfully updated."
else
ap({ errors: screen.errors })
redirect_to edit_screen_path, inertia: { errors: screen.errors }
end
end
Expand All @@ -71,6 +73,8 @@ def sortable_fields
end

def screen_params
params.require(:screen).permit(:title, :order)
params.require(:screen).permit(:title, :order, controls_attributes: [
:id, :title, :order
],)
end
end
4 changes: 2 additions & 2 deletions app/frontend/Components/Button/EditButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import { Link } from '@/Components'
import { EditIcon } from '@/Components/Icons'
import { ILinkProps } from '../Link'
import { LinkProps } from '../Link'

interface IEditButtonProps extends Omit<ILinkProps, 'children'> {
interface IEditButtonProps extends Omit<LinkProps, 'children'> {
label?: string
}

Expand Down
62 changes: 0 additions & 62 deletions app/frontend/Components/Button/ModalFormButton.tsx

This file was deleted.

7 changes: 5 additions & 2 deletions app/frontend/Components/Button/ToggleColorSchemeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react'
import { ActionIcon, useComputedColorScheme, useMantineColorScheme } from '@mantine/core'
import { ActionIcon, type ActionIconProps, useComputedColorScheme, useMantineColorScheme } from '@mantine/core'
import { SunIcon, MoonIcon } from '@/Components/Icons'

const ToggleColorSchemeButton = () => {
interface ToggleColorSchemeButtonProps extends ActionIconProps {}

const ToggleColorSchemeButton = (props: ToggleColorSchemeButtonProps) => {
const { colorScheme, setColorScheme } = useMantineColorScheme()
const computedColorScheme = useComputedColorScheme('dark')

Expand All @@ -17,6 +19,7 @@ const ToggleColorSchemeButton = () => {
title="Toggle color scheme"
style={ { display: 'inline-flex' } }
aria-label={ `Toggle color scheme to ${colorScheme === 'dark' ? 'light' : 'dark'} mode` }
{ ...props }
>
{ colorScheme === 'dark' ? <SunIcon size={ 18 } /> : <MoonIcon size={ 18 } /> }
</ActionIcon>
Expand Down
Loading

0 comments on commit f0ca699

Please sign in to comment.