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

Commit

Permalink
Merge pull request #805 from metasfresh/dev-801
Browse files Browse the repository at this point in the history
Included row: show row's references in context menu #801
  • Loading branch information
damianprzygodzki committed May 29, 2017
2 parents 172c24f + 93baec2 commit 568e682
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/actions/GenericActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ export function actionsRequest(entity, type, id, selected){
);
}

export function referencesRequest(entity, type, id){
export function referencesRequest(entity, type, docId, tabId, rowId){
return axios.get(
config.API_URL + '/' +
entity + '/' +
type + '/' +
id +
docId +
(tabId ? '/' + tabId : '') +
(rowId ? '/' + rowId : '') +
'/references'
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ body {
.context-menu {
position: fixed;
display: none;
width: 150px;
width: 180px;
background-color: #fff;
left: 0;
top: 0;
Expand Down
60 changes: 57 additions & 3 deletions src/components/table/TableContextMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
referencesRequest
} from '../../actions/GenericActions';

import {
setFilter
} from '../../actions/ListActions';
import {push} from 'react-router-redux';

import keymap from '../../keymap.js';

Expand All @@ -11,13 +19,15 @@ class TableContextMenu extends Component {
contextMenu:{
x:0,
y:0
}
},
references: []
}
}

componentDidMount() {
const {x, y, fieldName} = this.props;
const {x, y, fieldName, docId} = this.props;
this.setPosition(x, y, fieldName, this.contextMenu);
docId && this.getReferences();
}

getPosition = (dir, pos, element) => {
Expand Down Expand Up @@ -45,14 +55,39 @@ class TableContextMenu extends Component {
});
}

getReferences = () => {
const {docId, tabId, type, selected} = this.props;

referencesRequest('window', type, docId, tabId, selected[0])
.then(response => {
this.setState({
references: response.data.references

});
});
}

handleReferenceClick = (refType, filter) => {
const {
dispatch, type, docId
} = this.props;
dispatch(setFilter(filter, refType));
dispatch(push(
'/window/' + refType +
'?refType=' + type +
'&refId=' + docId
));
}

render() {
const {
blur, selected, mainTable, handleAdvancedEdit, handleOpenNewTab,
handleDelete, handleZoomInto
} = this.props;
const {contextMenu} = this.state;
const {contextMenu, references} = this.state;

const isSelectedOne = selected.length === 1;

return (
<div
className="context-menu context-menu-open panel-bordered panel-primary"
Expand Down Expand Up @@ -106,6 +141,25 @@ class TableContextMenu extends Component {
</span>
</div>
}

{references &&
<hr className="context-menu-separator" />
}

{references && references.map((item, index)=>
<div
className="context-menu-item"
key={index}
onClick={() => {
this.handleReferenceClick(item.documentType,
item.filter
)
}}
>
<i className="meta-icon-share" /> {item.caption}
</div>
)
}
</div>
)
}
Expand Down

0 comments on commit 568e682

Please sign in to comment.