-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/tasks #18
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
Merged
Merged
Feature/tasks #18
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac2625e
setup for exercise
Leenday b5e821c
adds a js_routes
Leenday 7dbd67e
display tasks
Leenday ca9a390
Add a component ColumnHeader, disable rule in propTypes and create ra…
Leenday af5b2ab
Add an dragging feature cards and update
Leenday 90f129c
Add a popup window, rework sort for tasks and add a feature to add tasks
Leenday 98ba6b9
Add a edit popup window, destroy/edit features for cards
Leenday cab0328
changes after review
Leenday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { pick, propOr } from 'ramda'; | ||
|
|
||
| export default { | ||
| defaultAttributes(attributes) { | ||
| return { | ||
| name: '', | ||
| description: '', | ||
| ...attributes, | ||
| }; | ||
| }, | ||
|
|
||
| attributesToSubmit(task) { | ||
| const pertmittedKeys = ['id', 'name', 'description']; | ||
|
|
||
| return { | ||
| ...pick(pertmittedKeys, task), | ||
| assigneeId: propOr(null, 'id', task.assignee), | ||
| authorId: propOr(null, 'id', task.author), | ||
| }; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import React, { useState } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { has } from 'ramda'; | ||
|
|
||
| import Button from '@material-ui/core/Button'; | ||
| import Card from '@material-ui/core/Card'; | ||
| import CardActions from '@material-ui/core/CardActions'; | ||
| import CardContent from '@material-ui/core/CardContent'; | ||
| import CardHeader from '@material-ui/core/CardHeader'; | ||
| import CloseIcon from '@material-ui/icons/Close'; | ||
| import IconButton from '@material-ui/core/IconButton'; | ||
| import Modal from '@material-ui/core/Modal'; | ||
| import TextField from '@material-ui/core/TextField'; | ||
|
|
||
| import TaskForm from 'forms/TaskForm'; | ||
|
|
||
| import useStyles from './useStyles'; | ||
|
|
||
| function AddPopup({ onClose, onCardCreate }) { | ||
| const [task, changeTask] = useState(TaskForm.defaultAttributes()); | ||
| const [isSaving, setSaving] = useState(false); | ||
| const [errors, setErrors] = useState({}); | ||
| const handleCreate = () => { | ||
| setSaving(true); | ||
|
|
||
| onCardCreate(task).catch((error) => { | ||
| setSaving(false); | ||
| setErrors(error || {}); | ||
|
|
||
| if (error instanceof Error) { | ||
| alert(`Creation Failed! Error: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
| const handleChangeTextField = (fieldName) => (event) => changeTask({ ...task, [fieldName]: event.target.value }); | ||
| const styles = useStyles(); | ||
|
|
||
| return ( | ||
| <Modal className={styles.modal} open onClose={onClose}> | ||
| <Card className={styles.root}> | ||
| <CardHeader | ||
| action={ | ||
| <IconButton onClick={onClose}> | ||
| <CloseIcon /> | ||
| </IconButton> | ||
| } | ||
| title="Add New Task" | ||
| /> | ||
| <CardContent> | ||
| <div className={styles.form}> | ||
| <TextField | ||
| error={has('name', errors)} | ||
| helperText={errors.name} | ||
| onChange={handleChangeTextField('name')} | ||
| value={task.name} | ||
| label="Name" | ||
| required | ||
| margin="dense" | ||
| /> | ||
| <TextField | ||
| error={has('description', errors)} | ||
| helperText={errors.description} | ||
| onChange={handleChangeTextField('description')} | ||
| value={task.description} | ||
| label="Description" | ||
| required | ||
| margin="dense" | ||
| /> | ||
| </div> | ||
| </CardContent> | ||
| <CardActions className={styles.actions}> | ||
| <Button disabled={isSaving} onClick={handleCreate} variant="contained" size="small" color="primary"> | ||
| Add | ||
| </Button> | ||
| </CardActions> | ||
| </Card> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| AddPopup.propTypes = { | ||
| onClose: PropTypes.func.isRequired, | ||
| onCardCreate: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default AddPopup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import AddPopup from './AddPopup'; | ||
|
|
||
| export default AddPopup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { makeStyles } from '@material-ui/core/styles'; | ||
|
|
||
| const useStyles = makeStyles(() => ({ | ||
| modal: { | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| outline: 0, | ||
| }, | ||
|
|
||
| root: { | ||
| width: 465, | ||
| }, | ||
|
|
||
| actions: { | ||
| display: 'flex', | ||
| justifyContent: 'right', | ||
| }, | ||
|
|
||
| form: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| }, | ||
| })); | ||
|
|
||
| export default useStyles; |
53 changes: 53 additions & 0 deletions
53
app/javascript/packs/components/ColumnHeader/ColumnHeader.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| import IconButton from '@material-ui/core/IconButton'; | ||
| import SystemUpdateAltIcon from '@material-ui/icons/SystemUpdateAlt'; | ||
|
|
||
| import useStyles from './useStyles'; | ||
|
|
||
| function ColumnHeader({ column, onLoadMore }) { | ||
| const styles = useStyles(); | ||
|
|
||
| const { | ||
| id, | ||
| title, | ||
| cards, | ||
| meta: { totalCount, currentPage, totalPages }, | ||
| } = column; | ||
|
|
||
| const count = cards.length; | ||
|
|
||
| const handleLoadMore = () => onLoadMore(id, currentPage + 1); | ||
|
|
||
| return ( | ||
| <div className={styles.root}> | ||
| <div className={styles.title}> | ||
| <b>{title}</b> ({count}/{totalCount || '…'}) | ||
| </div> | ||
| <div className={styles.actions}> | ||
| {currentPage >= totalPages ? null : ( | ||
| <IconButton aria-label="Load more" onClick={() => handleLoadMore()}> | ||
| <SystemUpdateAltIcon fontSize="small" /> | ||
| </IconButton> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| ColumnHeader.propTypes = { | ||
| column: PropTypes.shape({ | ||
| id: PropTypes.string, | ||
| title: PropTypes.string, | ||
| cards: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), | ||
| meta: PropTypes.shape({ | ||
| totalCount: PropTypes.number, | ||
| currentPage: PropTypes.number, | ||
| totalPages: PropTypes.number, | ||
| }), | ||
| }), | ||
| onLoadMore: PropTypes.func, | ||
| }; | ||
|
|
||
| export default ColumnHeader; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import ColumnHeader from './ColumnHeader'; | ||
|
|
||
| export default ColumnHeader; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { makeStyles } from '@material-ui/core/styles'; | ||
|
|
||
| const useStyles = makeStyles(() => ({ | ||
| root: { | ||
| height: 42, | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| }, | ||
| })); | ||
|
|
||
| export default useStyles; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import React, { useEffect, useState } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { isNil } from 'ramda'; | ||
|
|
||
| import Button from '@material-ui/core/Button'; | ||
| import Card from '@material-ui/core/Card'; | ||
| import CardActions from '@material-ui/core/CardActions'; | ||
| import CardContent from '@material-ui/core/CardContent'; | ||
| import CircularProgress from '@material-ui/core/CircularProgress'; | ||
| import CardHeader from '@material-ui/core/CardHeader'; | ||
| import CloseIcon from '@material-ui/icons/Close'; | ||
| import IconButton from '@material-ui/core/IconButton'; | ||
| import Modal from '@material-ui/core/Modal'; | ||
|
|
||
| import Form from './components/Form'; | ||
|
|
||
| import useStyles from './useStyles'; | ||
|
|
||
| function EditPopup({ cardId, onClose, onCardDestroy, onCardLoad, onCardUpdate }) { | ||
| const [task, setTask] = useState(null); | ||
| const [isSaving, setSaving] = useState(false); | ||
| const [errors, setErrors] = useState({}); | ||
| const styles = useStyles(); | ||
|
|
||
| useEffect(() => { | ||
| onCardLoad(cardId).then(setTask); | ||
| }, []); | ||
|
|
||
| const handleCardUpdate = () => { | ||
| setSaving(true); | ||
|
|
||
| onCardUpdate(task).catch((error) => { | ||
| setSaving(false); | ||
| setErrors(error || {}); | ||
|
|
||
| if (error instanceof Error) { | ||
| alert(`Update Failed! Error: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const handleCardDestroy = () => { | ||
| setSaving(true); | ||
|
|
||
| onCardDestroy(task).catch((error) => { | ||
| setSaving(false); | ||
|
|
||
| alert(`Destrucion Failed! Error: ${error.message}`); | ||
| }); | ||
| }; | ||
| const isLoading = isNil(task); | ||
|
|
||
| return ( | ||
| <Modal className={styles.modal} open onClose={onClose}> | ||
| <Card className={styles.root}> | ||
| <CardHeader | ||
| action={ | ||
| <IconButton onClick={onClose}> | ||
| <CloseIcon /> | ||
| </IconButton> | ||
| } | ||
| title={isLoading ? 'Your task is loading. Please be patient.' : `Task # ${task.id} [${task.name}]`} | ||
| /> | ||
| <CardContent> | ||
| {isLoading ? ( | ||
| <div className={styles.loader}> | ||
| <CircularProgress /> | ||
| </div> | ||
| ) : ( | ||
| <Form errors={errors} onChange={setTask} task={task} /> | ||
| )} | ||
| </CardContent> | ||
| <CardActions className={styles.actions}> | ||
| <Button disabled={isLoading || isSaving} onClick={handleCardUpdate} size="small" variant="contained" color="primary"> | ||
| Update | ||
| </Button> | ||
| <Button | ||
| disabled={isLoading || isSaving} | ||
| onClick={handleCardDestroy} | ||
| size="small" | ||
| variant="contained" | ||
| color="secondary" | ||
| > | ||
| Destroy | ||
| </Button> | ||
| </CardActions> | ||
| </Card> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| EditPopup.propTypes = { | ||
| cardId: PropTypes.number.isRequired, | ||
| onClose: PropTypes.func.isRequired, | ||
| onCardDestroy: PropTypes.func.isRequired, | ||
| onCardLoad: PropTypes.func.isRequired, | ||
| onCardUpdate: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default EditPopup; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Без этого, не создаются таски из-за отсутствия айди автора:
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.
мы же передаем author_id
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.
Мб я что-то пропустил.
В логах при создании таски вот такие параметры:
В следующем блоке точно передаются, если из селекта выбрать автора, а в противном случае тоже nil.
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.
странно 🤔 ну ладно