Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ICAT
Datahub
Commits
07341f89
Commit
07341f89
authored
Aug 31, 2020
by
Loic Huder
Browse files
Merge branch 'new-item-route' into 'master'
Updated item routes with itemId as parameter See merge request
!429
parents
e38590bd
76b2f2e1
Pipeline
#32381
passed with stages
in 9 minutes and 57 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/components/Items/ItemForm.js
View file @
07341f89
...
...
@@ -39,7 +39,9 @@ function ItemForm(props) {
<
Panel
bsStyle
=
{
bsStyle
}
>
<
Panel
.
Body
>
<
FormProvider
{...
methods
}
>
{
item
&&
<
input
name
=
"
_id
"
type
=
"
hidden
"
ref
=
{
register
}
/>
}
{
item
&&
item
.
_id
&&
(
<
input
name
=
"
_id
"
type
=
"
hidden
"
ref
=
{
register
}
/
>
)}
<
TextFieldGroup
registerOptions
=
{{
required
:
true
}}
name
=
"
name
"
...
...
src/components/Items/ItemTable.js
View file @
07341f89
...
...
@@ -42,13 +42,13 @@ function ItemTable(props) {
const
editItem
=
useFetcher
(
ItemResource
.
updateShape
());
const
deleteItem
=
useFetcher
(
ItemResource
.
deleteShape
());
const
[
isCreatingItem
,
setCreatingItem
]
=
useState
(
false
);
const
[
editedItem
,
setEditedItem
]
=
useState
();
const
onSubmitForm
=
isCreatingItem
?
createItem
:
editItem
;
const
onClosingForm
=
isCreatingItem
?
()
=>
setCreatingItem
(
false
)
:
()
=>
setEditedItem
(
undefined
);
const
onSubmitForm
=
editedItem
&&
editedItem
.
_id
?
(
params
,
body
)
=>
editItem
({
...
params
,
_id
:
editedItem
.
_id
},
body
)
:
createItem
;
const
onClosingForm
=
()
=>
setEditedItem
(
undefined
);
const
samples
=
useResource
(
SampleResource
.
listShape
(),
{
investigationId
});
const
columns
=
[
...
...
@@ -148,10 +148,11 @@ function ItemTable(props) {
onClick
=
{
async
()
=>
{
try
{
setAlert
(
undefined
);
await
deleteItem
(
{
investigationId
,
parcelId
},
{
_id
:
item
.
_id
}
);
await
deleteItem
({
investigationId
,
parcelId
,
_id
:
item
.
_id
,
});
onItemChange
();
setAlert
({
type
:
'
success
'
,
message
:
'
Item removed.
'
});
}
catch
(
error
)
{
...
...
@@ -173,7 +174,7 @@ function ItemTable(props) {
];
return
(
<
Grid
fluid
>
{
isParcelEditable
&&
(
isCreatingItem
||
editedItem
)
&&
(
{
isParcelEditable
&&
editedItem
&&
(
<
Row
>
<
ItemForm
item
=
{
editedItem
}
...
...
@@ -212,9 +213,7 @@ function ItemTable(props) {
icon
:
'
plus
'
,
disabled
:
!
isParcelEditable
,
bsStyle
:
'
primary
'
,
onClick
:
()
=>
{
setCreatingItem
(
true
);
},
onClick
:
()
=>
setEditedItem
({}),
},
]}
/
>
...
...
src/resources/item.js
View file @
07341f89
...
...
@@ -21,17 +21,17 @@ export default class ItemResource extends Resource {
static
url
(
params
)
{
const
{
sessionId
}
=
store
.
getState
().
user
;
const
{
investigationId
,
parcelId
}
=
params
;
return
`
${
ICATPLUS
.
server
}
/tracking/
${
sessionId
}
/investigation/id/
${
investigationId
}
/parcel/id/
${
parcelId
}
/item`
;
}
static
listUrl
(
params
)
{
return
this
.
url
(
params
);
return
`
${
ICATPLUS
.
server
}
/tracking/
${
sessionId
}
/investigation/id/
${
investigationId
}
/parcel/id/
${
parcelId
}
/item/
${
this
.
pk
(
params
)}
`
;
}
static
deleteShape
()
{
return
{
...
super
.
deleteShape
(),
fetch
:
(
params
,
body
)
=>
this
.
fetch
(
'
delete
'
,
this
.
url
(
params
),
body
),
};
static
listUrl
(
params
)
{
const
{
sessionId
}
=
store
.
getState
().
user
;
const
{
investigationId
,
parcelId
}
=
params
;
return
`
${
ICATPLUS
.
server
}
/tracking/
${
sessionId
}
/investigation/id/
${
investigationId
}
/parcel/id/
${
parcelId
}
/item`
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment