Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cicer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quique
cicer
Commits
8703cc73
Commit
8703cc73
authored
Oct 23, 2020
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Be able to delete products
parent
98d4eb2b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ProductList.js
+35
-6
35 additions, 6 deletions
src/ProductList.js
with
35 additions
and
6 deletions
src/ProductList.js
+
35
−
6
View file @
8703cc73
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Table
,
Alert
}
from
"
react-bootstrap
"
;
import
{
Table
,
Button
,
Alert
}
from
"
react-bootstrap
"
;
import
Fetcher
from
"
./Fetcher
"
;
import
Fetcher
from
"
./Fetcher
"
;
import
EditableCell
from
"
./EditableCell
"
;
import
EditableCell
from
"
./EditableCell
"
;
import
AuthContext
from
"
./AuthContext
"
;
import
AuthContext
from
"
./AuthContext
"
;
...
@@ -49,6 +49,24 @@ class ProductList extends React.Component {
...
@@ -49,6 +49,24 @@ class ProductList extends React.Component {
});
});
}
}
delProduct
(
code
)
{
let
products
=
this
.
state
.
products
;
const
index
=
products
.
findIndex
((
p
)
=>
p
.
code
===
code
);
products
.
splice
(
index
,
1
);
this
.
setState
({
products
});
fetch
(
"
/api/product/
"
+
code
,
{
headers
:
{
"
x-authentication
"
:
this
.
context
.
token
},
method
:
"
DELETE
"
,
}).
then
((
response
)
=>
{
if
(
!
response
.
ok
)
{
this
.
setState
({
error
:
response
.
status
.
toString
()
+
"
"
+
response
.
statusText
,
});
}
});
}
render
()
{
render
()
{
let
alert
=
null
;
let
alert
=
null
;
if
(
this
.
state
.
error
!==
null
)
{
if
(
this
.
state
.
error
!==
null
)
{
...
@@ -59,30 +77,40 @@ class ProductList extends React.Component {
...
@@ -59,30 +77,40 @@ class ProductList extends React.Component {
);
);
}
}
const
isAdmin
=
this
.
context
.
role
!
==
"
admin
"
;
const
isAdmin
=
this
.
context
.
role
=
==
"
admin
"
;
const
entries
=
this
.
state
.
products
.
map
((
product
,
row
)
=>
{
const
entries
=
this
.
state
.
products
.
map
((
product
,
row
)
=>
{
return
(
return
(
<
tr
key
=
{
product
.
code
}
>
<
tr
key
=
{
product
.
code
}
>
<
EditableCell
<
EditableCell
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
code
"
,
v
)}
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
code
"
,
v
)}
value
=
{
product
.
code
}
value
=
{
product
.
code
}
ro
=
{
isAdmin
}
ro
=
{
!
isAdmin
}
/
>
/
>
<
EditableCell
<
EditableCell
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
name
"
,
v
)}
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
name
"
,
v
)}
value
=
{
product
.
name
}
value
=
{
product
.
name
}
ro
=
{
isAdmin
}
ro
=
{
!
isAdmin
}
/
>
/
>
<
EditableCell
<
EditableCell
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
price
"
,
v
)}
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
price
"
,
v
)}
value
=
{
printMoney
(
product
.
price
)}
value
=
{
printMoney
(
product
.
price
)}
ro
=
{
isAdmin
}
ro
=
{
!
isAdmin
}
/
>
/
>
<
EditableCell
<
EditableCell
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
stock
"
,
v
)}
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
stock
"
,
v
)}
value
=
{
product
.
stock
}
value
=
{
product
.
stock
}
ro
=
{
isAdmin
}
ro
=
{
!
isAdmin
}
/
>
/
>
{
isAdmin
&&
(
<
td
sm
=
{
1
}
>
<
Button
variant
=
"
danger
"
onClick
=
{()
=>
this
.
delProduct
(
product
.
code
)}
>
-
<
/Button
>
<
/td
>
)}
<
/tr
>
<
/tr
>
);
);
});
});
...
@@ -100,6 +128,7 @@ class ProductList extends React.Component {
...
@@ -100,6 +128,7 @@ class ProductList extends React.Component {
<
th
>
Nombre
<
/th
>
<
th
>
Nombre
<
/th
>
<
th
>
Precio
<
/th
>
<
th
>
Precio
<
/th
>
<
th
>
Existencias
<
/th
>
<
th
>
Existencias
<
/th
>
{
isAdmin
&&
<
th
sm
=
{
1
}
><
/th>
}
<
/tr
>
<
/tr
>
<
/thead
>
<
/thead
>
<
tbody
>
{
entries
}
<
/tbody
>
<
tbody
>
{
entries
}
<
/tbody
>
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment