Skip to content

Commit 8b221db

Browse files
committed
(core) Fixing map-fields button on formview
Summary: Map and unmap fields button on forms stopped working after recent navigation improvments. Those function were put in the keyboard actions section before, now they are registered globally as they are button handlers not affected by the focus. Also unified testIds used in mappings between forms and other widgets Test Plan: Added new tests Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D4679
1 parent 96fc7f1 commit 8b221db

File tree

6 files changed

+84
-34
lines changed

6 files changed

+84
-34
lines changed

app/client/components/Forms/FormView.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,6 @@ export class FormView extends Disposable {
271271
await selected.deleteSelf();
272272
}).catch(reportError);
273273
},
274-
hideFields: (colId: [string]) => {
275-
// Get the ref from colId.
276-
const existing: Array<[number, string]> =
277-
this.viewSection.viewFields().all().map(f => [f.id(), f.column().colId()]);
278-
const ref = existing.filter(([_, c]) => colId.includes(c)).map(([r, _]) => r);
279-
if (!ref.length) { return; }
280-
const box = Array.from(this._root.filter(b => ref.includes(b.prop('leaf')?.get())));
281-
box.forEach(b => b.removeSelf());
282-
this._root.save(async () => {
283-
await this.viewSection.removeField(ref);
284-
}).catch(reportError);
285-
},
286274
insertFieldBefore: (what: NewBox) => {
287275
const selected = this.selectedBox.get();
288276
if (!selected) { return; }
@@ -314,6 +302,32 @@ export class FormView extends Disposable {
314302
this.save().catch(reportError);
315303
}
316304
},
305+
};
306+
this.autoDispose(commands.createGroup({
307+
...keyboardActions,
308+
cursorDown: keyboardActions.nextField,
309+
cursorUp: keyboardActions.prevField,
310+
cursorLeft: keyboardActions.prevField,
311+
cursorRight: keyboardActions.nextField,
312+
shiftDown: keyboardActions.lastField,
313+
shiftUp: keyboardActions.firstField,
314+
editField: keyboardActions.edit,
315+
deleteFields: keyboardActions.clearValues,
316+
}, this, this.viewSection.hasRegionFocus));
317+
318+
const commandHandlers = {
319+
hideFields: (colId: [string]) => {
320+
// Get the ref from colId.
321+
const existing: Array<[number, string]> =
322+
this.viewSection.viewFields().all().map(f => [f.id(), f.column().colId()]);
323+
const ref = existing.filter(([_, c]) => colId.includes(c)).map(([r, _]) => r);
324+
if (!ref.length) { return; }
325+
const box = Array.from(this._root.filter(b => ref.includes(b.prop('leaf')?.get())));
326+
box.forEach(b => b.removeSelf());
327+
this._root.save(async () => {
328+
await this.viewSection.removeField(ref);
329+
}).catch(reportError);
330+
},
317331
showColumns: (colIds: string[]) => {
318332
// Sanity check that type is correct.
319333
if (!colIds.every(c => typeof c === 'string')) { throw new Error('Invalid column id'); }
@@ -345,18 +359,8 @@ export class FormView extends Disposable {
345359
}).catch(reportError);
346360
},
347361
};
348-
this.autoDispose(commands.createGroup({
349-
...keyboardActions,
350-
cursorDown: keyboardActions.nextField,
351-
cursorUp: keyboardActions.prevField,
352-
cursorLeft: keyboardActions.prevField,
353-
cursorRight: keyboardActions.nextField,
354-
shiftDown: keyboardActions.lastField,
355-
shiftUp: keyboardActions.firstField,
356-
editField: keyboardActions.edit,
357-
deleteFields: keyboardActions.clearValues,
358-
hideFields: keyboardActions.hideFields,
359-
}, this, this.viewSection.hasRegionFocus));
362+
363+
this.autoDispose(commands.createGroup(commandHandlers, this, this.viewSection.hasFocus));
360364

361365
this._previewUrl = Computed.create(this, use => {
362366
const doc = use(this.gristDoc.docPageModel.currentDoc);

app/client/components/Forms/MappedFieldsConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class MappedFieldsConfig extends Disposable {
8686
primaryButton(
8787
dom.text(t("Unmap fields")),
8888
dom.on('click', unMapSelected),
89-
testId('visible-hide')
89+
testId('visible-hide'),
9090
),
9191
basicButton(
9292
t("Clear"),
@@ -116,12 +116,12 @@ export class MappedFieldsConfig extends Disposable {
116116
primaryButton(
117117
dom.text(t("Map fields")),
118118
dom.on('click', mapSelected),
119-
testId('visible-hide')
119+
testId('hidden-show'),
120120
),
121121
basicButton(
122122
t("Clear"),
123123
dom.on('click', () => unmappedColumns.get().forEach((col) => col.selected.set(false))),
124-
testId('visible-clear')
124+
testId('hidden-clear')
125125
),
126126
testId('visible-batch-buttons')
127127
),

app/client/ui/VisibleFieldsConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export class VisibleFieldsConfig extends Disposable {
371371
const selection = this._hiddenFieldsSelection;
372372

373373
return cssFieldEntry(
374+
testId('hidden-field'),
374375
cssFieldLabel(dom.text(column.label)),
375376
cssHideIcon('EyeShow',
376377
dom.on('click', () => this.addField(column)),
@@ -391,6 +392,7 @@ export class VisibleFieldsConfig extends Disposable {
391392
const selection = this._visibleFieldsSelection;
392393

393394
return cssFieldEntry(
395+
testId('visible-field'),
394396
cssFieldLabel(dom.text(field.label)),
395397
// TODO: we need a "cross-out eye" icon here.
396398
cssHideIcon('EyeHide',

test/nbrowser/FormView2.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,35 @@ describe('FormView2', function() {
2121

2222
gu.withClipboardTextArea();
2323

24+
describe('general', function() {
25+
before(async function() {
26+
session = await gu.session().login();
27+
api = session.createHomeApi();
28+
await session.tempNewDoc(cleanup);
29+
await gu.addNewPage('Form', 'Table1');
30+
});
31+
32+
it('properly maps fields in the creator panel', async function() {
33+
assert.deepEqual(await labels(), ['A', 'B', 'C']);
34+
35+
// Check A column and use `Unmap fields` button to check it works properly.
36+
await gu.toggleVisibleColumn('A');
37+
await gu.toggleVisibleColumn('B');
38+
await gu.hideColumns();
39+
40+
// Check that the field is no longer in the form.
41+
assert.deepEqual(await labels(), ['C']);
42+
43+
// Now map them back.
44+
await gu.toggleHiddenColumn('A');
45+
await gu.toggleHiddenColumn('B');
46+
await gu.showColumns();
47+
48+
// Check that the fields are back.
49+
assert.deepEqual(await labels(), ['C', 'A', 'B']);
50+
});
51+
});
52+
2453
describe('form borders', function() {
2554
before(async function() {
2655
session = await gu.session().login();

test/nbrowser/LinkingSelector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('LinkingSelector', function() {
3737
await gu.openWidgetPanel();
3838
await gu.selectAllVisibleColumns();
3939
await gu.toggleVisibleColumn('Start_Date');
40-
await gu.hideVisibleColumns();
40+
await gu.hideColumns();
4141

4242
// Make sure we see the same date.
4343
await gu.getCell('Start_Date', 1, 'CLASSES').click();
@@ -61,7 +61,7 @@ describe('LinkingSelector', function() {
6161
await gu.openWidgetPanel();
6262
await gu.selectAllVisibleColumns();
6363
await gu.toggleVisibleColumn('Start_Date');
64-
await gu.hideVisibleColumns();
64+
await gu.hideColumns();
6565

6666
// Rename it to list.
6767
await gu.renameActiveSection('List');
@@ -73,7 +73,7 @@ describe('LinkingSelector', function() {
7373
await gu.renameActiveSection('Card');
7474
await gu.selectAllVisibleColumns();
7575
await gu.toggleVisibleColumn('Start_Date');
76-
await gu.hideVisibleColumns();
76+
await gu.hideColumns();
7777

7878
// Select the second row.
7979
await gu.selectSectionByTitle('List');

test/nbrowser/gristUtils.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,15 +1581,25 @@ export async function selectAllVisibleColumns() {
15811581
* Toggle checkbox for a column in visible columns section.
15821582
*/
15831583
export async function toggleVisibleColumn(col: string) {
1584-
const row = await driver.findContent(".test-vfc-visible-fields .kf_draggable_content", exactMatch(col));
1584+
await openWidgetPanel('widget');
1585+
const row = await driver.findContent(".test-vfc-visible-field", exactMatch(col));
1586+
await row.find('input').click();
1587+
}
1588+
1589+
/**
1590+
* Toggle checkbox for a column in hidden columns section.
1591+
*/
1592+
export async function toggleHiddenColumn(col: string) {
1593+
await openWidgetPanel('widget');
1594+
const row = await driver.findContent(".test-vfc-hidden-field", exactMatch(col));
15851595
await row.find('input').click();
15861596
}
15871597

15881598
/**
15891599
* Lists all columns in the visible columns section.
15901600
*/
15911601
export async function getVisibleColumns() {
1592-
return await driver.findAll(".test-vfc-visible-fields .kf_draggable_content", async (row) => {
1602+
return await driver.findAll(".test-vfc-visible-field", async (row) => {
15931603
return row.getText();
15941604
});
15951605
}
@@ -1598,19 +1608,24 @@ export async function getVisibleColumns() {
15981608
* Lists all columns in the hidden columns section.
15991609
*/
16001610
export async function getHiddenColumns() {
1601-
return await driver.findAll(".test-vfc-hidden-fields .kf_draggable_content", async (row) => {
1611+
return await driver.findAll(".test-vfc-hidden-field", async (row) => {
16021612
return row.getText();
16031613
});
16041614
}
16051615

16061616
/**
16071617
* Clicks `Hide Columns` button in visible columns section.
16081618
*/
1609-
export async function hideVisibleColumns() {
1619+
export async function hideColumns() {
16101620
await driver.find('.test-vfc-visible-hide').click();
16111621
await waitForServer();
16121622
}
16131623

1624+
export async function showColumns() {
1625+
await driver.find('.test-vfc-hidden-show').click();
1626+
await waitForServer();
1627+
}
1628+
16141629
export async function search(what: string) {
16151630
await driver.find('.test-tb-search-icon').click();
16161631
await driver.sleep(500);

0 commit comments

Comments
 (0)