Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Rex Dri
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Jerphanion
Rex Dri
Commits
9ea5c94b
Commit
9ea5c94b
authored
Mar 10, 2019
by
Florent Chehab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added __apiParam to CustomComponentForApi and History use this class now
parent
f744905f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
59 deletions
+40
-59
frontend/src/components/common/CustomComponentForAPI.js
frontend/src/components/common/CustomComponentForAPI.js
+6
-0
frontend/src/components/university/modules/common/History.js
frontend/src/components/university/modules/common/History.js
+34
-59
No files found.
frontend/src/components/common/CustomComponentForAPI.js
View file @
9ea5c94b
...
...
@@ -48,6 +48,10 @@ class CustomComponentForAPI extends Component {
// mapping should be : props_key => other_props_that contains the attribute to use
__apiAttr
=
null
;
// __apiParam should be an object
// mapping the prop that needs to be fetched to the parameter to be passed to the read function
__apiParam
=
null
;
constructor
(
props
)
{
super
(
props
);
...
...
@@ -175,6 +179,8 @@ class CustomComponentForAPI extends Component {
performReadFromApi
(
propName
)
{
if
(
this
.
__apiAttr
&&
this
.
__apiAttr
[
propName
])
{
this
.
props
.
api
[
propName
](
this
.
props
[
this
.
__apiAttr
[
propName
]]);
}
else
if
(
this
.
__apiParam
&&
this
.
__apiParam
[
propName
])
{
this
.
props
.
api
[
propName
](
this
.
__apiParam
[
propName
]);
}
else
{
this
.
props
.
api
[
propName
]();
}
...
...
frontend/src/components/university/modules/common/History.js
View file @
9ea5c94b
import
React
,
{
Component
}
from
"
react
"
;
import
React
from
"
react
"
;
import
{
openFullScreenDialog
,
closeFullScreenDialog
}
from
"
../../../../redux/actions/fullScreenDialog
"
;
import
PropTypes
from
"
prop-types
"
;
...
...
@@ -22,6 +22,7 @@ import Loading from "../../../common/Loading";
import
dateTimeStrToStr
from
"
../../../../utils/dateTimeStrToStr
"
;
import
editorStyle
from
"
../../editors/common/editorStyle
"
;
import
CustomComponentForAPI
from
"
../../../common/CustomComponentForAPI
"
;
import
getActions
from
"
../../../../redux/api/getActions
"
;
...
...
@@ -30,17 +31,25 @@ import getActions from "../../../../redux/api/getActions";
/**
* Component to display the previous versions of module
*
* TODO: check if we can use CustomComponentForAPI
*
* @class History
* @extends {Component}
*/
class
History
extends
C
omponent
{
class
History
extends
C
ustomComponentForAPI
{
// Store the version that is being viewed
state
=
{
versionInView
:
1
}
constructor
(
props
)
{
super
(
props
);
const
{
contentTypeId
,
id
}
=
props
.
modelInfo
;
// set the __apiAttr here so that we can read the correct data
this
.
__apiParam
=
{
versions
:
{
contentTypeId
,
id
}
};
}
/**
* Move to next or previous version with step
*
...
...
@@ -58,45 +67,7 @@ class History extends Component {
* @memberof History
*/
getVersions
()
{
if
(
!
this
.
props
.
versions
.
readSucceeded
.
readAt
)
{
return
[];
}
else
{
return
this
.
props
.
versions
.
readSucceeded
.
data
.
map
((
el
)
=>
{
return
el
.
data
;
});
// get the data inside the version
}
}
/**
* Get the information about the model from the props.
*
* @returns
* @memberof History
*/
getContentTypeAndId
()
{
const
{
contentTypeId
,
id
}
=
this
.
props
.
modelInfo
;
return
{
contentTypeId
,
id
};
}
/**
* Checks whether the versioned data is ready or not.
*
* @returns
* @memberof History
*/
dataIsReady
()
{
if
(
this
.
props
.
versions
.
isInvalidated
)
{
return
false
;
}
const
{
contentTypeId
,
id
}
=
this
.
getContentTypeAndId
(),
versions
=
this
.
getVersions
();
if
(
versions
.
length
===
0
)
{
return
false
;
}
const
lastVersion
=
versions
[
0
];
return
lastVersion
.
content_type_id
==
contentTypeId
&&
lastVersion
.
id
==
id
;
return
this
.
getLatestReadData
(
"
versions
"
).
map
((
el
)
=>
{
return
el
.
data
;
});
}
/**
...
...
@@ -106,6 +77,7 @@ class History extends Component {
* @memberof Editor
*/
componentDidMount
()
{
super
.
componentDidMount
();
this
.
forceUpdate
();
}
...
...
@@ -114,12 +86,8 @@ class History extends Component {
*
* @memberof History
*/
componentDidUpdate
()
{
// Load the data as necessary
if
(
!
this
.
dataIsReady
()
&&
!
this
.
props
.
versions
.
isLoading
)
{
const
{
contentTypeId
,
id
}
=
this
.
getContentTypeAndId
();
this
.
props
.
readVersions
(
contentTypeId
,
id
);
}
componentDidUpdate
(
prevProps
,
prevState
,
snapshot
)
{
super
.
componentDidUpdate
(
prevProps
,
prevState
,
snapshot
);
this
.
props
.
openFullScreenDialog
(
this
.
renderPanel
());
}
...
...
@@ -141,6 +109,10 @@ class History extends Component {
* @memberof History
*/
renderPanel
()
{
if
(
!
this
.
allApiDataIsReady
())
{
return
<
Loading
/>
;
}
const
{
classes
}
=
this
.
props
;
return
(
<>
...
...
@@ -168,13 +140,6 @@ class History extends Component {
* @memberof History
*/
renderHistory() {
if (this.props.versions.readFailed.failed) {
return <p>Nous sommes désolé, une erreur est survenue lors du chargement de l
'
historique
<
/p>
;
}
if
(
!
this
.
dataIsReady
())
{
return
<
Loading
/>
;
}
const { theme } = this.props,
versions = this.getVersions(),
activeStep = this.state.versionInView,
...
...
@@ -245,8 +210,17 @@ class History extends Component {
);
}
// Dumb render function for the component TODO remove ?
/**
* @override
*
* @returns
* @memberof History
*/
render
()
{
if
(
!
this
.
allApiDataIsReady
())
{
return
<><
/>
;
}
return
<><
/>
;
}
}
...
...
@@ -254,7 +228,6 @@ class History extends Component {
History
.
propTypes
=
{
classes
:
PropTypes
.
object
.
isRequired
,
editFromVersion
:
PropTypes
.
func
.
isRequired
,
readVersions: PropTypes.func.isRequired,
closeHistoryPanel
:
PropTypes
.
func
.
isRequired
,
resetVersions
:
PropTypes
.
func
.
isRequired
,
versions
:
PropTypes
.
object
.
isRequired
,
...
...
@@ -279,7 +252,9 @@ const mapStateToProps = (state) => {
const
mapDispatchToProps
=
(
dispatch
)
=>
{
return
{
readVersions: (contentTypeId, id) => dispatch(getActions("versions").readSpecific(`${contentTypeId}/${id}`)),
api
:
{
versions
:
(
param
)
=>
dispatch
(
getActions
(
"
versions
"
).
readSpecific
(
`
${
param
.
contentTypeId
}
/
${
param
.
id
}
`
)),
},
resetVersions
:
()
=>
dispatch
(
getActions
(
"
versions
"
).
setInvalidatedSpecific
(
true
)),
openFullScreenDialog
:
(
innerNodes
)
=>
dispatch
(
openFullScreenDialog
(
innerNodes
)),
closeFullScreenDialog
:
()
=>
dispatch
(
closeFullScreenDialog
()),
...
...
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