Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fwf 3620 History part implemented #2307

Merged
1 change: 1 addition & 0 deletions forms-flow-web/src/actions/actionConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const ACTION_CONSTANTS = {
IS_FORM_PROCESS_STATUS_LOAD_ERROR: "IS_FORM_PROCESS_STATUS_LOAD_ERROR",
FORM_PROCESS_LIST: "FORM_PROCESS_LIST",
WORKFLOW_ASSOCIATION_CHANGED: "WORKFLOW_ASSOCIATION_CHANGED",
PROCESS_HISTORY: "PROCESS_HISTORY",
//Application
LIST_APPLICATIONS: "LIST_APPLICATIONS",
LIST_APPLICATIONS_OF_FORM: "LIST_APPLICATIONS_OF_FORM",
Expand Down
6 changes: 6 additions & 0 deletions forms-flow-web/src/actions/processActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ export const setIsPublicDiagram = (data) => (dispatch) => {
});
};

export const setProcessHistories = (historyData) => (dispatch) => {
dispatch({
type: ACTION_CONSTANTS.PROCESS_HISTORY,
payload:historyData,
});
};
export const setSubflowCount = (data) => (dispatch) => {
dispatch({
type: ACTION_CONSTANTS.SET_SUBFLOW_COUNT,
Expand Down
1 change: 1 addition & 0 deletions forms-flow-web/src/apiManager/endpoints/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const API = {
PUBLISH: `${WEB_BASE_URL}/form/<mapper_id>/publish`,
UN_PUBLISH: `${WEB_BASE_URL}/form/<mapper_id>/unpublish`,
FORM_HISTORY: `${WEB_BASE_URL}/form/form-history`,
PROCESS_HISTORY: `${WEB_BASE_URL}/process`,
Ajay-aot marked this conversation as resolved.
Show resolved Hide resolved
LANG_UPDATE: `${WEB_BASE_URL}/user/locale`,
FORM_PROCESSES: `${WEB_BASE_URL}/form/formid`,
GET_BPM_TASKS: `${BPM_BASE_URL_EXT}/v1/task`,
Expand Down
8 changes: 6 additions & 2 deletions forms-flow-web/src/apiManager/services/FormServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ export const formUpdate = (form_id,formData) => {
return RequestService.httpPUTRequest(`${API.FORM_DESIGN}/${form_id}`, formData);
};

export const getFormHistory = (form_id) => {
return RequestService.httpGETRequest(`${API.FORM_HISTORY}/${form_id}`);
export const getFormHistory = (form_id, page = null, limit = null) => {
let url = `${API.FORM_HISTORY}/${form_id}`;
if (page !== null && limit !== null) {
url += `?pageNo=${page}&limit=${limit}`;
}
return RequestService.httpGETRequest(url);
};


Expand Down
13 changes: 13 additions & 0 deletions forms-flow-web/src/apiManager/services/processServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,16 @@ export const deleteFormProcessMapper = (mapperId, ...rest) => {
});
};
};

export const getProcessHistory = (process_key, page = null, limit = null) => {
let url = `${API.PROCESS_HISTORY}/${process_key}/versions`;
Ajay-aot marked this conversation as resolved.
Show resolved Hide resolved
if (page !== null && limit !== null) {
url += `?pageNo=${page}&limit=${limit}`;
}
return RequestService.httpGETRequest(url);
};

export const fetchRevertingProcessData = (process_Id) => {
let url = `${API.PROCESS_HISTORY}/${process_Id}`;
Ajay-aot marked this conversation as resolved.
Show resolved Hide resolved
return RequestService.httpGETRequest(url);
};
6 changes: 2 additions & 4 deletions forms-flow-web/src/components/Form/EditForm/FlowEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import { toast } from 'react-toastify';
import { createXMLFromModeler, validateProcessNames, compareXML } from '../../../helper/processHelper.js';
import { ERROR_LINTING_CLASSNAME } from '../../Modeler/constants/bpmnModelerConstants.js';

const FlowEdit = forwardRef((_, ref) => {
const FlowEdit = forwardRef(({ handleHistory, CategoryType }, ref) => {
const { t } = useTranslation();
const dispatch = useDispatch();
const bpmnRef = useRef();
const processData = useSelector((state) => state.process?.processData);
const [lintErrors, setLintErrors] = useState([]);
const [historyModalShow, setHistoryModalShow] = useState(false);
const [savingFlow, setSavingFlow] = useState(false);
const [showDiscardModal, setShowDiscardModal] = useState(false);
// handle history modal
const handleHistoryModal = () => setHistoryModalShow(!historyModalShow);
const handleHanldeDisacardModal = () => setShowDiscardModal(!showDiscardModal);
//validate any erros in bpmn lint
const validateBpmnLintErrors = () => {
Expand Down Expand Up @@ -120,7 +118,7 @@ const FlowEdit = forwardRef((_, ref) => {
size="md"
icon={<HistoryIcon />}
label={t("History")}
onClick={handleHistoryModal}
onClick={() => handleHistory(CategoryType.WORKFLOW)}
dataTestid="flow-history-button-testid"
ariaLabel={t("Flow History Button")}
/>
Expand Down
151 changes: 139 additions & 12 deletions forms-flow-web/src/components/Form/EditForm/FormEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
HistoryIcon,
PreviewIcon,
FormBuilderModal,
HistoryModal,
} from "@formsflow/components";
import { RESOURCE_BUNDLES_DATA } from "../../../resourceBundles/i18n";
import LoadingOverlay from "react-loading-overlay-ts";
Expand All @@ -31,6 +32,7 @@ import {
formCreate,
publish,
unPublish,
getFormHistory,
} from "../../../apiManager/services/FormServices";
import utils from "@aot-technologies/formiojs/lib/utils";
import {
Expand All @@ -39,13 +41,19 @@ import {
setRestoreFormData,
setRestoreFormId,
setFormDeleteStatus,
setFormHistories,
} from "../../../actions/formActions";
import {
saveFormProcessMapperPut,
getProcessDetails,
unPublishForm,
getProcessHistory,
fetchRevertingProcessData
} from "../../../apiManager/services/processServices";
import { setProcessData } from "../../../actions/processActions.js";
import {
setProcessData,
setProcessHistories,
} from "../../../actions/processActions.js";
import _isEquial from "lodash/isEqual";
import _ from "lodash";
import SettingsModal from "../../Modals/SettingsModal";
Expand All @@ -67,12 +75,15 @@ const Edit = React.memo(() => {
const dispatch = useDispatch();
const { formId } = useParams();
const { t } = useTranslation();
//this variable handle the flow and layot tab switching
//this variable handle the flow and layot tab switching
const sideTabRef = useRef(null);

/* ------------------------------- mapper data ------------------------------ */
const { formProcessList: processListData, formPreviousData: previousData } =
useSelector((state) => state.process);
const {
processHistoryData = {},
formProcessList: processListData,
formPreviousData: previousData,
} = useSelector((state) => state.process);

/* -------------------------------- user data and form access data ------------------------------- */
const {
Expand Down Expand Up @@ -105,9 +116,11 @@ const Edit = React.memo(() => {
/* ------------------------- form history variables ------------------------- */
const [isNewVersionLoading, setIsNewVersionLoading] = useState(false);
const [restoreFormDataLoading, setRestoreFormDataLoading] = useState(false);
const { restoredFormData, restoredFormId } = useSelector(
(state) => state.formRestore
);
const {
formHistoryData = {},
restoredFormData,
restoredFormId,
} = useSelector((state) => state.formRestore);

/* -------------------------- getting process data -------------------------- */
const [isProcessDetailsLoading, setIsProcessDetailsLoading] = useState(false);
Expand All @@ -128,6 +141,12 @@ const Edit = React.memo(() => {
(state) => state.process?.applicationCount
);

const processHistory = processHistoryData.processHistory || [];
const formHistory = formHistoryData.formHistory || [];
const pageNo = 1;
const limit = 4;
const [history, setHistory] = useState(true);
const [showHistoryModal, setshowHistoryModal] = useState(false);
const [showConfirmModal, setShowConfirmModal] = useState(false);
const [modalType, setModalType] = useState("");

Expand Down Expand Up @@ -156,7 +175,6 @@ const Edit = React.memo(() => {
setFormSubmitted(false);
}
};

useEffect(() => {
if (restoredFormId) {
setRestoreFormDataLoading(true);
Expand Down Expand Up @@ -186,6 +204,38 @@ const Edit = React.memo(() => {
};
}, [restoredFormId]);

const fetchRestoredFormData = (restoredFormId) => {
if (restoredFormId) {
fetchFormById(restoredFormId)
.then((res) => {
if (res.data) {
const { data } = res;
dispatch(setRestoreFormData(res.data));
Ajay-aot marked this conversation as resolved.
Show resolved Hide resolved
dispatchFormAction({
type: "components",
value: _cloneDeep(data.components),
});
dispatchFormAction({ type: "type", value: data.type });
dispatchFormAction({ type: "display", value: data.display });
}
})
.catch((err) => {
toast.error(err.response.data);
});
}

const cleanup = () => {
dispatch(setRestoreFormData({}));
dispatch(setRestoreFormId(null));
};

return cleanup;
};

useEffect(() => {
fetchRestoredFormData(restoredFormId);
}, [restoredFormId]);

useEffect(() => {
if (processListData.processKey) {
setIsProcessDetailsLoading(true);
Expand Down Expand Up @@ -360,9 +410,69 @@ const Edit = React.memo(() => {
const backToForm = () => {
dispatch(push(`${redirectUrl}form/`));
};
const closeHistoryModal = () => {
setshowHistoryModal(false);
};
const fetchFormHistory = (parentFormId, page, limit) => {
getFormHistory(parentFormId, page, limit)
.then((res) => {
dispatch(setFormHistories(res.data));
})
.catch(() => {
setFormHistories([]);
});
};

const fetchProcessHistory = (processKey, page, limit) => {
getProcessHistory(processKey, page, limit)
.then((res) => {
dispatch(setProcessHistories(res.data));
})
.catch(() => {
setProcessHistories([]);
});
};
const handleHistory = (type) => {
setshowHistoryModal(true);
if (type === "WORKFLOW") {
setHistory(false);
dispatch(setProcessHistories({ processHistory: [], totalCount: 0 }));
if (processListData?.processKey) {
fetchProcessHistory(processListData?.processKey, pageNo, limit);
}
} else {
Ajay-aot marked this conversation as resolved.
Show resolved Hide resolved
setHistory(true);
dispatch(setFormHistories({ formHistory: [], totalCount: 0 }));
if (processListData?.parentFormId) {
fetchFormHistory(processListData?.parentFormId, pageNo, limit);
}
}
};

const loadMoreBtnAction = () => {
history
? fetchFormHistory(processListData?.parentFormId)
: fetchProcessHistory(processListData?.processKey);
};

const handleHistory = () => {
console.log("handleHistory");
const revertFormBtnAction = (cloneId) => {
dispatch(setRestoreFormId(cloneId));
fetchRestoredFormData(cloneId);
};

const revertProcessBtnAction = (processId) => {
if(processId){
setIsProcessDetailsLoading(true);
fetchRevertingProcessData(processId).then((res) =>{
if(res.data){
const { data } = res;
dispatch(setProcessData(data));
setIsProcessDetailsLoading(false);
}
}).catch((err) =>{
console.log(err.response.data);
});
}
};

const handlePreview = () => {
Expand Down Expand Up @@ -761,7 +871,7 @@ const Edit = React.memo(() => {
size="md"
icon={<HistoryIcon />}
label={t("History")}
onClick={handleHistory}
onClick={() => handleHistory(CategoryType.FORM)}
dataTestid="handle-form-history-testid"
ariaLabel={t("Form History Button")}
/>
Expand Down Expand Up @@ -822,7 +932,9 @@ const Edit = React.memo(() => {
className={`wraper flow-wraper ${isFlowLayout ? "visible" : ""}`}
>
{/* TBD: Add a loader instead. */}
{isProcessDetailsLoading ? <>loading...</> : <FlowEdit />}
{isProcessDetailsLoading ? <>loading...</> : <FlowEdit
handleHistory={handleHistory}
CategoryType={CategoryType}/>}
</div>
<button
className={`border-0 form-flow-wraper-${
Expand Down Expand Up @@ -886,6 +998,21 @@ const Edit = React.memo(() => {
size="md"
/>
)}

<HistoryModal
show={showHistoryModal}
onClose={closeHistoryModal}
title={t("History")}
loadMoreBtnText={t("Load More")}
revertBtnText={t("Revert To This")}
allHistory={history ? formHistory : processHistory}
loadMoreBtnAction={loadMoreBtnAction}
categoryType={history ? CategoryType.FORM : CategoryType.WORKFLOW}
revertBtnAction={history ? revertFormBtnAction : revertProcessBtnAction}
historyCount={
history ? formHistoryData.totalCount : processHistoryData.totalCount
}
/>
{renderDeleteModal()}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions forms-flow-web/src/modules/RestoreFormReducer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ACTION_CONSTANTS from "../actions/actionConstants";
import { setVersionNumberIfNotExist } from "../helper/formHistory";
// import { setVersionNumberIfNotExist } from "../helper/formHistory";

const initialState = {
restoredFormData: {},
restoredFormId: null,
formHistory:[]
formHistoryData:{}

};

Expand All @@ -15,7 +15,7 @@ const RestoreFormReducer = (state = initialState, action) => {
case ACTION_CONSTANTS.RESTORE_FORM_DATA:
return { ...state, restoredFormData: action.payload };
case ACTION_CONSTANTS.FORM_HISTORY:
return { ...state, formHistory: setVersionNumberIfNotExist(action.payload)};
return { ...state, formHistoryData: action.payload};
default:
return state;
}
Expand Down
3 changes: 3 additions & 0 deletions forms-flow-web/src/modules/processReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const initialState = {
bpmnSearchText: "",
dmnSearchText: "",
isPublicDiagram: null,
processHistoryData:{},
processData:{},
totalCount:0,
};
Expand Down Expand Up @@ -103,6 +104,8 @@ const process = (state = initialState, action) => {
return { ...state, dmnSearchText: action.payload };
case ACTION_CONSTANTS.IS_PUBLIC_DIAGRAM:
return { ...state, isPublicDiagram: action.payload };
case ACTION_CONSTANTS.PROCESS_HISTORY:
return { ...state, processHistoryData: action.payload };
case ACTION_CONSTANTS.SET_PROCESS_DATA:
return { ...state, processData: action.payload };
case ACTION_CONSTANTS.SET_SUBFLOW_COUNT:
Expand Down
Loading