-
Notifications
You must be signed in to change notification settings - Fork 12
/
HomeTabs.jsx
144 lines (138 loc) · 5.23 KB
/
HomeTabs.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
143
144
import React from 'react';
import { Tabs, Tab } from '@material-ui/core';
import { map, reject, get } from 'lodash';
import { ORANGE, BLUE } from '../../common/constants';
import { currentUserHasAccess } from '../../common/utils';
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 DynamicConfigResourceIcon from '../common/DynamicConfigResourceIcon'
import MembersForm from './MembersForm'
const HomeTabs = props => {
const {
tab, url, onTabChange, selectedConfig, customConfigs, onConfigChange,
aboutTab, showConfigSelection, tabColor, isOCLDefaultConfigSelected, org
} = props;
const tabConfigs = aboutTab ? selectedConfig.config.tabs : reject(selectedConfig.config.tabs, {type: 'about'});
const selectedTabConfig = tabConfigs[tab];
const selectedTabColor = get(selectedTabConfig, 'color') || tabColor;
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 getTABHref = tabConfig => {
let href = '';
if(tabConfig.type === 'about')
href = `#${org.url}about`
else if(tabConfig.type === 'versions')
href = `#${org.url}versions`
else if(tabConfig.type === 'users')
href = `#${org.url}members`
else if(tabConfig.href)
href = `#${org.url}${tabConfig.href}`
else {
const urlAttr = tabConfig.type + '_url'
href = `#${org[urlAttr]}`
}
let queryString = location.hash.split('?')[1] || ''
if(queryString)
queryString = `?${queryString}`
return href + queryString
}
const width = configFormWidth ? "calc(100% - " + (configFormWidth - 15) + "px)" : '100%';
return (
<div className='col-md-12 no-side-padding' style={{width: width}}>
<Tabs className='col-md-11 no-side-padding' value={tab} onChange={onTabChange} TabIndicatorProps={{style: {background: selectedTabColor}}} indicatorColor='primary'>
{
map(tabConfigs, (config, index) => {
const key = config.label + index
const isSelected = index === tab
const color = config.color || tabColor
const label = (
<span className='flex-vertical-center' style={isSelected ? {color: color || BLUE} : {}}>
<DynamicConfigResourceIcon icon={config.icon} resource={config.type} index={tabConfigs.indexOf(config)} style={{width: '0.7em'}} />
<span style={{marginLeft: '4px'}}>{config.label}</span>
</span>
);
if(isOCLDefaultConfigSelected)
return (
<Tab
style={color ? {color: color}: {}}
index={index}
key={key}
id={key}
label={label}
component="a"
href={getTABHref(config)}
className='capitalize'
/>
)
return (
<Tab
style={color ? {color: color}: {}}
index={index}
key={key}
id={key}
label={label}
className='capitalize'
/>
)
})
}
</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 color={tabColor} resources={['source', 'collection', 'editMembership']} onClick={onNewClick} />
</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 HomeTabs;