-
-
Notifications
You must be signed in to change notification settings - Fork 73
Issue 524 - Readonly dropdown column content #530
Changes from all commits
b95b9b3
a12f1ce
f1ad4d2
b5de56c
234f87c
0a98f3e
1605c11
776062b
60b3fd7
bc362da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ const mapRow = R.addIndex<IColumn, JSX.Element>(R.map); | |
|
||
enum CellType { | ||
Dropdown, | ||
DropdownLabel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make it easier to distinguish between the general label case and the dropdown one. Processing is different. |
||
Input, | ||
Label | ||
} | ||
|
@@ -40,7 +41,7 @@ function getCellType( | |
case Presentation.Input: | ||
return (!active || !editable) ? CellType.Label : CellType.Input; | ||
case Presentation.Dropdown: | ||
return (!dropdown || !editable) ? CellType.Label : CellType.Dropdown; | ||
return (!dropdown || !editable) ? CellType.DropdownLabel : CellType.Dropdown; | ||
default: | ||
return (!active || !editable) ? CellType.Label : CellType.Input; | ||
} | ||
|
@@ -124,7 +125,9 @@ class Contents { | |
'dash-cell-value' | ||
].join(' '); | ||
|
||
switch (getCellType(active, column.editable, dropdown && dropdown.options, column.presentation)) { | ||
const cellType = getCellType(active, column.editable, dropdown && dropdown.options, column.presentation); | ||
|
||
switch (cellType) { | ||
case CellType.Dropdown: | ||
return (<CellDropdown | ||
key={`column-${columnIndex}`} | ||
|
@@ -148,15 +151,26 @@ class Contents { | |
type={column.type} | ||
value={datum[column.id]} | ||
/>); | ||
case CellType.DropdownLabel: | ||
case CellType.Label: | ||
default: | ||
const resolvedValue = cellType === CellType.DropdownLabel ? | ||
this.resolveDropdownLabel(dropdown, datum[column.id]) : | ||
formatters[columnIndex](datum[column.id]); | ||
|
||
return (<CellLabel | ||
className={className} | ||
key={`column-${columnIndex}`} | ||
onClick={this.handlers(Handler.Click, rowIndex, columnIndex)} | ||
onDoubleClick={this.handlers(Handler.DoubleClick, rowIndex, columnIndex)} | ||
value={formatters[columnIndex](datum[column.id])} | ||
value={resolvedValue} | ||
/>); | ||
} | ||
} | ||
|
||
private resolveDropdownLabel(dropdown: IDropdown | undefined, value: any) { | ||
const dropdownValue = dropdown && dropdown.options && dropdown.options.find(option => option.value === value); | ||
|
||
return dropdownValue ? dropdownValue.label : value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ describe('filter', () => { | |
DashTable.getFilterById('ccc').click(); | ||
|
||
DashTable.getFilterById('bbb').within(() => cy.get('input').should('have.value', 'Tr')); | ||
DashTable.getCellById(0, 'bbb-readonly').within(() => cy.get('.dash-cell-value').should('have.html', 'Tropical Beaches')); | ||
DashTable.getCellById(0, 'bbb-readonly').within(() => cy.get('.dash-cell-value').should('have.html', 'label: Tropical Beaches')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update tests involving dropdowns so as to expect the |
||
}); | ||
|
||
it('filters `Numeric` columns with `equal` without operator', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,25 @@ Object.values([AppMode.ReadOnly]).forEach(mode => { | |
}); | ||
|
||
it('can sort', () => { | ||
DashTable.getCell(0, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Wet')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Snowy')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Tropical Beaches')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Humid')); | ||
DashTable.getCell(0, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Wet')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Snowy')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Tropical Beaches')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
|
||
DashTable.getCell(0, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Wet')); | ||
DashTable.getCell(1, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Snowy')); | ||
DashTable.getCell(2, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Tropical Beaches')); | ||
DashTable.getCell(3, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also check the readonly column |
||
cy.get('tr th.column-6 .sort').last().click(); | ||
DashTable.getCell(0, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Humid')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Humid')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Humid')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'Humid')); | ||
DashTable.getCell(0, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
|
||
DashTable.getCell(0, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also check the readonly column |
||
DashTable.getCell(1, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(2, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(3, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,25 @@ Object.values(ReadWriteModes).forEach(mode => { | |
}); | ||
|
||
it('can sort', () => { | ||
DashTable.getCell(0, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Wet')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Snowy')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Tropical Beaches')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Humid')); | ||
DashTable.getCell(0, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Wet')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Snowy')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Tropical Beaches')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Humid')); | ||
|
||
DashTable.getCell(0, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Wet')); | ||
DashTable.getCell(1, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Snowy')); | ||
DashTable.getCell(2, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Tropical Beaches')); | ||
DashTable.getCell(3, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also check the readonly column |
||
cy.get('tr th.column-6 .sort').last().click(); | ||
DashTable.getCell(0, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Humid')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Humid')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Humid')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.Select-value-label').should('have.html', 'Humid')); | ||
DashTable.getCell(0, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Humid')); | ||
DashTable.getCell(1, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Humid')); | ||
DashTable.getCell(2, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Humid')); | ||
DashTable.getCell(3, 6).within(() => cy.get('.Select-value-label').should('have.html', 'label: Humid')); | ||
|
||
DashTable.getCell(0, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(1, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(2, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
DashTable.getCell(3, 7).within(() => cy.get('.dash-cell-value').should('have.html', 'label: Humid')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also check the readonly column |
||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,48 @@ const columns2 = R.map( | |
); | ||
|
||
storiesOf('DashTable/Dropdown', module) | ||
.add('readonly dropdown shows label', () => <DataTable | ||
setProps={setProps} | ||
id='table' | ||
data={data} | ||
columns={columns} | ||
editable={false} | ||
dropdown={{ | ||
climate: { | ||
options: R.map( | ||
i => ({ label: `label: ${i}`, value: i }), | ||
['Sunny', 'Snowy', 'Rainy'] | ||
) | ||
}, | ||
city: { | ||
options: R.map( | ||
i => ({ label: `label: ${i}`, value: i }), | ||
['NYC', 'Montreal', 'Miami'] | ||
) | ||
} | ||
}} | ||
/>) | ||
.add('editable dropdown shows label', () => <DataTable | ||
setProps={setProps} | ||
id='table' | ||
data={data} | ||
columns={columns} | ||
editable={true} | ||
dropdown={{ | ||
climate: { | ||
options: R.map( | ||
i => ({ label: `label: ${i}`, value: i }), | ||
['Sunny', 'Snowy', 'Rainy'] | ||
) | ||
}, | ||
city: { | ||
options: R.map( | ||
i => ({ label: `label: ${i}`, value: i }), | ||
['NYC', 'Montreal', 'Miami'] | ||
) | ||
} | ||
}} | ||
/>) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. visual tests for readonly and editable dropdowns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used in conjonction with the updated standalone tests above |
||
.add('dropdown by column', () => (<DataTable | ||
setProps={setProps} | ||
id='table' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Differentiate between the label and value to catch these differences in the tests.