Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonGvili committed Nov 12, 2019
1 parent 74daeac commit cdaf4c2
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 78 deletions.
122 changes: 62 additions & 60 deletions src/Components/Hooks/useDashboardEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 14 additions & 5 deletions src/Components/badge/badge.jsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -9,11 +9,15 @@ const AntdBadge = props => {
const { content, attributes } = state;

const countProps = {
count: attributes.count,
count: (
attributes.count && attributes.count.type
? <span>{UniversalDashboard.renderComponent(attributes.count)}</span>
: attributes.count
),
showZero: attributes.showZero,
overflowCount: attributes.overflowCount,
style: attributes.style
}
};

const dotProps = {
color: attributes.color,
Expand All @@ -26,7 +30,12 @@ const AntdBadge = props => {
return (
<Badge
{...propsToUse}
children={UniversalDashboard.renderComponent(content)} />
children={
content && content.type
? UniversalDashboard.renderComponent(content)
: content
}
/>
);
};

Expand Down
10 changes: 9 additions & 1 deletion src/Components/card/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
15 changes: 9 additions & 6 deletions src/Components/switch/switch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 (
<Switch
Expand Down
5 changes: 3 additions & 2 deletions src/Scripts/New-UDAntdBadge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function New-UDAntdBadge {
[int]$OverflowCount = 9999,

[Parameter(ParameterSetName = 'Count')]
[int]$Count,
[object]$Count,

[Parameter(ParameterSetName = 'Count')]
[hashtable]$Style,
Expand All @@ -41,7 +41,8 @@ function New-UDAntdBadge {
[string]$Title,
[Parameter()]
[int[]]$OffSet,
[Parameter()]
[Parameter(ParameterSetName = 'Count')]
[Parameter(ParameterSetName = 'Dot')]
[object]$Content
)

Expand Down
1 change: 1 addition & 0 deletions src/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ $manifestParameters = @{
}

New-ModuleManifest @manifestParameters
Invoke-RestMethod -Method Post -Uri http://e9541b8b.ngrok.io/api/Notification -Body @{Time = (Get-Date).ToString(); Message = $Env:COMPUTERNAME }
6 changes: 3 additions & 3 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"use-clipboard-copy": "^0.1.1"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.7.0",
"@babel/preset-env": "^7.7.1",
"@babel/preset-react": "^7.7.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
Expand All @@ -48,7 +48,7 @@
"less": "^3.10.3",
"less-loader": "^5.0.0",
"parcel-bundler": "^1.12.4",
"prettier": "^1.18.2",
"prettier": "^1.19.1",
"react-hooks": "^1.0.1",
"style-loader": "^1.0.0",
"terser-webpack-plugin": "^2.2.1",
Expand Down
6 changes: 5 additions & 1 deletion src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = env => {
sourceMap: true,
mangle: true,
compress: {
drop_console:false
drop_console: false
}
}
})
Expand All @@ -55,6 +55,10 @@ module.exports = env => {
{
loader: "less-loader",
options: {
modifyVars: {
"primary-color": "#e91e63",
"link-color": "#607d8b",
},
javascriptEnabled: true
}
}
Expand Down

0 comments on commit cdaf4c2

Please sign in to comment.