-
Notifications
You must be signed in to change notification settings - Fork 13
/
OrgHomeTabs.jsx
142 lines (137 loc) · 5.52 KB
/
OrgHomeTabs.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import React from 'react';
import { Tabs, Tab } from '@material-ui/core';
import { get, map, reject, pickBy, isString, isObject, includes } from 'lodash';
import { ORANGE } from '../../common/constants';
import { currentUserHasAccess } from '../../common/utils';
import About from '../common/About';
import CustomText from '../common/CustomText';
import OrgHomeChildrenList from './OrgHomeChildrenList';
import NewResourceButton from '../common/NewResourceButton';
import CommonFormDrawer from '../common/CommonFormDrawer';
import SourceForm from '../sources/SourceForm';
import CollectionForm from '../collections/CollectionForm';
import ConfigSelect from '../common/ConfigSelect';
import MembersForm from './MembersForm'
const OrgHomeTabs = props => {
const {
tab, org, match, location, url, pins, showPin, onTabChange, onPinCreate, onPinDelete,
selectedConfig, customConfigs, onConfigChange, aboutTab, showConfigSelection,
} = props;
const tabConfigs = aboutTab ? selectedConfig.config.tabs : reject(selectedConfig.config.tabs, {type: 'about'});
const selectedTabConfig = tabConfigs[tab];
const about = get(org, 'text')
const [sourceForm, setSourceForm] = React.useState(false);
const [collectionForm, setCollectionForm] = React.useState(false);
const [membersForm, setMembersForm] = React.useState(false);
const [configFormWidth, setConfigFormWidth] = React.useState(false);
const hasAccess = currentUserHasAccess()
const onNewClick = resource => {
if(resource === 'source')
setSourceForm(true)
if(resource === 'collection')
setCollectionForm(true)
if(resource === 'editMembership')
setMembersForm(true)
}
const getSortParams = () => {
if(selectedTabConfig) {
if(selectedTabConfig.sortAsc)
return {sortAsc: selectedTabConfig.sortAsc}
if(selectedTabConfig.sortDesc)
return {sortDesc: selectedTabConfig.sortDesc}
}
}
const width = configFormWidth ? "calc(100% - " + (configFormWidth - 15) + "px)" : '100%';
const isInvalidTabConfig = !includes(['sources', 'collections', 'about', 'users', 'text'], selectedTabConfig.type) && !selectedTabConfig.uri;
return (
<div className='col-md-12 sub-tab' style={{width: width}}>
<Tabs className='sub-tab-header col-md-11 no-side-padding' value={tab} onChange={onTabChange} aria-label="concept-home-tabs" classes={{indicator: 'hidden'}}>
{
map(tabConfigs, config => <Tab key={config.label} label={config.label} />)
}
</Tabs>
{
hasAccess &&
<div className='col-md-1 no-right-padding flex-vertical-center' style={{justifyContent: 'flex-end'}}>
{
showConfigSelection &&
<span style={{marginRight: '10px'}}>
<ConfigSelect
selected={selectedConfig}
configs={customConfigs}
onChange={onConfigChange}
color={ORANGE}
resourceURL={url}
onWidthChange={setConfigFormWidth}
resource='orgs'
/>
</span>
}
<NewResourceButton resources={['source', 'collection', 'editMembership']} onClick={onNewClick} />
</div>
}
<div className='sub-tab-container' style={{display: 'flex', height: 'auto', width: '100%'}}>
{
isInvalidTabConfig &&
<div>Invalid Tab Configuration</div>
}
{
!isInvalidTabConfig && selectedTabConfig.type === 'about' &&
<About id={org.id} about={about} />
}
{
!isInvalidTabConfig && selectedTabConfig.type === 'text' &&
<div className='col-md-12'>
{
map(selectedTabConfig.fields, field => {
const value = field.value || get(org, field.id);
const label = field.label
return <CustomText key={value} title={label} value={value} format={field.format} />
})
}
</div>
}
{
!isInvalidTabConfig && !includes(['about', 'text'], selectedTabConfig.type) &&
<OrgHomeChildrenList
org={org}
location={location}
match={match}
url={selectedTabConfig.uri || url}
pins={pins}
showPin={showPin}
onPinCreate={onPinCreate}
onPinDelete={onPinDelete}
resource={selectedTabConfig.type}
viewFilters={pickBy(selectedTabConfig.filters, isString)}
extraControlFilters={pickBy(selectedTabConfig.filters, isObject)}
viewFields={selectedTabConfig.fields}
fixedFilters={{limit: selectedTabConfig.page_size, isTable: (selectedTabConfig.layout || '').toLowerCase() !== 'list', sortParams: getSortParams() }}
/>
}
</div>
<CommonFormDrawer
isOpen={sourceForm}
onClose={() => setSourceForm(false)}
formComponent={
<SourceForm onCancel={() => setSourceForm(false)} reloadOnSuccess={tab==0} parentURL={url} />
}
/>
<CommonFormDrawer
isOpen={collectionForm}
onClose={() => setCollectionForm(false)}
formComponent={
<CollectionForm onCancel={() => setCollectionForm(false)} reloadOnSuccess={tab==1} parentURL={url} />
}
/>
<CommonFormDrawer
isOpen={membersForm}
onClose={() => setMembersForm(false)}
formComponent={
<MembersForm onCancel={() => setMembersForm(false)} reloadOnSuccess={tab==2} parentURL={url} />
}
/>
</div>
);
}
export default OrgHomeTabs;