diff --git a/src/Components/Hooks/useDashboardEvent.jsx b/src/Components/Hooks/useDashboardEvent.jsx index e8c6032..d78c160 100644 --- a/src/Components/Hooks/useDashboardEvent.jsx +++ b/src/Components/Hooks/useDashboardEvent.jsx @@ -20,68 +20,70 @@ export default function useDashboardEvent(elementId, initialState) { // console.log("ud event hook: ", state); const pubSubToken = UniversalDashboard.subscribe(elementId, events); return () => UniversalDashboard.unsubscribe(pubSubToken); - }, [elementId, initialState]); + }); - const events = useCallback( - (msg, event) => { - switch (event.type) { - // Set-UDElement - case SET_STATE: - setState(state => { - return { - attributes: { ...state.attributes, ...event.state.attributes }, - content: event.state.content ? (Array.isArray(event.state.content) ? event.state.content : Array.from(event.state.content)) : [] - } - }); - break; - // Get-UDElement - case REQUEST_STATE: - UniversalDashboard.post( - `/api/internal/component/element/sessionState/${event.requestId}`, - { ...state } - ); - break; - // Add-UDElement - case ADD_ELEMENT: - setState(state => { - return { - ...state, - content: state.content.concat(event.elements) - }; - }); - break; - // Remove-UDElement - case REMOVE_ELEMENT: - setState(state => { - let newStateContent = state.content; - newStateContent.splice(-1, 1); - return { - ...state, - content: [...newStateContent] - }; - }); + const events = (msg, event) => { + switch (event.type) { + // Set-UDElement + case SET_STATE: + setState(state => { + return { + attributes: { ...state.attributes, ...event.state.attributes }, + content: event.state.content + ? Array.isArray(event.state.content) + ? event.state.content + : Array.from(event.state.content) + : state.content + }; + }); + break; + // Get-UDElement + case REQUEST_STATE: + console.log("REQUEST_STATE: ", state); + UniversalDashboard.post( + `/api/internal/component/element/sessionState/${event.requestId}`, + { ...state } + ); + break; + // Add-UDElement + case ADD_ELEMENT: + setState(state => { + return { + ...state, + content: state.content.concat(event.elements) + }; + }); + break; + // Remove-UDElement + case REMOVE_ELEMENT: + setState(state => { + let newStateContent = state.content; + newStateContent.splice(-1, 1); + return { + ...state, + content: [...newStateContent] + }; + }); - break; - // Clear-UDElement - case CLEAR_ELEMENT: - setState(state => { - return { - ...state, - content: [] - }; - }); - break; - // Sync-UDElement - case SYNC_ELEMENT: - reload(); - break; - // Just break - default: - break; - } - }, - [event] - ); + break; + // Clear-UDElement + case CLEAR_ELEMENT: + setState(state => { + return { + ...state, + content: [] + }; + }); + break; + // Sync-UDElement + case SYNC_ELEMENT: + reload(); + break; + // Just break + default: + break; + } + }; const reload = useCallback(() => { UniversalDashboard.get( diff --git a/src/Components/badge/badge.jsx b/src/Components/badge/badge.jsx index d67f019..ad87408 100644 --- a/src/Components/badge/badge.jsx +++ b/src/Components/badge/badge.jsx @@ -1,5 +1,5 @@ -import React from "react"; -import ReactInterval from "react-interval"; +import React, { Fragment } from "react"; +// import ReactInterval from "react-interval"; import { Badge } from "antd"; import useDashboardEvent from "../Hooks/useDashboardEvent.jsx"; @@ -9,11 +9,15 @@ const AntdBadge = props => { const { content, attributes } = state; const countProps = { - count: attributes.count, + count: ( + attributes.count && attributes.count.type + ? {UniversalDashboard.renderComponent(attributes.count)} + : attributes.count + ), showZero: attributes.showZero, overflowCount: attributes.overflowCount, style: attributes.style - } + }; const dotProps = { color: attributes.color, @@ -26,7 +30,12 @@ const AntdBadge = props => { return ( + children={ + content && content.type + ? UniversalDashboard.renderComponent(content) + : content + } + /> ); }; diff --git a/src/Components/card/card.jsx b/src/Components/card/card.jsx index 19ffbad..d47e0fe 100644 --- a/src/Components/card/card.jsx +++ b/src/Components/card/card.jsx @@ -57,7 +57,15 @@ const renderCardContent = props => { switch (parameterSet) { case "Default": - cardContent = UniversalDashboard.renderComponent(props.content); + cardContent = Array.isArray(props.content) + ? props.content.map(item => + item.type + ? UniversalDashboard.renderComponent(item) + : item + ) + : props.content.type + ? UniversalDashboard.renderComponent(props.content) + : props.content; break; case "Meta": cardContent = ( diff --git a/src/Components/switch/switch.jsx b/src/Components/switch/switch.jsx index e144da8..4b6c381 100644 --- a/src/Components/switch/switch.jsx +++ b/src/Components/switch/switch.jsx @@ -5,11 +5,10 @@ import useDashboardEvent from "../Hooks/useDashboardEvent"; const AntdSwitch = props => { const [state, reload] = useDashboardEvent(props.id, props); const { content, attributes } = state; - const [checked, setChecked] = useState(attributes.checked) - + const [checked, setChecked] = useState(attributes.checked); const onChange = event => { - setChecked(!checked) + setChecked(event) UniversalDashboard.publish("element-event", { type: "clientEvent", eventId: attributes.id + "onChange", @@ -19,9 +18,13 @@ const AntdSwitch = props => { }; const customIcons = { - checkedChildren: UniversalDashboard.renderComponent(attributes.checkedChildren), - unCheckedChildren: UniversalDashboard.renderComponent(attributes.unCheckedChildren) - } + checkedChildren: UniversalDashboard.renderComponent( + attributes.checkedChildren + ), + unCheckedChildren: UniversalDashboard.renderComponent( + attributes.unCheckedChildren + ) + }; return ( { sourceMap: true, mangle: true, compress: { - drop_console:false + drop_console: false } } }) @@ -55,6 +55,10 @@ module.exports = env => { { loader: "less-loader", options: { + modifyVars: { + "primary-color": "#e91e63", + "link-color": "#607d8b", + }, javascriptEnabled: true } }