mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
fix(mail-merge): Skip row in table data if its empty
- Don't show annoying error if entire row is empty - Just show error if just the email cell is empty
This commit is contained in:
parent
28183cb870
commit
432fc99f3c
4 changed files with 87 additions and 4 deletions
|
@ -1,4 +1,9 @@
|
|||
import {testData, testDataSource, testDataSourceUneven} from '../../fixtures/table-data'
|
||||
import {
|
||||
testData,
|
||||
testDataSource,
|
||||
testDataSourceEmpty,
|
||||
testDataSourceUneven,
|
||||
} from '../../fixtures/table-data'
|
||||
|
||||
|
||||
describe('TableDataSource', function describeBlock() {
|
||||
|
@ -41,6 +46,37 @@ describe('TableDataSource', function describeBlock() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('isEmpty', () => {
|
||||
it('throws if no args passed', () => {
|
||||
expect(() => testDataSource.isEmpty()).toThrow()
|
||||
});
|
||||
|
||||
it('throws if row does not exist', () => {
|
||||
expect(() => testDataSource.isEmpty({rowIdx: 100})).toThrow()
|
||||
});
|
||||
|
||||
it('throws if col does not exist', () => {
|
||||
expect(() => testDataSource.isEmpty({colIdx: 100})).toThrow()
|
||||
});
|
||||
|
||||
it('returns correct value when checking cell', () => {
|
||||
expect(testDataSourceEmpty.isEmpty({rowIdx: 2, colIdx: 1})).toBe(true)
|
||||
expect(testDataSourceEmpty.isEmpty({rowIdx: 3, colIdx: 1})).toBe(true)
|
||||
expect(testDataSourceEmpty.isEmpty({rowIdx: 0, colIdx: 0})).toBe(false)
|
||||
});
|
||||
|
||||
it('returns correct value when checking col', () => {
|
||||
expect(testDataSourceEmpty.isEmpty({colIdx: 2})).toBe(true)
|
||||
expect(testDataSourceEmpty.isEmpty({colIdx: 0})).toBe(false)
|
||||
});
|
||||
|
||||
it('returns correct value when checking row', () => {
|
||||
expect(testDataSourceEmpty.isEmpty({rowIdx: 2})).toBe(true)
|
||||
expect(testDataSourceEmpty.isEmpty({rowIdx: 3})).toBe(true)
|
||||
expect(testDataSourceEmpty.isEmpty({rowIdx: 1})).toBe(false)
|
||||
});
|
||||
});
|
||||
|
||||
describe('rows', () => {
|
||||
it('returns all rows', () => {
|
||||
expect(testDataSource.rows()).toBe(testData.rows)
|
||||
|
|
12
spec/fixtures/table-data.es6
vendored
12
spec/fixtures/table-data.es6
vendored
|
@ -18,6 +18,16 @@ export const testDataUneven = {
|
|||
],
|
||||
}
|
||||
|
||||
export const testDataEmpty = {
|
||||
columns: ['col1', 'col2', ''],
|
||||
rows: [
|
||||
[1, 2],
|
||||
[4, 5, 6],
|
||||
['', ''],
|
||||
[],
|
||||
],
|
||||
}
|
||||
|
||||
class TestSource extends Table.TableDataSource {
|
||||
setRows(rows) {
|
||||
const data = {
|
||||
|
@ -32,6 +42,8 @@ export const testDataSource = new TestSource(testData)
|
|||
|
||||
export const testDataSourceUneven = new TestSource(testDataUneven)
|
||||
|
||||
export const testDataSourceEmpty = new TestSource(testDataEmpty)
|
||||
|
||||
export const selection = {colIdx: 0, rowIdx: 0, key: null}
|
||||
|
||||
export const cellProps = {tableDataSource: testDataSource, selection, colIdx: 0, rowIdx: 0, onSetSelection: () => {}, onCellEdited: () => {}}
|
||||
|
|
|
@ -45,7 +45,8 @@ export default class TableDataSource {
|
|||
* @method colAt
|
||||
*/
|
||||
colAt(colIdx) {
|
||||
return this._tableData.columns[colIdx] || null
|
||||
const col = this._tableData.columns[colIdx]
|
||||
return col != null ? col : null
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +91,41 @@ export default class TableDataSource {
|
|||
return this.colAt(colIdx)
|
||||
}
|
||||
const row = this.rowAt(rowIdx)
|
||||
return row ? row[colIdx] || null : null
|
||||
const cell = row ? row[colIdx] : null
|
||||
return cell != null ? cell : null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given cell, column, or row is empty
|
||||
*
|
||||
* ```
|
||||
* source.isEmpty({rowIdx: 1}) // true if row 1 is empty
|
||||
* ```
|
||||
*
|
||||
* @param {object} arg
|
||||
* @param {number} arg.rowIdx - Row index of cell
|
||||
* @param {number} arg.colIdx - Col index of cell
|
||||
* @return {any} - value for cell at given indices or null if it does not exist
|
||||
* @method cellAt
|
||||
*/
|
||||
isEmpty({rowIdx, colIdx} = {}) {
|
||||
if (rowIdx == null && colIdx == null) {
|
||||
throw new Error('TableDataSource::isEmpty - Must provide rowIdx and/or colIdx')
|
||||
}
|
||||
if (rowIdx == null) {
|
||||
const col = this.colAt(colIdx)
|
||||
if (col == null) {
|
||||
throw new Error('TableDataSource::isEmpty - Must provide a valid colIdx')
|
||||
}
|
||||
}
|
||||
const row = this.rowAt(rowIdx)
|
||||
if (!row) {
|
||||
throw new Error('TableDataSource::isEmpty - Must provide a valid rowIdx')
|
||||
}
|
||||
if (colIdx == null) {
|
||||
return row.every((el) => !el)
|
||||
}
|
||||
return !this.cellAt({rowIdx, colIdx})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
2
src/pro
2
src/pro
|
@ -1 +1 @@
|
|||
Subproject commit e04a35d00a2320a915d4164c886c6d7dd3f0d8f3
|
||||
Subproject commit 0e0a398fbcb4445c10d053da8636b552e0700201
|
Loading…
Reference in a new issue