mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Multi-column configuration
Summary: Creator panel allows now to edit multiple columns at once for some options that are common for them. Options that are not common are disabled. List of options that can be edited for multiple columns: - Column behavior (but limited to empty/formula columns) - Alignment and wrapping - Default style - Number options (for numeric columns) - Column types (but only for empty/formula columns) If multiple columns of the same type are selected, most of the options are available to change, except formula, trigger formula and conditional styles. Editing column label or column id is disabled by default for multiple selection. Not related: some tests were fixed due to the change in the column label and id widget in grist-core (disabled attribute was replaced by readonly). Test Plan: Updated and new tests. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3598
This commit is contained in:
@@ -188,6 +188,21 @@ export class RightPanel extends Disposable {
|
||||
return vsi && vsi.activeFieldBuilder();
|
||||
}));
|
||||
|
||||
const selectedColumns = owner.autoDispose(ko.computed(() => {
|
||||
const vsi = this._gristDoc.viewModel.activeSection?.().viewInstance();
|
||||
return vsi && vsi.selectedColumns ? vsi.selectedColumns() : null;
|
||||
}));
|
||||
|
||||
const isMultiSelect = owner.autoDispose(ko.pureComputed(() => {
|
||||
const list = selectedColumns();
|
||||
return Boolean(list && list.length > 1);
|
||||
}));
|
||||
|
||||
owner.autoDispose(selectedColumns.subscribe(cols => {
|
||||
this._gristDoc.viewModel.activeSection()?.selectedFields(cols || []);
|
||||
}));
|
||||
this._gristDoc.viewModel.activeSection()?.selectedFields(selectedColumns.peek() || []);
|
||||
|
||||
const docModel = this._gristDoc.docModel;
|
||||
const origColRef = owner.autoDispose(ko.computed(() => fieldBuilder()?.origColumn.origColRef() || 0));
|
||||
const origColumn = owner.autoDispose(docModel.columns.createFloatingRowModel(origColRef));
|
||||
@@ -206,24 +221,44 @@ export class RightPanel extends Disposable {
|
||||
const {buildNameConfig, buildFormulaConfig} = ViewPane.FieldConfig;
|
||||
return dom.maybe(isColumnValid, () =>
|
||||
buildConfigContainer(
|
||||
dom.create(buildNameConfig, origColumn, cursor),
|
||||
cssSection(
|
||||
dom.create(buildNameConfig, origColumn, cursor, isMultiSelect),
|
||||
),
|
||||
cssSeparator(),
|
||||
dom.create(buildFormulaConfig, origColumn, this._gristDoc, this._activateFormulaEditor.bind(this)),
|
||||
cssSection(
|
||||
dom.create(buildFormulaConfig,
|
||||
origColumn, this._gristDoc, this._activateFormulaEditor.bind(this)),
|
||||
),
|
||||
cssSeparator(),
|
||||
cssLabel('COLUMN TYPE'),
|
||||
dom.maybe<FieldBuilder|null>(fieldBuilder, builder => [
|
||||
builder.buildSelectTypeDom(),
|
||||
builder.buildSelectWidgetDom(),
|
||||
builder.buildConfigDom()
|
||||
cssLabel('COLUMN TYPE'),
|
||||
cssSection(
|
||||
builder.buildSelectTypeDom(),
|
||||
),
|
||||
cssSection(
|
||||
builder.buildSelectWidgetDom(),
|
||||
),
|
||||
cssSection(
|
||||
builder.buildConfigDom(),
|
||||
),
|
||||
builder.buildColorConfigDom(),
|
||||
cssSection(
|
||||
builder.buildSettingOptions(),
|
||||
dom.maybe(isMultiSelect, () => disabledSection())
|
||||
),
|
||||
]),
|
||||
cssSeparator(),
|
||||
dom.maybe(refSelect.isForeignRefCol, () => [
|
||||
cssLabel('Add referenced columns'),
|
||||
cssRow(refSelect.buildDom()),
|
||||
cssSeparator()
|
||||
]),
|
||||
cssLabel('TRANSFORM'),
|
||||
dom.maybe<FieldBuilder|null>(fieldBuilder, builder => builder.buildTransformDom()),
|
||||
cssSection(
|
||||
dom.maybe(refSelect.isForeignRefCol, () => [
|
||||
cssLabel('Add referenced columns'),
|
||||
cssRow(refSelect.buildDom()),
|
||||
cssSeparator()
|
||||
]),
|
||||
cssLabel('TRANSFORM'),
|
||||
dom.maybe<FieldBuilder|null>(fieldBuilder, builder => builder.buildTransformDom()),
|
||||
dom.maybe(isMultiSelect, () => disabledSection()),
|
||||
testId('panel-transform'),
|
||||
),
|
||||
this._disableIfReadonly(),
|
||||
)
|
||||
);
|
||||
@@ -239,7 +274,7 @@ export class RightPanel extends Disposable {
|
||||
// Custom save handler.
|
||||
onSave?: (column: ColumnRec, formula: string) => Promise<void>,
|
||||
// Custom cancel handler.
|
||||
onCancel?: () => void,) {
|
||||
onCancel?: () => void) {
|
||||
const vsi = this._gristDoc.viewModel.activeSection().viewInstance();
|
||||
if (!vsi) { return; }
|
||||
const editRowModel = vsi.moveEditRowToCursor();
|
||||
@@ -527,6 +562,12 @@ export class RightPanel extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
function disabledSection() {
|
||||
return cssOverlay(
|
||||
testId('panel-disabled-section'),
|
||||
);
|
||||
}
|
||||
|
||||
export function buildConfigContainer(...args: DomElementArg[]): HTMLElement {
|
||||
return cssConfigContainer(
|
||||
// The `position: relative;` style is needed for the overlay for the readonly mode. Note that
|
||||
@@ -774,3 +815,7 @@ const cssTextInput = styled(textInput, `
|
||||
pointer-events: none;
|
||||
}
|
||||
`);
|
||||
|
||||
const cssSection = styled('div', `
|
||||
position: relative;
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user