Skip to content

Commit

Permalink
Cleaning stale elements when the reportHash changes (streamlit#617)
Browse files Browse the repository at this point in the history
* Cleaning stale elements when the reportHash changes

* Cleaning

* Fixing Metrics

* Removing reportName and some cleaning
  • Loading branch information
arraydude authored Nov 7, 2019
1 parent ae4ac67 commit 5f3f902
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface State {
connectionState: ConnectionState
elements: Elements
reportId: string
reportName: string | null
reportHash: string | null
reportRunState: ReportRunState
showLoginBox: boolean
userSettings: UserSettings
Expand Down Expand Up @@ -113,7 +113,7 @@ class App extends PureComponent<Props, State> {
sidebar: fromJS([]),
},
reportId: "<null>",
reportName: null,
reportHash: null,
reportRunState: ReportRunState.NOT_RUNNING,
showLoginBox: false,
userSettings: {
Expand Down Expand Up @@ -382,10 +382,14 @@ class App extends PureComponent<Props, State> {
* @param newReportProto a NewReport protobuf
*/
handleNewReport(newReportProto: NewReport): void {
const name = newReportProto.name
const scriptPath = newReportProto.scriptPath
const { reportHash } = this.state
const { name: reportName, scriptPath } = newReportProto

document.title = `${name} · Streamlit`
const newReportHash = hashString(
SessionInfo.current.installationId + scriptPath
)

document.title = `${reportName} · Streamlit`

MetricsManager.current.clearDeltaCounter()

Expand All @@ -394,13 +398,16 @@ class App extends PureComponent<Props, State> {
// how many projects are being created with Streamlit while still keeping
// possibly-sensitive info like the scriptPath outside of our metrics
// services.
reportHash: hashString(SessionInfo.current.installationId + scriptPath),
reportHash: newReportHash,
})

this.setState({
reportId: newReportProto.id,
reportName: name,
})
if (reportHash === newReportHash) {
this.setState({
reportId: newReportProto.id,
})
} else {
this.clearAppState(newReportHash, newReportProto.id)
}
}

/**
Expand Down Expand Up @@ -465,6 +472,26 @@ class App extends PureComponent<Props, State> {
.filter((element: any) => element !== null)
}

/*
* Clear all elements from the state.
*/
clearAppState(reportHash: string, reportId: string): void {
this.setState(
{
reportHash,
reportId,
elements: {
main: fromJS([]),
sidebar: fromJS([]),
},
},
() => {
this.elementListBuffer = this.state.elements
this.widgetMgr.clean(fromJS([]))
}
)
}

/**
* Opens a dialog with the specified state.
*/
Expand Down

0 comments on commit 5f3f902

Please sign in to comment.