mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-25 18:13:52 +03:00
Simplified updating of entity.
This commit is contained in:
parent
35fd055fdb
commit
a2c7f7252d
@ -12,12 +12,12 @@ export const add = ({= entityLowerName =}) => ({
|
||||
|
||||
/**
|
||||
* @param {String} id
|
||||
* @param {{= entity.name =}} updated{= entity.name =}
|
||||
* @param {Object} data - Partial data that will be merged with existing {= entityLowerName =}.
|
||||
*/
|
||||
export const update = (id, updated{= entity.name =}) => ({
|
||||
export const update = (id, data) => ({
|
||||
type: types.UPDATE,
|
||||
id,
|
||||
data: updated{= entity.name =}.toData()
|
||||
data
|
||||
})
|
||||
|
||||
/**
|
||||
|
@ -30,13 +30,6 @@ export class {= listName =} extends React.Component {
|
||||
{= entityBeingEditedStateVar =}: null
|
||||
}
|
||||
|
||||
update{= entityName =} = (data, {= entityLowerName =}) => {
|
||||
const updated{= entityName =} = new {= entityClassName =}(
|
||||
{ ...{= entityLowerName =}.toData(), ...data }
|
||||
)
|
||||
this.props.update{= entityName =}({= entityLowerName =}.id, updated{= entityName =})
|
||||
}
|
||||
|
||||
setAsBeingEdited = {= entityLowerName =} => this.setState({
|
||||
{= entityBeingEditedStateVar =}: {= entityLowerName =}.id
|
||||
})
|
||||
@ -56,7 +49,7 @@ export class {= listName =} extends React.Component {
|
||||
{=& render =}
|
||||
{=/ render =}
|
||||
{=/ listFields =}
|
||||
|
||||
|
||||
render() {
|
||||
const {= entityLowerName =}ListToShow = this.props.filter ?
|
||||
{=! TODO(matija): duplication, we could extract entityLowerName_List =}
|
||||
@ -88,8 +81,8 @@ export class {= listName =} extends React.Component {
|
||||
'aria-label': 'checkbox'
|
||||
}}
|
||||
disabled={!this.props.editable}
|
||||
onChange={e => this.update{= entityName =}(
|
||||
{ '{= name =}': e.target.checked }, {= entityLowerName =}
|
||||
onChange={e => this.props.update{= entityName =}(
|
||||
{= entityLowerName =}.id, { '{= name =}': e.target.checked }
|
||||
)}
|
||||
/>
|
||||
</TableCell>
|
||||
@ -102,8 +95,8 @@ export class {= listName =} extends React.Component {
|
||||
{this.props.editable && this.isBeingEdited({= entityLowerName =}) ? (
|
||||
<TextField
|
||||
value={{= entityLowerName =}.{= name =}}
|
||||
onChange={e => this.update{= entityName =}(
|
||||
{ '{= name =}': e.target.value }, {= entityLowerName =}
|
||||
onChange={e => this.props.update{= entityName =}(
|
||||
{= entityLowerName =}.id, { '{= name =}': e.target.value }
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
|
@ -25,7 +25,10 @@ const reducer = (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
all: state.all.map(
|
||||
{= entityLowerName =} => {= entityLowerName =}.id === action.id ? action.data : {= entityLowerName =}
|
||||
{= entityLowerName =} =>
|
||||
{= entityLowerName =}.id === action.id
|
||||
? { ...{= entityLowerName =}, ...action.data }
|
||||
: {= entityLowerName =}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,7 @@ export default class Todo extends React.Component {
|
||||
|
||||
toggleIsDoneForAllTasks = () => {
|
||||
const areAllDone = this.props.taskList.every(t => t.isDone)
|
||||
{/* TODO: This feels clumsy / complicated. Is there a better way than using id (maybe not)?
|
||||
Should we consider passing just data to update, not the whole object, so we don't have to
|
||||
create new object here? Maybe we can change this update, or have a second update method. */}
|
||||
this.props.taskList.map(
|
||||
(t) => this.props.updateTask(t.id, new Task ({ ...t.toData(), isDone: !areAllDone }))
|
||||
)
|
||||
this.props.taskList.map(t => this.props.updateTask(t.id, { isDone: !areAllDone }))
|
||||
}
|
||||
|
||||
deleteCompletedTasks = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user