Skip to content

Commit

Permalink
Remove grid layout handlers. (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Mar 29, 2019
1 parent 004d882 commit 75ed25f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 48 deletions.
12 changes: 1 addition & 11 deletions src/UniversalDashboard/Controls/src/grid-layout.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ function New-UDGridLayout {
[Parameter()]
[switch]$Resizable,
[Parameter()]
[switch]$Persist,
[Parameter()]
[object]$OnLayoutChanged
[switch]$Persist
)

End {
Expand All @@ -57,13 +55,6 @@ function New-UDGridLayout {
xxs = $ExtraExtraSmallColumns
}

if ($null -ne $OnLayoutChanged -and $OnLayoutChanged -is ([ScriptBlock])) {
$OnLayoutChanged = New-UDEndpoint -Endpoint $OnLayoutChanged
}
elseif ($null -ne $OnLayoutChanged -and $OnLayoutChanged -isnot ([UniversalDashboard.Models.Endpoint])) {
throw "OnLayoutChanged must be a ScriptBlock of UDEndpoint"
}

@{
type = "grid-layout"
id = $Id
Expand All @@ -77,7 +68,6 @@ function New-UDGridLayout {
isDraggable = $Draggable.IsPresent
isResizable = $Resizable.IsPresent
persist = $Persist.IsPresent
endpoint = $OnLayoutChanged.Name
}
}
}
38 changes: 1 addition & 37 deletions src/client/src/app/ud-grid-layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,7 @@ export default class UDGridLayout extends React.Component {
UniversalDashboard.subscribe(this.props.id, this.onIncomingEvent.bind(this));
}

onIncomingEvent(eventName, event) {
if (event.type === "addElement") {
var layouts = this.state.layouts;

event.elements.forEach(x => {
layouts.push({
i: `grid-element-${x.id}`
})
})

this.setState({
layouts,
content: this.state.content.concat(event.elements)
})
}

if (event.type == "removeElement") {
this.setState({
layouts: this.state.filter(x => x.i !== event.id),
content: this.state.content.filter(x => x.id !== event.id)
})
}
}

onLayoutChange(layout, layouts) {

if (this.props.endpoint) {
UniversalDashboard.publish('element-event', {
type: "clientEvent",
eventId: this.props.endpoint,
eventName: 'onLayoutChanged',
eventData: JSON.stringify(layouts)
});
}

if (this.props.persist) {
saveToLS("layouts", layouts);
this.setState({ layouts });
Expand All @@ -86,9 +52,7 @@ export default class UDGridLayout extends React.Component {
);

return (
<ResponsiveReactGridLayout className={this.props.className} layouts={this.state.layouts} cols={this.props.cols} rowHeight={this.props.rowHeight} onLayoutChange={(layout, layouts) =>
this.onLayoutChange(layout, layouts)
}>
<ResponsiveReactGridLayout className={this.props.className} layouts={this.state.layouts} cols={this.props.cols} rowHeight={this.props.rowHeight} >
{elements}
</ResponsiveReactGridLayout>
)
Expand Down

0 comments on commit 75ed25f

Please sign in to comment.