Skip to content
Snippets Groups Projects
Unverified Commit 808cbf6c authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Fix no visual feedback when updating data model column properties (#20874)

parent 8b7971b8
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ const mapDispatchToProps = {
: push(`/admin/datamodel/database/${id}`),
selectTable: ({ id, db_id }) =>
push(`/admin/datamodel/database/${db_id}/table/${id}`),
updateField: field => Fields.actions.update(field),
updateField: field => Fields.actions.updateField(field),
onRetireMetric: ({ id, ...rest }) =>
Metrics.actions.setArchived({ id }, true, rest),
};
......
import { createEntity } from "metabase/lib/entities";
import { t } from "ttag";
import { createEntity, undo } from "metabase/lib/entities";
import {
compose,
withAction,
......@@ -86,6 +87,13 @@ const Fields = createEntity({
return { id, values };
}),
updateField(field, opts) {
return Fields.actions.update(
{ id: field.id },
field,
undo(opts, field.display_name, t`updated`),
);
},
// Docstring from m.api.field:
// Update the human-readable values for a `Field` whose semantic type is
// `category`/`city`/`state`/`country` or whose base type is `type/Boolean`."
......
......@@ -259,12 +259,14 @@ export function createEntity(def) {
);
if (notify) {
if (notify.undo) {
// pick only the attributes that were updated
const undoObject = _.pick(
originalObject,
...Object.keys(updatedObject || {}),
);
// pick only the attributes that were updated
const undoObject = _.pick(
originalObject,
...Object.keys(updatedObject || {}),
);
// https://github.com/metabase/metabase/pull/20874#pullrequestreview-902384264
const canUndo = !hasCircularReference(undoObject);
if (notify.undo && canUndo) {
dispatch(
addUndo({
actions: [
......@@ -611,6 +613,16 @@ export function createEntity(def) {
return entity;
}
function hasCircularReference(object) {
try {
JSON.stringify(object);
} catch (error) {
return true;
}
return false;
}
export function combineEntities(entities) {
const entitiesMap = {};
const reducersMap = {};
......
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