Verified Commit 5f1a54c3 authored by Florent Chehab's avatar Florent Chehab
Browse files

fix(front): restored pending moderation

* can now moderate again
* display pending moderation data correctly

Closes  #183
parent d2e97741
...@@ -42,6 +42,14 @@ class Editor extends React.Component { ...@@ -42,6 +42,14 @@ class Editor extends React.Component {
props.subscribeToModuleWrapper(this); props.subscribeToModuleWrapper(this);
} }
componentDidMount() {
const { saveOnMount } = this.props;
// handle moderation request
if (saveOnMount) {
this.performSave(this.parseRawModelData(this.props.rawModelData));
}
}
/** /**
* Function that extracts the modelData from the raw one. * Function that extracts the modelData from the raw one.
* *
...@@ -234,7 +242,7 @@ Editor.propTypes = { ...@@ -234,7 +242,7 @@ Editor.propTypes = {
lastUpdateTimeInModel: PropTypes.string, lastUpdateTimeInModel: PropTypes.string,
hasPendingModeration: PropTypes.bool, hasPendingModeration: PropTypes.bool,
saveData: PropTypes.func.isRequired, saveData: PropTypes.func.isRequired,
saveOnMount: PropTypes.bool.isRequired, // should we save the data on editor mount (useful when trying to moderate)
Form: PropTypes.func.isRequired, // Components with the fields Form: PropTypes.func.isRequired, // Components with the fields
formLevelErrors: PropTypes.array, formLevelErrors: PropTypes.array,
license: PropTypes.string, license: PropTypes.string,
......
...@@ -14,6 +14,7 @@ import withNetworkWrapper, { ...@@ -14,6 +14,7 @@ import withNetworkWrapper, {
NetWrapParam NetWrapParam
} from "../../hoc/withNetworkWrapper"; } from "../../hoc/withNetworkWrapper";
import { useApiInvalidateAll } from "../../hooks/wrappers/api"; import { useApiInvalidateAll } from "../../hooks/wrappers/api";
import useOnComponentUnMount from "../../hooks/useOnComponentUnMount";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
editButton: { editButton: {
...@@ -71,7 +72,6 @@ function PendingModeration({ ...@@ -71,7 +72,6 @@ function PendingModeration({
api, api,
modelInfo, modelInfo,
pendingModeration, pendingModeration,
moderatePendingModeration,
editFromPendingModeration, editFromPendingModeration,
renderTitle, renderTitle,
renderCore, renderCore,
...@@ -79,9 +79,9 @@ function PendingModeration({ ...@@ -79,9 +79,9 @@ function PendingModeration({
}) { }) {
const resetData = useApiInvalidateAll("pendingModerationObj"); const resetData = useApiInvalidateAll("pendingModerationObj");
useEffect(() => { useOnComponentUnMount(() => {
return () => resetData(); resetData();
}, []); });
// keep the component up to date // keep the component up to date
useEffect(() => { useEffect(() => {
...@@ -89,14 +89,15 @@ function PendingModeration({ ...@@ -89,14 +89,15 @@ function PendingModeration({
}, [modelInfo]); }, [modelInfo]);
const pendingModelData = useMemo(() => { const pendingModelData = useMemo(() => {
const pending = pendingModeration[0];
return { return {
...pendingModeration.new_object, ...pending.new_object,
id: pendingModeration.object_id id: pending.object_id
}; };
}, [pendingModeration]); }, [pendingModeration]);
const moderate = useCallback(() => { const moderate = useCallback(() => {
moderatePendingModeration(pendingModelData); editFromPendingModeration(pendingModelData, true); // open editor and auto save
}, [pendingModelData]); }, [pendingModelData]);
const editFromPending = useCallback(() => { const editFromPending = useCallback(() => {
...@@ -127,9 +128,8 @@ PendingModeration.propTypes = { ...@@ -127,9 +128,8 @@ PendingModeration.propTypes = {
id: PropTypes.number.isRequired id: PropTypes.number.isRequired
}).isRequired, }).isRequired,
editFromPendingModeration: PropTypes.func.isRequired, editFromPendingModeration: PropTypes.func.isRequired,
moderatePendingModeration: PropTypes.func.isRequired,
userCanModerate: PropTypes.bool.isRequired, userCanModerate: PropTypes.bool.isRequired,
pendingModeration: PropTypes.object.isRequired, pendingModeration: PropTypes.array.isRequired,
renderTitle: PropTypes.func.isRequired, renderTitle: PropTypes.func.isRequired,
renderCore: PropTypes.func.isRequired, renderCore: PropTypes.func.isRequired,
api: getApiPropTypes("pendingModeration").isRequired api: getApiPropTypes("pendingModeration").isRequired
......
...@@ -105,8 +105,6 @@ function ModuleWrapper({ ...@@ -105,8 +105,6 @@ function ModuleWrapper({
id: rawModelData.id id: rawModelData.id
}} }}
editFromPendingModeration={openEditorTmp} editFromPendingModeration={openEditorTmp}
// TODO Repare pending moderation validation
moderatePendingModeration={() => {}}
userCanModerate={rawModelData.obj_info.user_can_moderate} userCanModerate={rawModelData.obj_info.user_can_moderate}
/> />
); );
......
...@@ -13,7 +13,7 @@ import useEditorState from "./wrappers/useEditorState"; ...@@ -13,7 +13,7 @@ import useEditorState from "./wrappers/useEditorState";
*/ */
function useEditor(formInfo, onClose = () => {}) { function useEditor(formInfo, onClose = () => {}) {
// Returns a callback that opens an editor correctly configured // Returns a callback that opens an editor correctly configured
return useCallback(modelData => { return useCallback((modelData, saveOnMount = false) => {
const { route, license, Form, formLevelErrors } = formInfo; const { route, license, Form, formLevelErrors } = formInfo;
const InternalEditor = React.memo(() => { const InternalEditor = React.memo(() => {
...@@ -33,6 +33,7 @@ function useEditor(formInfo, onClose = () => {}) { ...@@ -33,6 +33,7 @@ function useEditor(formInfo, onClose = () => {}) {
rawModelData={modelData} rawModelData={modelData}
// state api related // state api related
saveData={saveData} saveData={saveData}
saveOnMount={saveOnMount}
clearSaveError={clearSaveError} clearSaveError={clearSaveError}
savingHasError={savingHasError} savingHasError={savingHasError}
lastUpdateTimeInModel={lastUpdateTimeInModel} lastUpdateTimeInModel={lastUpdateTimeInModel}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment