Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 27e5ec30 authored by Simon Ebel's avatar Simon Ebel
Browse files

feat: move values update to data view component. Ref #168

parent 10a8ae34
No related branches found
No related tags found
No related merge requests found
......@@ -183,12 +183,10 @@ function DataView({
activeSource,
statement,
shouldExecuteQuery,
shouldUpdateValues,
}) {
const { activeLang } = useLang();
const [shouldUpdateValues, setShouldUpdateValues] = React.useState(false);
const [valuesToUpdate, setValuesToUpdate] = React.useState({});
const [activeRows, setActiveRows] = React.useState({});
const [displayRows, setDisplayRows] = React.useState([]);
const [columnData, setColumnData] = React.useState([]);
......@@ -308,6 +306,16 @@ function DataView({
setfieldIdToValueIdToRowId(fieldIdToValueIdToRowId);
}, [activeRows, IdToField]);
const [valuesToUpdate, setValuesToUpdate] = React.useState({});
const { updated, isUpdateError, isUpdateLoading } = useUpdateValues(
shouldUpdateValues,
database,
contexts,
valuesToUpdate,
activeSource.type
);
return (
<Box>
{Object.keys(activeRows).length > 0 ? (
......@@ -348,35 +356,37 @@ function DataView({
const fieldId = params.colDef.id;
const valueId = params.row.fieldToValue[fieldId];
const rowsToUpdate = fieldIdToValueIdToRowId[fieldId][valueId];
const updatedValue = event.target.value;
var updatedRows = { ...activeRows };
rowsToUpdate.forEach((id) => {
var updatedRow = { ...activeRows[id] };
updatedRow[IdToField[fieldId]] = updatedValue;
updatedRows[id] = updatedRow;
let oldValue = activeRows[id][IdToField[fieldId]];
if (!(id in valuesToUpdate)) {
valuesToUpdate[id] = {};
if (event.target) {
const updatedValue = event.target.value;
var updatedRows = { ...activeRows };
rowsToUpdate.forEach((id) => {
var updatedRow = { ...activeRows[id] };
updatedRow[IdToField[fieldId]] = updatedValue;
updatedRows[id] = updatedRow;
let oldValue = activeRows[id][IdToField[fieldId]];
if (!(id in valuesToUpdate)) {
valuesToUpdate[id] = {};
}
if (!(fieldId in valuesToUpdate[id])) {
valuesToUpdate[id][fieldId] = {
newValue: updatedValue,
oldValue: oldValue,
};
} else {
valuesToUpdate[id][fieldId] = {
newValue: updatedValue,
oldValue: valuesToUpdate[id][fieldId].oldValue,
};
}
});
setActiveRows(updatedRows);
setValuesToUpdate({ ...valuesToUpdate });
if (params.reason === GridCellEditStopReasons.cellFocusOut) {
event.defaultMuiPrevented = true;
}
if (!(fieldId in valuesToUpdate[id])) {
valuesToUpdate[id][fieldId] = {
newValue: updatedValue,
oldValue: oldValue,
};
} else {
valuesToUpdate[id][fieldId] = {
newValue: updatedValue,
oldValue: valuesToUpdate[id][fieldId].oldValue,
};
}
});
setActiveRows(updatedRows);
setValuesToUpdate({ ...valuesToUpdate });
if (params.reason === GridCellEditStopReasons.cellFocusOut) {
event.defaultMuiPrevented = true;
}
}}
/>
......@@ -714,15 +724,6 @@ export default function View() {
};
const [shouldUpdateValues, setShouldUpdateValues] = React.useState(false);
const [valuesToUpdate, setValuesToUpdate] = React.useState({});
const { updated, isUpdateError, isUpdateLoading } = useUpdateValues(
shouldUpdateValues,
database,
contexts,
valuesToUpdate,
activeSource.type
);
const handleOnUpdate = () => {
setShouldUpdateValues(true);
......@@ -848,6 +849,7 @@ export default function View() {
activeSource={activeSource}
statement={statement}
shouldExecuteQuery={shouldExecuteQuery}
shouldUpdateValues={shouldUpdateValues}
></DataView>
</Box>
);
......
......@@ -176,6 +176,7 @@ public class DataViewServlet extends MasterServlet {
try {
String UpdatedStatement = request.getParameter(RequestParameters.STATETMENT);
SimpleQuery mq = getMixedQuery(contexts);
mq.toSQLQuery();
StringBuffer data =
ConnectionManagerCl.executeStatement(database, UpdatedStatement, mq);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment