Skip to content

Commit 9e3d575

Browse files
Merge pull request #163 from blackjackkent/development
Production deployment v1.4.1
2 parents d65d061 + 7691747 commit 9e3d575

7 files changed

Lines changed: 94 additions & 11 deletions

File tree

src/display/shared/columns/threads/LastPoster.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import React from 'react';
33
import columns from '../../../../infrastructure/constants/columns';
44

5+
const stopPropagation = (e) => e.stopPropagation();
6+
57
export default (lastPosters, includeFilter) => ({
68
Header: columns.LAST_POSTER.name,
79
accessor: columns.LAST_POSTER.key,
@@ -12,6 +14,7 @@ export default (lastPosters, includeFilter) => ({
1214
target="_blank"
1315
rel="noopener noreferrer"
1416
href={row.original.status && row.original.status.lastPostUrl}
17+
onClick={stopPropagation}
1518
>
1619
{row.value} <i className="fas fa-external-link-alt" />
1720
</a>

src/display/views/help/components/AboutTrackerPane.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const AboutTrackerPane = () => (
7575
<strong>Megabyte Tier ($10 a month)</strong>
7676
</p>
7777
<ul>
78-
<li>Carla Page</li>
7978
<li>Insolitus-Academy</li>
8079
<li>girl-next-door-writes</li>
8180
<li>Jess</li>

src/display/views/help/components/__tests__/__snapshots__/AboutTrackerPane.spec.js.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ exports[`rendering snapshots should render valid snapshot 1`] = `
166166
</strong>
167167
</p>
168168
<ul>
169-
<li>
170-
Carla Page
171-
</li>
172169
<li>
173170
Insolitus-Academy
174171
</li>

src/display/views/threads/components/CheckboxTable.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class CheckboxTable extends React.Component {
2929
};
3030
this.toggleSelection = this.toggleSelection.bind(this);
3131
this.getTrProps = this.getTrProps.bind(this);
32+
this.getTdProps = this.getTdProps.bind(this);
3233
this.toggleAll = this.toggleAll.bind(this);
3334
this.isSelected = this.isSelected.bind(this);
3435
this.clearSelection = this.clearSelection.bind(this);
@@ -54,6 +55,17 @@ class CheckboxTable extends React.Component {
5455
return {};
5556
}
5657

58+
getTdProps(state, rowInfo, column, instance) {
59+
const { getTdProps } = this.props;
60+
return getTdProps(state, rowInfo, column, instance, () => {
61+
if (rowInfo) {
62+
const row = rowInfo.original;
63+
// eslint-disable-next-line no-underscore-dangle
64+
this.toggleSelection(`select-${row._id}`, false, row);
65+
}
66+
});
67+
}
68+
5769
toggleSelection(key, shift, row) {
5870
let { selection } = this.state;
5971
const { data, onSelectionChanged } = this.props;
@@ -115,7 +127,6 @@ class CheckboxTable extends React.Component {
115127
noDataText,
116128
defaultFilterMethod,
117129
SubComponent,
118-
getTdProps,
119130
defaultSorted,
120131
defaultPageSize,
121132
onPageSizeChange
@@ -141,8 +152,8 @@ class CheckboxTable extends React.Component {
141152
defaultPageSize={defaultPageSize}
142153
onPageSizeChange={onPageSizeChange}
143154
columns={columns}
144-
getTdProps={getTdProps}
145155
getTrProps={this.getTrProps}
156+
getTdProps={this.getTdProps}
146157
defaultSorted={defaultSorted}
147158
defaultFilterMethod={defaultFilterMethod}
148159
showPaginationTop

src/display/views/threads/components/__tests__/CheckboxTable.spec.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('behavior', () => {
8181
}
8282
]);
8383
});
84-
it('should trigger onSelectionChanged when item is added', () => {
84+
it('should trigger onSelectionChanged when item is removed', () => {
8585
const onSelectionChanged = jest.fn();
8686
const props = createTestProps({
8787
onSelectionChanged
@@ -130,6 +130,44 @@ describe('behavior', () => {
130130
element.update();
131131
expect(element.find('RTSelectTable').props().selectAll).toBe(true);
132132
});
133+
it('should support toggling selection from td props, to allow clicking empty space on the row to select it', () => {
134+
const onSelectionChanged = jest.fn();
135+
const props = createTestProps({
136+
onSelectionChanged,
137+
getTdProps: jest.fn(() => ({}))
138+
});
139+
const state = {};
140+
const rowInfo = { original: props.data[0] };
141+
const column = {};
142+
const instance = {};
143+
const jsx = <CheckboxTable {...props} />;
144+
const element = shallow(jsx);
145+
element.instance().getTdProps(state, rowInfo, column, instance);
146+
expect(props.getTdProps).toBeCalledWith(
147+
state,
148+
rowInfo,
149+
column,
150+
instance,
151+
expect.any(Function)
152+
);
153+
const toggleSelectionCallback = props.getTdProps.mock.calls[0][4];
154+
toggleSelectionCallback();
155+
expect(onSelectionChanged).toHaveBeenCalledTimes(1);
156+
expect(onSelectionChanged).toHaveBeenLastCalledWith([{ _id: 1, testProp: 'test1' }]);
157+
});
158+
it('should color selected rows', () => {
159+
const props = createTestProps({
160+
getTdProps: jest.fn(() => ({}))
161+
});
162+
const rowInfo = { original: props.data[0] };
163+
const jsx = <CheckboxTable {...props} />;
164+
const element = shallow(jsx);
165+
element.instance().getTdProps({}, rowInfo, {}, {});
166+
const toggleSelectionCallback = props.getTdProps.mock.calls[0][4];
167+
toggleSelectionCallback();
168+
const trProps = element.instance().getTrProps({}, rowInfo);
169+
expect(typeof trProps.style.backgroundColor).toBe('string');
170+
});
133171
it('should set select-all checkbox checked when selected items length equals row length', () => {});
134172
});
135173
describe('toggleAll', () => {
@@ -186,7 +224,7 @@ describe('behavior', () => {
186224
const isSelected = element.instance().isSelected(1);
187225
expect(isSelected).toBe(true);
188226
});
189-
it('should return true if item is not selected', () => {
227+
it('should return false if item is not selected', () => {
190228
const props = createTestProps();
191229
const jsx = <CheckboxTable {...props} />;
192230
const element = mount(jsx);

src/display/views/threads/components/__tests__/_getTdProps.spec.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,32 @@ describe('behavior', () => {
9191
});
9292
});
9393
});
94+
describe('row selection', () => {
95+
it('should not toggle row selection if onClick handled the action', () => {
96+
const clickedColumn = { id: 'editButton' };
97+
const toggleSelection = jest.fn();
98+
const propsCreator = _getTdProps(jest.fn(), jest.fn(), jest.fn(), jest.fn());
99+
const props = propsCreator({}, { original: {} }, clickedColumn, {}, toggleSelection);
100+
props.onClick({}, jest.fn());
101+
expect(toggleSelection).not.toBeCalled();
102+
});
103+
it('should toggle row selection if onClick did not handle the action', () => {
104+
const clickedColumn = { id: 'unrecognized' };
105+
const toggleSelection = jest.fn();
106+
const propsCreator = _getTdProps(jest.fn(), jest.fn(), jest.fn(), jest.fn());
107+
const props = propsCreator({}, { original: {} }, clickedColumn, {}, toggleSelection);
108+
props.onClick({}, jest.fn());
109+
expect(toggleSelection).toBeCalled();
110+
});
111+
it('should not toggle row selection if onClick did not handle the action and the column is an Expander', () => {
112+
const clickedColumn = { id: 'unrecognized', Expander: jest.fn() };
113+
const toggleSelection = jest.fn();
114+
const propsCreator = _getTdProps(jest.fn(), jest.fn(), jest.fn(), jest.fn());
115+
const props = propsCreator({}, { original: {} }, clickedColumn, {}, toggleSelection);
116+
props.onClick({}, jest.fn());
117+
expect(toggleSelection).not.toBeCalled();
118+
});
119+
});
94120
describe('handleOriginal', () => {
95121
it('should fall back to handleOriginal in other cases', () => {
96122
const clickedColumn = {
@@ -105,7 +131,7 @@ describe('behavior', () => {
105131
};
106132
const handleOriginal = jest.fn();
107133
const propsCreator = _getTdProps(jest.fn(), jest.fn(), jest.fn(), jest.fn());
108-
const props = propsCreator({}, clickedRow, clickedColumn);
134+
const props = propsCreator({}, clickedRow, clickedColumn, {}, jest.fn());
109135
props.onClick({}, handleOriginal);
110136
expect(handleOriginal).toHaveBeenCalledTimes(1);
111137
});
@@ -121,7 +147,7 @@ describe('behavior', () => {
121147
}
122148
};
123149
const propsCreator = _getTdProps(jest.fn(), jest.fn(), jest.fn(), jest.fn());
124-
const props = propsCreator({}, clickedRow, clickedColumn);
150+
const props = propsCreator({}, clickedRow, clickedColumn, {}, jest.fn());
125151
props.onClick({}, null);
126152
expect(true).toBe(true);
127153
});

src/display/views/threads/components/_getTdProps.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import columns from '../../../../infrastructure/constants/columns';
22

33
const getTdProps = (onDeleteTrigger, onEditTrigger, onArchiveTrigger, onQueueTrigger) => {
4-
const generateTdProps = (state, row, column) => ({
4+
const generateTdProps = (state, row, column, _instance, toggleSelection) => ({
55
onClick: (e, handleOriginal) => {
66
if (column.id === columns.DELETE_BUTTON.key) {
77
onDeleteTrigger(row.original.thread);
@@ -19,6 +19,15 @@ const getTdProps = (onDeleteTrigger, onEditTrigger, onArchiveTrigger, onQueueTri
1919
onQueueTrigger(row.original.thread);
2020
return;
2121
}
22+
23+
// there's a bug in react-table where triggering selection state change
24+
// undoes expansion. this manifests as the expand button not doing anything
25+
// when clicked. we can workaround because we don't selection to happen
26+
// on expansion anyway
27+
if (!column.Expander) {
28+
toggleSelection();
29+
}
30+
2231
if (handleOriginal) {
2332
handleOriginal();
2433
}

0 commit comments

Comments
 (0)