Skip to content

Commit

Permalink
Org | custom configs driven layout
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Feb 2, 2021
1 parent 130be7e commit b6e6211
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 91 deletions.
29 changes: 29 additions & 0 deletions src/components/app/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ td.pagination-center {
-webkit-box-orient: vertical;
overflow: hidden;
}
.ellipsis-text-3 {
text-overflow: ellipsis;
overflow: hidden;
}
.gray-italics {
color: gray;
font-style: italic;
Expand Down Expand Up @@ -497,3 +501,28 @@ div.login-paper {
color: gray;
font-style: italic;
}
td.xxsmall {
max-width: 50px;
text-overflow: ellipsis;
overflow: hidden;
}
td.xsmall {
max-width: 100px;
text-overflow: ellipsis;
overflow: hidden;
}
td.small {
max-width: 200px;
text-overflow: ellipsis;
overflow: hidden;
}
td.medium {
max-width: 300px;
text-overflow: ellipsis;
overflow: hidden;
}
td.large {
max-width: 400px;
text-overflow: ellipsis;
overflow: hidden;
}
57 changes: 57 additions & 0 deletions src/components/common/ConfigSelect.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import { Tooltip, Chip, MenuItem, Menu } from '@material-ui/core'
import SettingsIcon from '@material-ui/icons/SettingsOverscan';
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
import { map } from 'lodash';

const ConfigSelect = ({configs, selected, onChange, color}) => {
const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState(null);

const toggleOpen = event => {
const newOpen = !open

setOpen(newOpen)
setAnchorEl(newOpen ? event.currentTarget : null)
}

const _onChange = (event, config) => {
event.persist();

onChange(config)
toggleOpen(event)
}
return (
<span>
<Tooltip title='Change View Layout'>
<Chip
variant="default"
color='secondary'
icon={<SettingsIcon style={{width: '18px', marginLeft: '8px'}} />}
deleteIcon={<ArrowDropDownIcon style={{width: '18px'}} />}
label={`Layout : ${selected.name}`}
onClick={toggleOpen}
onDelete={toggleOpen}
style={{backgroundColor: color, borderColor: color}}
/>
</Tooltip>
<Menu
id="results-size-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={toggleOpen}
>
{
map(configs, config => (
<MenuItem key={config.name} onClick={event => _onChange(event, config)}>
{config.name}
</MenuItem>
))
}
</Menu>
</span>
)
}

export default ConfigSelect;
12 changes: 6 additions & 6 deletions src/components/common/ResourceLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const ResourceLabel = props => {
{
(props.owner && props.parent) ?
<React.Fragment>
<span>{props.owner}</span>
<span className='ellipsis-text-3'>{props.owner}</span>
<span>{SEPARATOR}</span>
<span>{props.parent}</span>
<span className='ellipsis-text-3'>{props.parent}</span>
</React.Fragment> :
(
props.parentURL &&
<span>{props.parentURL}</span>
<span className='ellipsis-text-3'>{props.parentURL}</span>
)
}
<span>{SEPARATOR}</span>
<span className='resource-name ellipsis-text' style={{maxWidth: '100%'}}>{props.id || props.name}</span>
<span className='resource-name ellipsis-text-3' style={{maxWidth: '100%'}}>{props.id || props.name}</span>
</span>
<span className='resource-label resource-id ellipsis-text' style={{maxWidth: '100%'}}>
<span>{props.name || 'None'}</span>
<span className='resource-label resource-id' style={{maxWidth: '100%'}}>
<span className='ellipsis-text'>{props.name || 'None'}</span>
</span>
</div>
)
Expand Down
84 changes: 66 additions & 18 deletions src/components/orgs/OrgHome.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import React from 'react';
import alertifyjs from 'alertifyjs';
import { CircularProgress } from '@material-ui/core';
import { reject, get, isEmpty, values } from 'lodash';
import { reject, get, isEmpty, values, find, findIndex, isEqual } from 'lodash';
import APIService from '../../services/APIService';
import { isCurrentUserMemberOf, isAdminUser } from '../../common/utils';
import Pins from '../common/Pins';
import OrgHomeHeader from './OrgHomeHeader';
import OrgHomeTabs from './OrgHomeTabs';
const DEFAULT_CONFIG = {
name: 'OCL Default',
page_size: 25,
layout: 'table',
config: {
tabs: [
{type: "sources", label: "Sources", page_size: 25, "default": true},
{type: "collections", label: "Collections", page_size: 25},
{type: "users", label: "Members", page_size: 25},
]
}
}

class OrgHome extends React.Component {
constructor(props) {
Expand All @@ -15,7 +27,10 @@ class OrgHome extends React.Component {
isLoading: true,
org: {},
pins: [],
tab: this.getDefaultTabIndex()
tab: null,
selectedConfig: null,
customConfigs: [],
isCustomConfigSelected: false,
}
}

Expand All @@ -34,6 +49,15 @@ class OrgHome extends React.Component {
return 0;
}

getDefaultTabIndexFromConfig() {
const index = findIndex(this.state.selectedConfig.config.tabs, {"default": true});
return index > -1 ? index : 0;
}

setTab() {
this.setState({tab: this.getDefaultTabIndexFromConfig()});
}

getOrgId() {
return get(this.props, 'match.params.org')
}
Expand Down Expand Up @@ -62,7 +86,7 @@ class OrgHome extends React.Component {
if(prevProps.location.pathname !== this.props.location.pathname) {
this.refreshDataByURL()
this.getPins()
this.onTabChange(null, this.getDefaultTabIndex())
//this.onTabChange(null, this.getDefaultTabIndex())
}
}

Expand All @@ -78,11 +102,29 @@ class OrgHome extends React.Component {
this.setState(
{isLoading: true},
() => service
.get()
.then(response => this.setState({isLoading: false, org: response.data})))
.get(null, null, {includeClientConfigs: true})
.then(response => {
const org = response.data;
const customConfigs = get(response.data, 'client_configs', [])
const defaultCustomConfig = find(customConfigs, {is_default: true});
this.setState({
isLoading: false,
org: org,
selectedConfig: defaultCustomConfig || DEFAULT_CONFIG,
customConfigs: customConfigs,
isCustomConfigSelected: Boolean(defaultCustomConfig),
}, this.setTab)
}))
}
}

onConfigChange = config => {
this.setState({
selectedConfig: config,
isCustomConfigSelected: !isEqual(config, DEFAULT_CONFIG)
})
}

onTabChange = (event, value) => {
this.setState({tab: value})
}
Expand Down Expand Up @@ -131,7 +173,7 @@ class OrgHome extends React.Component {
}

render() {
const { org, isLoading, tab, pins } = this.state;
const { org, isLoading, tab, pins, selectedConfig, customConfigs } = this.state;
const url = this.getURLFromPath()
const isCurrentUserMemberOfOrg = isCurrentUserMemberOf(this.getOrgId()) || isAdminUser();
const showAboutTab = this.shouldShowAboutTab()
Expand All @@ -148,18 +190,24 @@ class OrgHome extends React.Component {
canDelete={isCurrentUserMemberOfOrg}
onOrderUpdate={this.updatePinOrder}
/>
<OrgHomeTabs
tab={tab}
onTabChange={this.onTabChange}
org={org}
location={this.props.location}
url={url}
pins={pins}
onPinCreate={this.createPin}
onPinDelete={this.deletePin}
showPin={isCurrentUserMemberOfOrg}
aboutTab={showAboutTab}
/>
{
tab !== null &&
<OrgHomeTabs
tab={tab}
onTabChange={this.onTabChange}
org={org}
location={this.props.location}
url={url}
pins={pins}
onPinCreate={this.createPin}
onPinDelete={this.deletePin}
showPin={isCurrentUserMemberOfOrg}
aboutTab={showAboutTab}
customConfigs={[...customConfigs, DEFAULT_CONFIG]}
onConfigChange={this.onConfigChange}
selectedConfig={selectedConfig}
/>
}
</div>
}
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/components/orgs/OrgHomeChildrenList.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { merge } from 'lodash';
import Search from '../search/Search';

class OrgHomeChildrenList extends React.Component {
Expand All @@ -10,13 +11,13 @@ class OrgHomeChildrenList extends React.Component {
}

render() {
const { org, resource } = this.props;
const { org, resource, fixedFilters } = this.props;
return (
<Search
{...this.props}
nested
baseURL={this.getURL()}
fixedFilters={{isTable: true, limit: 25}}
fixedFilters={merge({isTable: true, limit: 25}, (fixedFilters || {}))}
searchInputPlaceholder={`Search ${org.id} ${resource}...`}
/>
)
Expand Down
Loading

0 comments on commit b6e6211

Please sign in to comment.