Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Packageables window: up/down arrows are working weird #923
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunkat committed Jun 27, 2017
1 parent 91566fc commit 4aa95db
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
34 changes: 33 additions & 1 deletion src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,8 @@ export function mapIncluded(
let ind = indent ? indent : [];
let result = [];

let includedMap = [];

const nodeCopy = Object.assign({}, node, {
indent: ind
});
Expand All @@ -837,6 +839,7 @@ export function mapIncluded(
}

if(node.includedDocuments){
includedMap = includedMap.push(node);
for(let i = 0; i < node.includedDocuments.length; i++){
let copy = node.includedDocuments[i];
if(i === node.includedDocuments.length - 1){
Expand All @@ -850,10 +853,39 @@ export function mapIncluded(
)
}
}

return result;
}

export function collapsedMap(
node, isCollapsed, initialMap
) {
let collapsedMap = [];
if(initialMap){
if(!isCollapsed) {
initialMap.splice(
initialMap.indexOf(node.includedDocuments[0]),
node.includedDocuments.length
);
collapsedMap = initialMap;
} else {
initialMap.map(item => {
collapsedMap.push(item);
if(item.id === node.id) {
collapsedMap = collapsedMap.concat(node.includedDocuments);

}
});
}

} else {
if(node.includedDocuments){
collapsedMap.push(node);
}
}

return collapsedMap;
}

export function connectWS(topic, cb) {
(this.sockClient && this.sockClient.connected) &&
this.sockClient.disconnect();
Expand Down
31 changes: 26 additions & 5 deletions src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
selectTableItems,
deleteLocal,
mapIncluded,
collapsedMap,
getItemsByProperty,
getZoomIntoWindow
} from '../../actions/WindowActions';
Expand Down Expand Up @@ -52,7 +53,8 @@ class Table extends Component {
rows: [],
collapsedRows: [],
collapsedParentsRows: [],
pendingInit: true
pendingInit: true,
collapsedArrayMap: []
}
}

Expand Down Expand Up @@ -133,12 +135,17 @@ class Table extends Component {
document.getElementsByClassName('js-table')[0].focus();
}

let mapCollapsed = [];
if(collapsible){

rows && !!rows.length && rows.map(row => {
if(
row.indent.length >= expandedDepth &&
row.includedDocuments
){
mapCollapsed = mapCollapsed.concat(
collapsedMap(row)
);
this.setState(prev => ({
collapsedParentsRows:
prev.collapsedParentsRows.concat(
Expand All @@ -156,6 +163,10 @@ class Table extends Component {
}
})
}

this.setState({
collapsedArrayMap: mapCollapsed
});
})
} else {
this.setState({
Expand Down Expand Up @@ -271,7 +282,7 @@ class Table extends Component {
}

handleKeyDown = (e) => {
const {selected, rows, listenOnKeys} = this.state;
const {selected, rows, listenOnKeys, collapsedArrayMap} = this.state;

if(!listenOnKeys){
return;
Expand Down Expand Up @@ -299,7 +310,9 @@ class Table extends Component {
case 'ArrowDown': {
e.preventDefault();

const array = rows.map((item) => item[keyProperty]);
const array = collapsedArrayMap.length > 0 ?
collapsedArrayMap.map((item) => item[keyProperty]) :
rows.map((item) => item[keyProperty]);
const currentId = array.findIndex(x =>
x === selected[selected.length-1]
);
Expand All @@ -322,7 +335,9 @@ class Table extends Component {
case 'ArrowUp': {
e.preventDefault();

const array = rows.map(item => item[keyProperty]);
const array = collapsedArrayMap.length > 0 ?
collapsedArrayMap.map((item) => item[keyProperty]) :
rows.map((item) => item[keyProperty]);
const currentId = array.findIndex(x =>
x === selected[selected.length-1]
);
Expand Down Expand Up @@ -615,7 +630,13 @@ class Table extends Component {

handleRowCollapse = (node, collapsed) => {
const {keyProperty} = this.props;
const {collapsedParentsRows, collapsedRows} = this.state;
const {
collapsedParentsRows, collapsedRows, collapsedArrayMap
} = this.state;

this.setState({
collapsedArrayMap: collapsedMap(node, collapsed, collapsedArrayMap)
});

if(collapsed){
this.setState(prev => ({
Expand Down

0 comments on commit 4aa95db

Please sign in to comment.