Skip to content

Commit

Permalink
Fixes issue with dynamic pages
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Nov 9, 2018
1 parent 2622cce commit 3e67713
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/UniversalDashboard.UITest/Integration/Page.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,16 @@ Describe "New-UDPage" {
$Page3 = New-UDPage -Name "Test" -Content {
New-UDCard -Text "TestPage" -Id "Test-Page"
}

$Page4 = New-UDPage -Url "/level/:test" -Endpoint {
New-UDCard -Text "Level 1" -Id "Level1"
}

$Page5 = New-UDPage -Url "/level/level2/:test" -Endpoint {
New-UDCard -Text "Level 2" -Id "Level2"
}

$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2, $Page3)
$dashboard = New-UDDashboard -Title "Test" -Pages @($Page1, $Page2, $Page3, $Page5, $Page4)
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Expand Down Expand Up @@ -119,6 +127,18 @@ Describe "New-UDPage" {
(Find-SeElement -Id 'home-page' -Driver $Driver).text | Should not be $TestPageText
}

it "should have level 1 but not level 2" {
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/level/1"
Find-SeElement -Id 'Level1' -Driver $Driver | Should not be $null
Find-SeElement -Id 'Level2' -Driver $Driver | Should be $null
}

it "should have level 2 but not level 1" {
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort/level/level2/1"
Find-SeElement -Id 'Level1' -Driver $Driver | Should be $null
Find-SeElement -Id 'Level2' -Driver $Driver | Should not be $null
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
}
Expand Down
15 changes: 9 additions & 6 deletions src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React,{Suspense} from 'react';

import {
Route,
Redirect
Redirect,
Switch
} from 'react-router-dom'
import {getApiPath} from 'config';
import UdPage from './ud-page.jsx';
Expand Down Expand Up @@ -289,15 +290,15 @@ export default class UdDashboard extends React.Component {
if (x.url === null) return null;

return <Route path={x.url} render={props => (
<UdPage id={x.id} dynamic={true} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval}/>
<UdPage id={x.id} dynamic={true} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval} key={props.location.key}/>
)} />
})

var staticPages = this.state.dashboard.pages.map(function(x) {
if (x.url !== null) return null;

return <Route path={'/' + x.name.replace(/ /g, "-")} render={props => (
<UdPage dynamic={false} {...x} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval}/>
<UdPage dynamic={false} {...x} {...props} autoRefresh={x.autoRefresh} refreshInterval={x.refreshInterval} key={props.location.key}/>
)} />
})

Expand All @@ -314,9 +315,11 @@ export default class UdDashboard extends React.Component {
authenticated={this.state.authenticated}
/>,
<main style={{background: this.state.dashboard.backgroundColor, color: this.state.dashboard.fontColor}}>
{staticPages}
{dynamicPages}
<Route exact path="/" render={this.redirectToHomePage.bind(this)}/>
<Switch>
{staticPages}
{dynamicPages}
<Route exact path="/" render={this.redirectToHomePage.bind(this)} />
</Switch>
</main>,
<Suspense fallback={<div></div>}>
<UdModalComponent />
Expand Down

0 comments on commit 3e67713

Please sign in to comment.