From 5436956f8ae7db3bd9f9abc27bd0d989a2150eb7 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 7 Feb 2024 16:38:00 +0530 Subject: [PATCH 01/12] [#1152] control center key error fixed --- frontend/src/pages/control-center/ControlCenter.jsx | 6 +++--- .../src/pages/control-center/components/PanelApprovals.jsx | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/control-center/ControlCenter.jsx b/frontend/src/pages/control-center/ControlCenter.jsx index 2ac3c27b0..9774586f3 100644 --- a/frontend/src/pages/control-center/ControlCenter.jsx +++ b/frontend/src/pages/control-center/ControlCenter.jsx @@ -1,4 +1,4 @@ -import React, { useMemo } from "react"; +import React, { Fragment, useMemo } from "react"; import "./style.scss"; import { Row, Col, Button } from "antd"; import { store, config, uiText } from "../../lib"; @@ -113,7 +113,7 @@ const ControlCenter = () => { {selectedPanels.map((panel, index) => { if (panel?.render) { - return panel.render; + return {panel.render}; } const cardOnly = selectedPanels.filter((x) => !x?.render); const isFullWidth = @@ -124,7 +124,7 @@ const ControlCenter = () => {
diff --git a/frontend/src/pages/control-center/components/PanelApprovals.jsx b/frontend/src/pages/control-center/components/PanelApprovals.jsx index af05eb733..4d1c7c2a8 100644 --- a/frontend/src/pages/control-center/components/PanelApprovals.jsx +++ b/frontend/src/pages/control-center/components/PanelApprovals.jsx @@ -49,7 +49,11 @@ const PanelApprovals = () => { api .get(url) .then((res) => { - setApprovalsPending(res.data.batch); + const newData = res.data.batch.map((item, index) => ({ + ...item, + key: index.toString(), + })); + setApprovalsPending(newData); setLoading(false); }) .catch((e) => { From c57b965ba0149ade6103f70b467e56b4b51f8e67 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 7 Feb 2024 18:22:38 +0530 Subject: [PATCH 02/12] [#1152] yellow color still exist when editing solved --- .../src/pages/approvals/ApprovalDetail.jsx | 37 ++++++++++++------- frontend/src/pages/approvals/style.scss | 6 +++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/frontend/src/pages/approvals/ApprovalDetail.jsx b/frontend/src/pages/approvals/ApprovalDetail.jsx index 03c3660d9..b3be54e4e 100644 --- a/frontend/src/pages/approvals/ApprovalDetail.jsx +++ b/frontend/src/pages/approvals/ApprovalDetail.jsx @@ -158,6 +158,12 @@ const ApprovalDetail = ({ resetObj[d.question] = false; }); setresetButton({ ...resetButton, ...resetObj }); + const indexToUpdate = rawValues.findIndex((row) => row.id === data.id); + if (indexToUpdate !== -1) { + const updatedRawValues = [...rawValues]; + updatedRawValues[indexToUpdate].edited = false; + setRawValues(updatedRawValues); + } }) .catch((e) => { console.error(e); @@ -166,6 +172,7 @@ const ApprovalDetail = ({ setSaving(null); }); }; + const handleApprove = (id, status) => { let payload = { batch: id, @@ -436,6 +443,22 @@ const ApprovalDetail = ({ ) : (
+
+ +
{record.data?.map((r, rI) => (

{r.name}

@@ -492,20 +515,6 @@ const ApprovalDetail = ({ />
))} -
)}
diff --git a/frontend/src/pages/approvals/style.scss b/frontend/src/pages/approvals/style.scss index 3d7edb665..e624bad2e 100644 --- a/frontend/src/pages/approvals/style.scss +++ b/frontend/src/pages/approvals/style.scss @@ -187,7 +187,13 @@ .pending-data-outer { height: 500px; overflow-y: scroll; + margin-top: 2rem; + .save-edit-button { + position: absolute; + top: 5px; + right: 16px; + } .pending-data-wrapper { border: solid #e9e9e9 1px; margin-bottom: 20px; From aa5ea215073de80e67659286ef22bed2522fcdf5 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 7 Feb 2024 18:35:07 +0530 Subject: [PATCH 03/12] [#1151] prop type added null also into that --- frontend/src/components/EditableCell.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/EditableCell.jsx b/frontend/src/components/EditableCell.jsx index 8c56aea51..c40571c50 100644 --- a/frontend/src/components/EditableCell.jsx +++ b/frontend/src/components/EditableCell.jsx @@ -21,7 +21,7 @@ const EditableCell = ({ const [editing, setEditing] = useState(false); const [locationName, setLocationName] = useState(null); const [value, setValue] = useState(null); - + console.log(record, "RECORD"); useEffect(() => { if ( record && @@ -205,7 +205,7 @@ EditableCell.propTypes = { record: PropTypes.shape({ id: PropTypes.number.isRequired, type: PropTypes.string.isRequired, - value: PropTypes.any.isRequired, + value: PropTypes.oneOfType([PropTypes.any, PropTypes.null]), option: PropTypes.array, newValue: PropTypes.any, }), From 46fd6119ccbecbb96a615125a4bf7cd49b04891e Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 7 Feb 2024 20:10:55 +0530 Subject: [PATCH 04/12] [1152] editable cel yellow color added for main row in manage data --- frontend/src/components/EditableCell.jsx | 2 +- frontend/src/pages/manage-data/DataDetail.jsx | 9 +++++++++ frontend/src/pages/manage-data/ManageData.jsx | 6 ++++++ frontend/src/pages/manage-data/style.scss | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/EditableCell.jsx b/frontend/src/components/EditableCell.jsx index c40571c50..f7cf7fc7b 100644 --- a/frontend/src/components/EditableCell.jsx +++ b/frontend/src/components/EditableCell.jsx @@ -21,7 +21,7 @@ const EditableCell = ({ const [editing, setEditing] = useState(false); const [locationName, setLocationName] = useState(null); const [value, setValue] = useState(null); - console.log(record, "RECORD"); + useEffect(() => { if ( record && diff --git a/frontend/src/pages/manage-data/DataDetail.jsx b/frontend/src/pages/manage-data/DataDetail.jsx index 9db85dda1..6eded71bb 100644 --- a/frontend/src/pages/manage-data/DataDetail.jsx +++ b/frontend/src/pages/manage-data/DataDetail.jsx @@ -14,6 +14,8 @@ const DataDetail = ({ updateRecord, setDeleteData, isPublic = false, + editedRecord, + setEditedRecord, }) => { const [dataset, setDataset] = useState([]); const [loading, setLoading] = useState(false); @@ -25,12 +27,14 @@ const DataDetail = ({ const updateCell = (key, parentId, value) => { setresetButton({ ...resetButton, [key]: true }); + setEditedRecord({ ...editedRecord, [record.id]: true }); let prev = JSON.parse(JSON.stringify(dataset)); prev = prev.map((qg) => qg.id === parentId ? { ...qg, question: qg.question.map((qi) => { + let hasEdits = false; if (qi.id === key) { if ( isEqual(qi.value, value) && @@ -40,6 +44,10 @@ const DataDetail = ({ } else { qi.newValue = value; } + const edited = !isEqual(qi.value, value); + if (edited && !hasEdits) { + hasEdits = true; + } return qi; } return qi; @@ -112,6 +120,7 @@ const DataDetail = ({ resetObj[d.question] = false; }); setresetButton({ ...resetButton, ...resetObj }); + setEditedRecord({ ...editedRecord, [record.id]: false }); }) .catch((e) => { console.error(e); diff --git a/frontend/src/pages/manage-data/ManageData.jsx b/frontend/src/pages/manage-data/ManageData.jsx index 01faf427f..f748c02e2 100644 --- a/frontend/src/pages/manage-data/ManageData.jsx +++ b/frontend/src/pages/manage-data/ManageData.jsx @@ -33,6 +33,7 @@ const ManageData = () => { const [updateRecord, setUpdateRecord] = useState(false); const [deleteData, setDeleteData] = useState(null); const [deleting, setDeleting] = useState(false); + const [editedRecord, setEditedRecord] = useState({}); const { language, advancedFilters } = store.useState((s) => s); const { active: activeLang } = language; const text = useMemo(() => { @@ -202,6 +203,9 @@ const ManageData = () => { showTotal: (total, range) => `Results: ${range[0]} - ${range[1]} of ${total} data`, }} + rowClassName={(record) => + editedRecord[record.id] ? "row-edited" : "row-normal sticky" + } rowKey="id" expandable={{ expandedRowRender: (record) => ( @@ -211,6 +215,8 @@ const ManageData = () => { updateRecord={updateRecord} updater={setUpdateRecord} setDeleteData={setDeleteData} + setEditedRecord={setEditedRecord} + editedRecord={editedRecord} /> ), expandIcon: ({ expanded, onExpand, record }) => diff --git a/frontend/src/pages/manage-data/style.scss b/frontend/src/pages/manage-data/style.scss index de9d3ca46..72c636abf 100644 --- a/frontend/src/pages/manage-data/style.scss +++ b/frontend/src/pages/manage-data/style.scss @@ -59,5 +59,19 @@ } } } + .button-save { + position: absolute; + top: 0px; + right: 22px; + } + .ant-table { + tr.row-edited td { + background-color: #fefebe; + } + tr.ant-table-row.row-edited:hover > td, + tr.row-edited > td.ant-table-cell-row-hover { + background: #fefebe; + } + } } } From e5d0dadd233ff6fb5c0c92b656eedd83d74e44fe Mon Sep 17 00:00:00 2001 From: dedenbangkit Date: Thu, 8 Feb 2024 19:39:13 +0700 Subject: [PATCH 05/12] Add approval instructions to short HH test form --- backend/source/forms/short-test-form.test.json | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/source/forms/short-test-form.test.json b/backend/source/forms/short-test-form.test.json index 63d4f369c..8bcf1db87 100644 --- a/backend/source/forms/short-test-form.test.json +++ b/backend/source/forms/short-test-form.test.json @@ -6,6 +6,13 @@ "languages": ["en"], "version": 1, "translations": null, + "approval_instructions": { + "text": "Please check all of the checkbox below", + "action": [ + "I have checked all of the data correctly", + "I approve this data for submission" + ] + }, "question_groups": [ { "id": 16993539153821, @@ -105,9 +112,7 @@ "dependency": [ { "id": 16993542207341, - "options": [ - "New" - ] + "options": ["New"] } ], "extra": { @@ -125,9 +130,7 @@ "dependency": [ { "id": 16993542207341, - "options": [ - "New" - ] + "options": ["New"] } ], "extra": { From b138d016b64ed415325d401b6bd393d4a5d210cc Mon Sep 17 00:00:00 2001 From: abhishek Date: Thu, 8 Feb 2024 19:05:41 +0530 Subject: [PATCH 06/12] [#1152] pending submition page save button made static --- frontend/src/components/EditableCell.jsx | 2 +- frontend/src/pages/submissions/BatchDetail.jsx | 13 ++++++++++--- frontend/src/pages/submissions/Submissions.jsx | 6 ++++++ frontend/src/pages/submissions/style.scss | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/EditableCell.jsx b/frontend/src/components/EditableCell.jsx index 8534ac1be..8a9ac40a5 100644 --- a/frontend/src/components/EditableCell.jsx +++ b/frontend/src/components/EditableCell.jsx @@ -209,7 +209,7 @@ EditableCell.propTypes = { record: PropTypes.shape({ id: PropTypes.number.isRequired, type: PropTypes.string.isRequired, - value: PropTypes.oneOfType([PropTypes.any, PropTypes.null]), + value: PropTypes.oneOfType([PropTypes.any, PropTypes.oneOf([null])]), option: PropTypes.array, newValue: PropTypes.any, }), diff --git a/frontend/src/pages/submissions/BatchDetail.jsx b/frontend/src/pages/submissions/BatchDetail.jsx index cb53a3aa3..51ef99da1 100644 --- a/frontend/src/pages/submissions/BatchDetail.jsx +++ b/frontend/src/pages/submissions/BatchDetail.jsx @@ -4,7 +4,14 @@ import { api, store, uiText } from "../../lib"; import { isEqual, flatten } from "lodash"; import { useNotification } from "../../util/hooks"; -const BatchDetail = ({ expanded, setReload, deleting, handleDelete }) => { +const BatchDetail = ({ + expanded, + setReload, + deleting, + handleDelete, + editedRecord, + setEditedRecord, +}) => { const [dataLoading, setDataLoading] = useState(true); const [saving, setSaving] = useState(null); const [rawValue, setRawValue] = useState(null); @@ -82,7 +89,6 @@ const BatchDetail = ({ expanded, setReload, deleting, handleDelete }) => { } }); }); - api .put( `form-pending-data/${expanded.form}?pending_data_id=${data.id}`, @@ -90,12 +96,12 @@ const BatchDetail = ({ expanded, setReload, deleting, handleDelete }) => { ) .then(() => { setReload(data.id); - const resetObj = {}; formData.map((data) => { resetObj[data.question] = false; }); setresetButton({ ...resetButton, ...resetObj }); + setEditedRecord({ ...editedRecord, [expanded.id]: false }); notify({ type: "success", message: text.successDataUpdated, @@ -111,6 +117,7 @@ const BatchDetail = ({ expanded, setReload, deleting, handleDelete }) => { const updateCell = (key, parentId, value) => { setresetButton({ ...resetButton, [key]: true }); + setEditedRecord({ ...editedRecord, [expanded.id]: true }); let hasEdits = false; const data = rawValue.data.map((rd) => ({ ...rd, diff --git a/frontend/src/pages/submissions/Submissions.jsx b/frontend/src/pages/submissions/Submissions.jsx index 6e6610ae1..6da2aae76 100644 --- a/frontend/src/pages/submissions/Submissions.jsx +++ b/frontend/src/pages/submissions/Submissions.jsx @@ -37,6 +37,7 @@ const Submissions = () => { const { selectedForm, user } = store.useState((state) => state); const [batchName, setBatchName] = useState(""); const [comment, setComment] = useState(""); + const [editedRecord, setEditedRecord] = useState({}); const { language } = store.useState((s) => s); const { active: activeLang } = language; const { notify } = useNotification(); @@ -341,6 +342,9 @@ const Submissions = () => { className="main-table" dataSource={dataset} onChange={handleChange} + rowClassName={(record) => + editedRecord[record.id] ? "row-edited" : "row-normal" + } columns={ dataTab === "pending-submission" ? [...columnsPending, Table.EXPAND_COLUMN] @@ -380,6 +384,8 @@ const Submissions = () => { dataset={dataset} handleDelete={handleDelete} deleting={deleting} + setEditedRecord={setEditedRecord} + editedRecord={editedRecord} /> ); } diff --git a/frontend/src/pages/submissions/style.scss b/frontend/src/pages/submissions/style.scss index 62c53f7bd..2da14a2b2 100644 --- a/frontend/src/pages/submissions/style.scss +++ b/frontend/src/pages/submissions/style.scss @@ -197,6 +197,20 @@ } } + .ant-table-expanded-row { + .ant-table-cell { + .pending-data-actions { + position: absolute; + top: -6px; + right: -9px; + } + } + } + + tr.ant-table-expanded-row > td{ + padding-top: 3rem; + } + .pending-data-outer { height: 500px; overflow-y: scroll; From ea567a5f76d606f72c9a534c128a0289442778de Mon Sep 17 00:00:00 2001 From: abhishek Date: Thu, 8 Feb 2024 22:25:16 +0530 Subject: [PATCH 07/12] [#1152] translation text added and save button made sticky and yellow color removing when editing done --- frontend/src/pages/approvals/ApprovalDetail.jsx | 11 +++++++---- frontend/src/pages/manage-data/DataDetail.jsx | 12 +++++++++--- frontend/src/pages/submissions/BatchDetail.jsx | 2 ++ frontend/src/pages/submissions/SubmissionEditing.jsx | 1 + frontend/src/pages/submissions/style.scss | 4 ++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/approvals/ApprovalDetail.jsx b/frontend/src/pages/approvals/ApprovalDetail.jsx index b3be54e4e..01d1f0179 100644 --- a/frontend/src/pages/approvals/ApprovalDetail.jsx +++ b/frontend/src/pages/approvals/ApprovalDetail.jsx @@ -17,7 +17,7 @@ import { LoadingOutlined, HistoryOutlined, } from "@ant-design/icons"; -import { api, store, config } from "../../lib"; +import { api, store, config, uiText } from "../../lib"; import { EditableCell } from "../../components"; import { isEqual, flatten } from "lodash"; import { useNotification } from "../../util/hooks"; @@ -112,9 +112,12 @@ const ApprovalDetail = ({ new Array(record.form?.approval_instructions?.action.length).fill(false) ); const [resetButton, setresetButton] = useState({}); - - const { user: authUser } = store.useState((s) => s); + const { user: authUser, language } = store.useState((s) => s); const { approvalsLiteral } = config; + const { active: activeLang } = language; + const text = useMemo(() => { + return uiText[activeLang]; + }, [activeLang]); //for checking the null value const approveButtonEnable = useMemo(() => { @@ -456,7 +459,7 @@ const ApprovalDetail = ({ isEdited(record.id) === false } > - Save Edits + {text.saveEditButton}
{record.data?.map((r, rI) => ( diff --git a/frontend/src/pages/manage-data/DataDetail.jsx b/frontend/src/pages/manage-data/DataDetail.jsx index 36a1be816..06082159e 100644 --- a/frontend/src/pages/manage-data/DataDetail.jsx +++ b/frontend/src/pages/manage-data/DataDetail.jsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"; import { Table, Button, Space, Spin, Alert } from "antd"; import { LoadingOutlined, HistoryOutlined } from "@ant-design/icons"; import { EditableCell } from "../../components"; -import { api, config, store } from "../../lib"; +import { api, config, store, uiText } from "../../lib"; import { useNotification } from "../../util/hooks"; import { flatten, isEqual } from "lodash"; import { HistoryTable } from "../../components"; @@ -24,6 +24,11 @@ const DataDetail = ({ const pendingData = record?.pending_data?.created_by || false; const { user: authUser, forms } = store.useState((state) => state); const { notify } = useNotification(); + const { language } = store.useState((s) => s); + const { active: activeLang } = language; + const text = useMemo(() => { + return uiText[activeLang]; + }, [activeLang]); const updateCell = (key, parentId, value) => { setresetButton({ ...resetButton, [key]: true }); @@ -73,6 +78,7 @@ const DataDetail = ({ } : qg ); + setEditedRecord({ ...editedRecord, [record.id]: false }); setDataset(prev); }; @@ -271,7 +277,7 @@ const DataDetail = ({ loading={saving} shape="round" > - Save Edits + {text.saveEditButton} {deleteData && ( )} diff --git a/frontend/src/pages/submissions/BatchDetail.jsx b/frontend/src/pages/submissions/BatchDetail.jsx index 51ef99da1..fdd660faf 100644 --- a/frontend/src/pages/submissions/BatchDetail.jsx +++ b/frontend/src/pages/submissions/BatchDetail.jsx @@ -86,6 +86,7 @@ const BatchDetail = ({ question: rq.id, value: value, }); + delete rq.newValue; } }); }); @@ -171,6 +172,7 @@ const BatchDetail = ({ return rq; }), })); + setEditedRecord({ ...editedRecord, [expanded.id]: false }); setRawValue({ ...prev, data, diff --git a/frontend/src/pages/submissions/SubmissionEditing.jsx b/frontend/src/pages/submissions/SubmissionEditing.jsx index 438fb9b94..60e98851a 100644 --- a/frontend/src/pages/submissions/SubmissionEditing.jsx +++ b/frontend/src/pages/submissions/SubmissionEditing.jsx @@ -41,6 +41,7 @@ const SubmissionEditing = ({ ); } + return ( <>
diff --git a/frontend/src/pages/submissions/style.scss b/frontend/src/pages/submissions/style.scss index 2da14a2b2..52f43f022 100644 --- a/frontend/src/pages/submissions/style.scss +++ b/frontend/src/pages/submissions/style.scss @@ -207,10 +207,10 @@ } } - tr.ant-table-expanded-row > td{ + tr.ant-table-expanded-row > td { padding-top: 3rem; } - + .pending-data-outer { height: 500px; overflow-y: scroll; From d6dc2e389ceabf0c8aaf422398247ce3ef003a4c Mon Sep 17 00:00:00 2001 From: ifirmawan Date: Fri, 9 Feb 2024 10:50:21 +0700 Subject: [PATCH 08/12] [#1152] Move setEditedRecord to fix yellow row status --- frontend/src/pages/submissions/BatchDetail.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/submissions/BatchDetail.jsx b/frontend/src/pages/submissions/BatchDetail.jsx index fdd660faf..6cbeed079 100644 --- a/frontend/src/pages/submissions/BatchDetail.jsx +++ b/frontend/src/pages/submissions/BatchDetail.jsx @@ -118,7 +118,6 @@ const BatchDetail = ({ const updateCell = (key, parentId, value) => { setresetButton({ ...resetButton, [key]: true }); - setEditedRecord({ ...editedRecord, [expanded.id]: true }); let hasEdits = false; const data = rawValue.data.map((rd) => ({ ...rd, @@ -145,6 +144,7 @@ const BatchDetail = ({ return rq; }), })); + setEditedRecord({ ...editedRecord, [expanded.id]: hasEdits }); setRawValue({ ...rawValue, data, From fa593d539279a718fcb74f10c48cd2757bc343b0 Mon Sep 17 00:00:00 2001 From: ifirmawan Date: Fri, 9 Feb 2024 10:54:03 +0700 Subject: [PATCH 09/12] [#1152] Remove unnecessary params id in isEdit function --- frontend/src/pages/submissions/SubmissionEditing.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/pages/submissions/SubmissionEditing.jsx b/frontend/src/pages/submissions/SubmissionEditing.jsx index 60e98851a..387e23ad0 100644 --- a/frontend/src/pages/submissions/SubmissionEditing.jsx +++ b/frontend/src/pages/submissions/SubmissionEditing.jsx @@ -107,9 +107,7 @@ const SubmissionEditing = ({ shape="round" onClick={() => handleSave(expanded)} loading={expanded.id === saving} - disabled={ - expanded.id === dataLoading || isEdited(expanded.id) === false - } + disabled={expanded.id === dataLoading || isEdited() === false} > {text.saveEditButton} From f9062689012bbe63a4a633d85579adc356cb4e82 Mon Sep 17 00:00:00 2001 From: abhishek Date: Sat, 10 Feb 2024 21:03:12 +0530 Subject: [PATCH 10/12] [#1152] yellow color bug fixed --- frontend/src/pages/manage-data/DataDetail.jsx | 21 ++++++++++++------- .../src/pages/submissions/BatchDetail.jsx | 20 ++++++++++++++---- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/frontend/src/pages/manage-data/DataDetail.jsx b/frontend/src/pages/manage-data/DataDetail.jsx index 06082159e..d5f860730 100644 --- a/frontend/src/pages/manage-data/DataDetail.jsx +++ b/frontend/src/pages/manage-data/DataDetail.jsx @@ -32,20 +32,18 @@ const DataDetail = ({ const updateCell = (key, parentId, value) => { setresetButton({ ...resetButton, [key]: true }); - setEditedRecord({ ...editedRecord, [record.id]: true }); let prev = JSON.parse(JSON.stringify(dataset)); + let hasEdits = false; prev = prev.map((qg) => qg.id === parentId ? { ...qg, question: qg.question.map((qi) => { - let hasEdits = false; if (qi.id === key) { - if ( - isEqual(qi.value, value) && - (qi.newValue || qi.newValue === 0) - ) { - delete qi.newValue; + if (isEqual(qi.value, value)) { + if (qi.newValue) { + delete qi.newValue; + } } else { qi.newValue = value; } @@ -60,6 +58,10 @@ const DataDetail = ({ } : qg ); + const hasNewValue = prev + .find((p) => p.id === parentId) + ?.question?.some((q) => typeof q.newValue !== "undefined"); + setEditedRecord({ [record.id]: hasNewValue }); setDataset(prev); }; @@ -78,7 +80,10 @@ const DataDetail = ({ } : qg ); - setEditedRecord({ ...editedRecord, [record.id]: false }); + const hasNewValue = prev + .find((p) => p.id === parentId) + ?.question?.some((q) => typeof q.newValue !== "undefined"); + setEditedRecord({ [record.id]: hasNewValue }); setDataset(prev); }; diff --git a/frontend/src/pages/submissions/BatchDetail.jsx b/frontend/src/pages/submissions/BatchDetail.jsx index 6cbeed079..70cdf9c8f 100644 --- a/frontend/src/pages/submissions/BatchDetail.jsx +++ b/frontend/src/pages/submissions/BatchDetail.jsx @@ -123,8 +123,10 @@ const BatchDetail = ({ ...rd, question: rd.question.map((rq) => { if (rq.id === key && expanded.id === parentId) { - if (isEqual(rq.value, value) && (rq.newValue || rq.newValue === 0)) { - delete rq.newValue; + if (isEqual(rq.value, value)) { + if (rq.newValue) { + delete rq.newValue; + } } else { rq.newValue = value; } @@ -144,7 +146,12 @@ const BatchDetail = ({ return rq; }), })); - setEditedRecord({ ...editedRecord, [expanded.id]: hasEdits }); + const hasNewValue = data.some((d) => { + return d.question?.some((q) => { + return typeof q.newValue !== "undefined"; + }); + }); + setEditedRecord({ [expanded.id]: hasNewValue }); setRawValue({ ...rawValue, data, @@ -172,7 +179,12 @@ const BatchDetail = ({ return rq; }), })); - setEditedRecord({ ...editedRecord, [expanded.id]: false }); + const hasNewValue = data.some((d) => { + return d.question?.some((q) => { + return typeof q.newValue !== "undefined"; + }); + }); + setEditedRecord({ [expanded.id]: hasNewValue }); setRawValue({ ...prev, data, From 9fe7317926b0fdc92ce5aafa9e36bb2d2d3b898e Mon Sep 17 00:00:00 2001 From: ifirmawan Date: Mon, 12 Feb 2024 08:53:34 +0700 Subject: [PATCH 11/12] [#1152] Set directly to false in resetCell --- frontend/src/pages/manage-data/DataDetail.jsx | 5 +---- frontend/src/pages/submissions/BatchDetail.jsx | 7 +------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/manage-data/DataDetail.jsx b/frontend/src/pages/manage-data/DataDetail.jsx index d5f860730..a9d6de34e 100644 --- a/frontend/src/pages/manage-data/DataDetail.jsx +++ b/frontend/src/pages/manage-data/DataDetail.jsx @@ -80,10 +80,7 @@ const DataDetail = ({ } : qg ); - const hasNewValue = prev - .find((p) => p.id === parentId) - ?.question?.some((q) => typeof q.newValue !== "undefined"); - setEditedRecord({ [record.id]: hasNewValue }); + setEditedRecord({ [record.id]: false }); setDataset(prev); }; diff --git a/frontend/src/pages/submissions/BatchDetail.jsx b/frontend/src/pages/submissions/BatchDetail.jsx index 70cdf9c8f..4ff8ea485 100644 --- a/frontend/src/pages/submissions/BatchDetail.jsx +++ b/frontend/src/pages/submissions/BatchDetail.jsx @@ -179,12 +179,7 @@ const BatchDetail = ({ return rq; }), })); - const hasNewValue = data.some((d) => { - return d.question?.some((q) => { - return typeof q.newValue !== "undefined"; - }); - }); - setEditedRecord({ [expanded.id]: hasNewValue }); + setEditedRecord({ [expanded.id]: false }); setRawValue({ ...prev, data, From b47212f04f275a98f8c6302a00ff052785517431 Mon Sep 17 00:00:00 2001 From: ifirmawan Date: Mon, 12 Feb 2024 09:26:02 +0700 Subject: [PATCH 12/12] [#1152] Fix yellow background in datapoint when reset in diff question group --- frontend/src/pages/manage-data/DataDetail.jsx | 11 +++++++++-- frontend/src/pages/submissions/BatchDetail.jsx | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/manage-data/DataDetail.jsx b/frontend/src/pages/manage-data/DataDetail.jsx index a9d6de34e..614de44aa 100644 --- a/frontend/src/pages/manage-data/DataDetail.jsx +++ b/frontend/src/pages/manage-data/DataDetail.jsx @@ -61,7 +61,7 @@ const DataDetail = ({ const hasNewValue = prev .find((p) => p.id === parentId) ?.question?.some((q) => typeof q.newValue !== "undefined"); - setEditedRecord({ [record.id]: hasNewValue }); + setEditedRecord({ ...editedRecord, [record.id]: hasNewValue }); setDataset(prev); }; @@ -80,7 +80,14 @@ const DataDetail = ({ } : qg ); - setEditedRecord({ [record.id]: false }); + /** + * Check whether it still has newValue or not + * in all groups of questions + */ + const hasNewValue = prev + ?.flatMap((p) => p?.question) + ?.find((q) => q?.newValue); + setEditedRecord({ ...editedRecord, [record.id]: hasNewValue }); setDataset(prev); }; diff --git a/frontend/src/pages/submissions/BatchDetail.jsx b/frontend/src/pages/submissions/BatchDetail.jsx index 4ff8ea485..10fbf5dcf 100644 --- a/frontend/src/pages/submissions/BatchDetail.jsx +++ b/frontend/src/pages/submissions/BatchDetail.jsx @@ -151,7 +151,7 @@ const BatchDetail = ({ return typeof q.newValue !== "undefined"; }); }); - setEditedRecord({ [expanded.id]: hasNewValue }); + setEditedRecord({ ...editedRecord, [expanded.id]: hasNewValue }); setRawValue({ ...rawValue, data, @@ -179,7 +179,14 @@ const BatchDetail = ({ return rq; }), })); - setEditedRecord({ [expanded.id]: false }); + /** + * Check whether it still has newValue or not + * in all groups of questions + */ + const hasNewValue = data + ?.flatMap((d) => d?.question) + ?.find((q) => q?.newValue); + setEditedRecord({ ...editedRecord, [expanded.id]: hasNewValue }); setRawValue({ ...prev, data,