Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Allow renaming single-row headers #549

Merged
merged 3 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
[#314](https://github.com/plotly/dash-table/issues/533)
### Fixed
[#533](https://github.com/plotly/dash-table/issues/533)
- Fixed problem clearing one column shifting everything to the left and
leaving the last column blank
- Add merge_duplicate_headers prop to correct `export_format: display` behaviour.
[#549](https://github.com/plotly/dash-table/issues/549)
- Fixed renaming of single-row headers in the GUI

## [4.1.0] - 2019-08-05
### Added
Expand Down
15 changes: 15 additions & 0 deletions demo/AppMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum AppMode {
MergeDuplicateHeaders = 'mergeDuplicateHeaders',
ReadOnly = 'readonly',
ColumnsInSpace = 'columnsInSpace',
SingleHeaders = 'singleHeaders',
TaleOfTwoTables = 'taleOfTwoTables',
Tooltips = 'tooltips',
Typed = 'typed',
Expand Down Expand Up @@ -193,6 +194,18 @@ function getTypedState() {
return state;
}

function getSingleHeaderState() {
const state = getDefaultState();

R.forEach(column => {
if (Array.isArray(column.name)) {
column.name = column.name[column.name.length - 1];
}
}, state.tableProps.columns || []);

return state;
}

function getActionableState() {
const state = getDefaultState();
state.tableProps.filter_action = TableAction.Native;
Expand Down Expand Up @@ -378,6 +391,8 @@ function getState() {
return getVirtualizedState();
case AppMode.Typed:
return getTypedState();
case AppMode.SingleHeaders:
return getSingleHeaderState();
case AppMode.TaleOfTwoTables:
case AppMode.Default:
default:
Expand Down
4 changes: 2 additions & 2 deletions src/dash-table/utils/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export function changeColumnHeader(column, columns, headerRowIndex, mergeDuplica
);

R.range(groupIndexFirst, groupIndexLast + 1).map(i => {
let namePath;
const namePath = [i, 'name'];
if (R.type(newColumns[i].name) === 'Array') {
namePath = [i, 'name', headerRowIndex];
namePath.push(headerRowIndex);
}
newColumns = R.set(R.lensPath(namePath), newColumnName, newColumns);
});
Expand Down
33 changes: 25 additions & 8 deletions tests/cypress/tests/standalone/edit_headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import DashTable from 'cypress/DashTable';
import { AppMode } from 'demo/AppMode';

describe(`edit, mode=${AppMode.Typed}`, () => {
beforeEach(() => {
cy.visit(`http://localhost:8080?mode=${AppMode.Typed}`);
DashTable.toggleScroll(false);
});

describe(`edit headers, mode=${AppMode.Typed}`, () => {
beforeEach(() => {
cy.visit(`http://localhost:8080?mode=${AppMode.Typed}`);
DashTable.toggleScroll(false);
});

it('changing the column 0 header should not change any column 0 headers below it ', () => {
it('changing the column 0 header should not change any column 0 headers below it', () => {
cy.window().then((win: any) => {
cy.stub(win, 'prompt').returns('Hello');
});
Expand All @@ -37,7 +32,7 @@ describe(`edit, mode=${AppMode.Typed}`, () => {
cy.visit(`http://localhost:8080?mode=${AppMode.MergeDuplicateHeaders}`);
DashTable.toggleScroll(false);
});
it('changing the column 0 header should not change any column 0 headers below it ', () => {
it('changing the column 0 header should not change any column 0 headers below it', () => {
cy.window().then((win: any) => {
cy.stub(win, 'prompt').returns('Otter');
});
Expand All @@ -55,4 +50,26 @@ describe(`edit, mode=${AppMode.Typed}`, () => {
cy.get('.dash-header.column-6 > div > span:last-child').should('have.html', ``);
});
});
});

describe(`edit headers, mode=${AppMode.SingleHeaders}`, () => {
beforeEach(() => {
cy.visit(`http://localhost:8080?mode=${AppMode.SingleHeaders}`);
DashTable.toggleScroll(false);
});
it('allows changing single-row column 0 header', () => {
cy.window().then((win: any) => {
cy.stub(win, 'prompt').returns('Russia');
});
cy.get('.dash-header.column-0 .column-header--edit').eq(0).click();
cy.get('.dash-header.column-0 > div > span:last-child').should('have.html', 'Russia');
});
it('changing the column 1 header should not change any other headers', () => {
cy.window().then((win: any) => {
cy.stub(win, 'prompt').returns('Alaska');
});
cy.get('.dash-header.column-1 .column-header--edit').eq(0).click();
cy.get('.dash-header.column-0 > div > span:last-child').should('have.html', 'rows');
cy.get('.dash-header.column-1 > div > span:last-child').should('have.html', 'Alaska');
});
});
});