From 773e30da12d3778623162a935aba63a5c9c9365b Mon Sep 17 00:00:00 2001 From: katarzynadunikowska Date: Mon, 29 May 2017 14:18:27 +0200 Subject: [PATCH] Included row: show row's references in context menu #801 --- src/actions/GenericActions.js | 6 ++- src/assets/css/styles.css | 2 +- src/components/table/TableContextMenu.js | 61 ++++++++++++++++++++++-- src/components/widget/Lookup/Lookup.js | 2 +- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/actions/GenericActions.js b/src/actions/GenericActions.js index 7861d0c5d..a5eb70e17 100644 --- a/src/actions/GenericActions.js +++ b/src/actions/GenericActions.js @@ -186,12 +186,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' ); } diff --git a/src/assets/css/styles.css b/src/assets/css/styles.css index 370417414..6da15dbcc 100644 --- a/src/assets/css/styles.css +++ b/src/assets/css/styles.css @@ -107,7 +107,7 @@ body { .context-menu { position: fixed; display: none; - width: 150px; + width: 180px; background-color: #fff; left: 0; top: 0; diff --git a/src/components/table/TableContextMenu.js b/src/components/table/TableContextMenu.js index cb3cdd480..44a55e702 100644 --- a/src/components/table/TableContextMenu.js +++ b/src/components/table/TableContextMenu.js @@ -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'; @@ -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) => { @@ -45,14 +55,40 @@ class TableContextMenu extends Component { }); } + getReferences = () => { + const {dispatch, docId, tabId, type, selected} = this.props; + + dispatch( + 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 (
} + + {references && +
+ } + + {references && references.map((item, index)=> +
{ + this.handleReferenceClick(item.documentType, + item.filter + ) + }} + > + {item.caption} +
+ ) + } ) } diff --git a/src/components/widget/Lookup/Lookup.js b/src/components/widget/Lookup/Lookup.js index 038c1253c..b8d0da345 100644 --- a/src/components/widget/Lookup/Lookup.js +++ b/src/components/widget/Lookup/Lookup.js @@ -273,7 +273,7 @@ class Lookup extends Component { validLocal: response.data.values.length === 0 && handleChangeOnFocus!==true ? false : true }); - }).catch((err) => { + }).catch(() => { this.setState({ list: [], loading: false