mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fix y-axis blinking in chart view configuration
Summary: This is a follow up diff for https://phab.getgrist.com/D3021. Y-axis draggable list used to blink when user changed either one of the x axis or groupdata column. This was due to the fact that all of theses axis are stored into the same array and changing one of them changes the whole array even though items relative to the y-axis actually were not changing. This diff addresses this issue by 1) being carefull at not updating the array of items when the changes do not impact y axis. And 2) by adding a freeze observable allowing to freeze the draggable list of y-axis while actions are being treated on the server. Test Plan: Catching such bug is hard, and given that it's only look and fill, maybe not worth the time and effort. Tested manually though. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3023
This commit is contained in:
@@ -13,6 +13,7 @@ import { icon } from "app/client/ui2018/icons";
|
||||
import * as gutil from 'app/common/gutil';
|
||||
import { Computed, Disposable, dom, IDomArgs, makeTestId, Observable, styled, subscribe } from "grainjs";
|
||||
import difference = require("lodash/difference");
|
||||
import isEqual = require("lodash/isEqual");
|
||||
|
||||
const testId = makeTestId('test-vfc-');
|
||||
|
||||
@@ -27,6 +28,11 @@ interface DraggableFieldsOption {
|
||||
// the group-by-column in the chart type widget.
|
||||
skipFirst?: Observable<number>;
|
||||
|
||||
// Allows to prevent updates of the list. This option is to be used when skipFirst option is used
|
||||
// and it is useful to prevent the list to update during changes that only affect the skipped
|
||||
// fields.
|
||||
freeze?: Observable<boolean>;
|
||||
|
||||
// the itemCreateFunc callback passed to kf.draggableList for the visible fields.
|
||||
itemCreateFunc(field: IField): Element|undefined;
|
||||
}
|
||||
@@ -93,14 +99,21 @@ export class VisibleFieldsConfig extends Disposable {
|
||||
let fields = this._section.viewFields.peek();
|
||||
|
||||
if (options.skipFirst) {
|
||||
const freeze = options.freeze;
|
||||
const allFields = this._section.viewFields.peek();
|
||||
const newArray = new KoArray<ViewFieldRec>();
|
||||
function update() {
|
||||
newArray.assign(allFields.peek().filter((_v, i) => i + 1 > options.skipFirst!.get()));
|
||||
if (freeze && freeze.get()) { return; }
|
||||
const newValues = allFields.peek().filter((_v, i) => i + 1 > options.skipFirst!.get());
|
||||
if (isEqual(newArray.all(), newValues)) { return; }
|
||||
newArray.assign(newValues);
|
||||
}
|
||||
update();
|
||||
this.autoDispose(allFields.subscribe(update));
|
||||
this.autoDispose(subscribe(options.skipFirst, update));
|
||||
if (options.freeze) {
|
||||
this.autoDispose(subscribe(options.freeze, update));
|
||||
}
|
||||
fields = newArray;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user