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
meskio
cicer
Commits
5df2fe71
Commit
5df2fe71
authored
Jan 31, 2021
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Use price editor on product prices
parent
7471a700
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EditableCell.js
+16
-6
16 additions, 6 deletions
src/EditableCell.js
src/ProductList.js
+3
-5
3 additions, 5 deletions
src/ProductList.js
with
19 additions
and
11 deletions
src/EditableCell.js
+
16
−
6
View file @
5df2fe71
import
React
,
{
useState
}
from
"
react
"
;
import
{
Form
}
from
"
react-bootstrap
"
;
import
{
printMoney
}
from
"
./util
"
;
import
PriceEditor
from
"
./PriceEditor
"
;
function
EditableCell
(
props
)
{
const
[
data
,
setData
]
=
useState
(
props
.
value
);
const
[
editing
,
setEditing
]
=
useState
(
false
);
let
value
=
props
.
value
;
if
(
props
.
price
)
{
value
=
printMoney
(
props
.
value
);
}
if
(
props
.
ro
||
!
editing
)
{
return
<
td
onClick
=
{()
=>
setEditing
(
true
)}
>
{
props
.
value
}
<
/td>
;
return
<
td
onClick
=
{()
=>
setEditing
(
true
)}
>
{
value
}
<
/td>
;
}
const
submit
=
(
e
)
=>
{
...
...
@@ -18,11 +24,15 @@ function EditableCell(props) {
return
(
<
td
>
<
Form
onSubmit
=
{
submit
}
>
{
props
.
price
?
(
<
PriceEditor
value
=
{
data
}
onChange
=
{(
price
)
=>
setData
(
price
)}
/
>
)
:
(
<
Form
.
Control
value
=
{
data
}
onChange
=
{(
e
)
=>
setData
(
e
.
target
.
value
)}
onBlur
=
{()
=>
setEditing
(
false
)}
/
>
)}
<
/Form
>
<
/td
>
);
...
...
This diff is collapsed.
Click to expand it.
src/ProductList.js
+
3
−
5
View file @
5df2fe71
...
...
@@ -4,7 +4,7 @@ import Fetcher from "./Fetcher";
import
EditableCell
from
"
./EditableCell
"
;
import
ProductAdder
from
"
./ProductAdder
"
;
import
AuthContext
from
"
./AuthContext
"
;
import
{
printMoney
,
url
}
from
"
./util
"
;
import
{
url
}
from
"
./util
"
;
class
ProductList
extends
React
.
Component
{
static
contextType
=
AuthContext
;
...
...
@@ -34,9 +34,6 @@ class ProductList extends React.Component {
case
"
stock
"
:
value
=
parseInt
(
value
);
break
;
case
"
price
"
:
value
=
value
*
100
;
break
;
default
:
break
;
}
...
...
@@ -127,8 +124,9 @@ class ProductList extends React.Component {
/
>
<
EditableCell
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
price
"
,
v
)}
value
=
{
printMoney
(
product
.
price
)
}
value
=
{
product
.
price
}
ro
=
{
!
isAdmin
}
price
/>
<
EditableCell
onChange
=
{(
v
)
=>
this
.
update
(
row
,
"
stock
"
,
v
)}
...
...
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