-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* recreate udtab component & fixes #1169 * Merge Co-authored-by: Adam Driscoll <[email protected]>
- Loading branch information
1 parent
50d6aa8
commit 95a88de
Showing
15 changed files
with
8,265 additions
and
6,291 deletions.
There are no files selected for viewing
4,850 changes: 2,171 additions & 2,679 deletions
4,850
src/UniversalDashboard.MaterialUI/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useEffect, useState, useRef } from 'react'; | ||
import Tab from 'react-materialize/lib/Tab' | ||
|
||
const SET_STATE = "setState"; | ||
const REQUEST_STATE = "requestState"; | ||
const REMOVE_ELEMENT = "removeElement"; | ||
const ADD_ELEMENT = "addElement"; | ||
const CLEAR_ELEMENT = "clearElement"; | ||
const SYNC_ELEMENT = "syncElement"; | ||
|
||
const UDTab = props => { | ||
const [tabContent, setTabContent] = useState(props.content) | ||
const tabRef = useRef() | ||
useEffect(() => { | ||
console.log('udtab', props) | ||
const pubSubToken = UniversalDashboard.subscribe(props.id, events); | ||
return () => UniversalDashboard.unsubscribe(pubSubToken); | ||
}, [props.id]); | ||
|
||
const events = (msg, event) => { | ||
switch (event.type) { | ||
case SYNC_ELEMENT: | ||
UniversalDashboard.get( | ||
`/api/internal/component/element/${props.id}`, | ||
data => | ||
setTabContent(data) | ||
); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
const reload = () => { | ||
UniversalDashboard.get( | ||
`/api/internal/component/element/${props.id}`, | ||
data => | ||
setTabContent(data) | ||
) | ||
} | ||
return <Tab | ||
options={{ | ||
duration: 300, | ||
onShow: props.isEndpoint ? reload : null, | ||
responsiveThreshold: Infinity, | ||
swipeable: false | ||
}} | ||
title={`${props.title}`}> | ||
{UniversalDashboard.renderComponent(tabContent)} | ||
</Tab> | ||
} | ||
|
||
export default UDTab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,43 @@ | ||
import React, { Fragment } from 'react'; | ||
import M from 'materialize-css'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { TabBar, Tab } from '@rmwc/tabs' | ||
|
||
export default class TabContainer extends React.Component { | ||
|
||
componentDidMount() { | ||
M.Tabs.init(this.element); | ||
var instance = M.Tabs.getInstance(this.element); | ||
instance.updateTabIndicator(); | ||
} | ||
|
||
renderTabHeaders() { | ||
|
||
var tabIndex = 0; | ||
|
||
return this.props.tabs.map(x => { | ||
tabIndex++; | ||
return ( | ||
<li class="tab"><a href={`#${this.props.id}${tabIndex}`}>{x.text}</a></li> | ||
) | ||
}); | ||
} | ||
const TabPanel = ({ content, ...props }) => { | ||
console.log('TabPanel Props: ', props) | ||
console.log('TabPanel Content: ', content) | ||
return <div>{UniversalDashboard.renderComponent(content)}</div> | ||
} | ||
|
||
renderTabContent() { | ||
var tabIndex = 0; | ||
const TabContainer = props => { | ||
const { tabs } = props | ||
const [activeTabIndex, setActiveTabIndex] = useState(0) | ||
const [activeTabPanel, setActiveTabPanel] = useState(tabs[0]) | ||
|
||
return this.props.tabs.map(x => { | ||
tabIndex++; | ||
return ( | ||
<div id={`${this.props.id}${tabIndex}`} className="col s12"> | ||
{UniversalDashboard.renderComponent(x.content)} | ||
</div> | ||
) | ||
}); | ||
const refreshTabPanel = (id, tab) => { | ||
UniversalDashboard.get(`/api/internal/component/element/${id}`, data => { | ||
setActiveTabPanel({ ...tab, content: data }) | ||
}) | ||
} | ||
|
||
render() { | ||
var headers = this.renderTabHeaders(); | ||
var content = this.renderTabContent(); | ||
|
||
return ( | ||
<Fragment> | ||
<div> | ||
<ul className="tabs" ref={x => this.element = x}> | ||
{headers} | ||
</ul> | ||
</div> | ||
{content} | ||
</Fragment> | ||
|
||
) | ||
} | ||
return ( | ||
<div> | ||
<TabBar | ||
activeTabIndex={activeTabIndex} | ||
onActivate={evt => setActiveTabIndex(evt.detail.index)} | ||
> | ||
{ | ||
tabs.map(tab => <Tab | ||
id={tab.id} | ||
label={tab.label} | ||
stacked={tab.icon && tab.stacked || undefined} | ||
onInteraction={evt => tab.refreshWhenActive && tab.isEndpoint ? refreshTabPanel(evt.detail.tabId, tab) : setActiveTabPanel(tab)} | ||
icon={tab.icon && UniversalDashboard.renderComponent(tab.icon)} /> | ||
) | ||
} | ||
</TabBar> | ||
<TabPanel {...activeTabPanel} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default TabContainer | ||
|
Oops, something went wrong.
95a88de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Ironman Software Forums. There might be relevant details there:
https://forums.universaldashboard.io/t/bug-in-default-theme-for-release-nightly-build-20200106-4/1938/4