Skip to content

Commit

Permalink
Fix a couple issues with saving field formats, #19037
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed May 15, 2018
1 parent 8e65b02 commit af6fdda
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ uiModules
}

if (!self.selectedFormatId) {
delete indexPattern.fieldFormatMap[field.name];
indexPattern.fieldFormatMap[field.name] = {};
} else {
indexPattern.fieldFormatMap[field.name] = self.field.format;
}
Expand Down Expand Up @@ -116,12 +116,20 @@ uiModules
const changedFormat = cur !== prev;
const missingFormat = cur && (!format || format.type.id !== cur);

if (!changedFormat || !missingFormat) return;
if (!changedFormat || !missingFormat) {
return;
}

// reset to the defaults, but make sure it's an object
const FieldFormat = getFieldFormatType();
const paramDefaults = new FieldFormat({}, getConfig).getParamDefaults();
const currentFormatParams = self.formatParams;
self.formatParams = _.assign({}, _.cloneDeep(paramDefaults));
// If there are no current or new params, the watch will not trigger
// so manually update the format here
if (_.size(currentFormatParams) === 0 && _.size(self.formatParams) === 0) {
self.field.format = new FieldFormat(self.formatParams, getConfig);
}
});

$scope.$watch('editor.formatParams', function () {
Expand Down

0 comments on commit af6fdda

Please sign in to comment.