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 #467 from metasfresh/dev-448
Browse files Browse the repository at this point in the history
Dev 448
  • Loading branch information
damianprzygodzki committed Mar 2, 2017
2 parents 258389c + 466f768 commit c33b622
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,16 @@ export function createWindow(windowType, docId = 'NEW', tabId, rowId, isModal =
).then(response => {
let tabTmp = {};

response.layout.tabs && response.layout.tabs.map(tab => {
response.layout.tabs && response.layout.tabs.map((tab, index) => {
tabTmp[tab.tabid] = {};
dispatch(getTab(tab.tabid, windowType, docId)).then(res => {
tabTmp[tab.tabid] = res;
dispatch(addRowData(tabTmp, getScope(isModal)));
})

if(index === 0 || !tab.queryOnActivate){
dispatch(getTab(tab.tabid, windowType, docId)).then(res => {
tabTmp[tab.tabid] = res;
dispatch(addRowData(tabTmp, getScope(isModal)));
})
}

}
)
}).catch((err) => {
Expand All @@ -238,7 +242,7 @@ export function createWindow(windowType, docId = 'NEW', tabId, rowId, isModal =
}
}

function getTab(tabId, windowType, docId) {
export function getTab(tabId, windowType, docId) {
return dispatch =>
dispatch(getData('window', windowType, docId, tabId))
.then(res => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class Window extends Component {
tabIndex={this.tabIndex.tabs}
toggleTableFullScreen={this.toggleTableFullScreen}
fullScreen={fullScreen}
windowType={type}
>
{tabs.map((elem)=> {
const {
tabid, caption, elements, emptyResultText, emptyResultHint
tabid, caption, elements, emptyResultText,
emptyResultHint, queryOnActivate
} = elem;
return (
<Table
Expand All @@ -70,6 +72,7 @@ class Window extends Component {
emptyHint={emptyResultHint}
newRow={newRow}
tabIndex={this.tabIndex.tabs}
queryOnActivate={queryOnActivate}
/>
)
})}
Expand Down
41 changes: 41 additions & 0 deletions src/components/tabs/Tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { Component, PropTypes } from 'react';
import {connect} from 'react-redux';

import {
getTab,
addRowData
} from '../../actions/WindowActions';

class Tab extends Component {
constructor(props) {
super(props);

const {
dispatch, tabid, windowType, queryOnActivate, docId
} = this.props;

if(queryOnActivate){
dispatch(getTab(tabid, windowType, docId)).then(res => {
dispatch(addRowData({[tabid]: res}, 'master'));
});
}
}

render() {
const {children} = this.props;

return (
<div>
{children}
</div>
);
}
}

Tab.propTypes = {
dispatch: PropTypes.func.isRequired
};

Tab = connect()(Tab);

export default Tab;
24 changes: 21 additions & 3 deletions src/components/tabs/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { Component } from 'react';

import Tab from './Tab';

class Tabs extends Component {
constructor(props) {
super(props);
Expand All @@ -24,6 +26,7 @@ class Tabs extends Component {
renderPills = (pills) => {
const {tabIndex} = this.props;
const maxWidth = (95 / pills.length) + '%';
const {selected} = this.state;

return pills.map((item) => {
return (
Expand All @@ -35,15 +38,25 @@ class Tabs extends Component {
onKeyDown={(e) => this.handlePillKeyDown(e, item.key)}
style={{ maxWidth }}
>
<a className={'nav-link ' + ((this.state.selected === item.key) ? 'active' : '')}>{item.props.caption}</a>
<a
className={
'nav-link ' +
((selected === item.key) ? 'active' : '')
}
>
{item.props.caption}
</a>
</li>
);
});
}

renderTabs = (tabs) => {
const {toggleTableFullScreen, fullScreen} = this.props;
const {
toggleTableFullScreen, fullScreen, windowType
} = this.props;
const {selected} = this.state;

return tabs.map((item) => {
const itemWithProps = Object.assign({}, item, {
props: Object.assign({}, item.props, {
Expand All @@ -53,12 +66,16 @@ class Tabs extends Component {
});

if(selected == item.key){
const {tabid, queryOnActivate, docId} = item.props;

return (
<div
key={'pane' + item.key}
className="tab-pane active"
>
{itemWithProps}
<Tab {...{queryOnActivate, tabid, docId, windowType}}>
{itemWithProps}
</Tab>
</div>
);
}else{
Expand All @@ -70,6 +87,7 @@ class Tabs extends Component {

render() {
const {children, tabIndex, fullScreen} = this.props;

return (
<div className={
'mb-1 ' +
Expand Down

0 comments on commit c33b622

Please sign in to comment.