Fix saving of big tables on steps [SCI-8216]

This commit is contained in:
Oleksii Kriuchykhin 2023-03-28 13:29:02 +02:00
parent e3a0f3c55f
commit 0beb64511d
2 changed files with 12 additions and 7 deletions

View file

@ -25,7 +25,13 @@ module StepElements
def update
ActiveRecord::Base.transaction do
@table.update!(table_params)
@table.assign_attributes(table_params.except(:metadata))
begin
@table.metadata = JSON.parse(table_params[:metadata])
rescue JSON::ParserError
@table.metadata = {}
end
@table.save!
log_step_activity(:table_edited, { table_name: @table.name })
end
@ -61,7 +67,7 @@ module StepElements
private
def table_params
params.permit(:name, :contents, metadata: {})
params.permit(:name, :contents, :metadata)
end
def load_table

View file

@ -156,9 +156,8 @@
updateTable() {
if (this.editingTable == false) return;
let tableData = JSON.stringify({data: this.tableObject.getData()});
this.element.attributes.orderable.contents = tableData;
this.element.attributes.orderable.metadata = {cells: this.tableObject.getCellsMeta().map(
this.element.attributes.orderable.contents = JSON.stringify({ data: this.tableObject.getData() });
this.element.attributes.orderable.metadata = JSON.stringify({ cells: this.tableObject.getCellsMeta().map(
(x) => {
if (x) {
return {
@ -169,8 +168,8 @@
} else {
return null
}
}).filter(e => { return e !== null})
};
}).filter(e => { return e !== null })
});
this.update();
this.editingTable = false;
},