This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate router and <app-view> to React (getredash#4525)
* Migrate router and <app-view> to React: skeleton * Update layout on route change * Start moving page routes from angular to react * Move page routes to react except of public dashboard and visualization embed) * Move public dashboard and visualization embed routes to React * Replace $route/$routeParams usages * Some cleanup * Replace AngularJS $location service with implementation based on history library * Minor fix to how ApplicationView handles route change * Explicitly use global layout for each page instead of handling related stuff in ApplicationArea component * Error handling * Remove AngularJS and related dependencies * Move Parameter factory method to a separate file * Fix CSS (replace custom components with classes) * Fix: keep other url parts when updating location partially; refine code * Fix tests * Make router work in multi-org mode (respect <base> tag) * Optimzation: don't resolve route if path didn't change * Fix search input in header; error handling improvement (handle more errors in pages; global error handler for unhandled errors; dialog dismiss 'unhandled rejection' errors) * Fix page keys; fix navigateTo calls (third parameter not available) * Use relative links * Router: ignore location REPLACE events, resolve only on PUSH/POP * Fix tests * Remove unused jQuery reference * Show error from backend when creating Destination * Remove route.resolve where not necessary (used constant values) * New Query page: keep state on saving, reload when creating another new query * Use currentRoute.key instead of hard-coded keys for page components * Tidy up Router * Tidy up location service * Fix tests * Don't add parameters changes to browser's history * Fix test (improved fix) Co-authored-by: Gabriel Dutra <nesk.frz@gmail.com>
- Loading branch information
1 parent
a891160
commit a682265
Showing
114 changed files
with
2,240 additions
and
1,978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
client/app/components/ApplicationArea/AuthenticatedPageWrapper.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import ErrorBoundary from "@/components/ErrorBoundary"; | ||
import { Auth } from "@/services/auth"; | ||
import organizationStatus from "@/services/organizationStatus"; | ||
import ApplicationHeader from "./ApplicationHeader"; | ||
import ErrorMessage from "./ErrorMessage"; | ||
|
||
export default function AuthenticatedPageWrapper({ bodyClass, children }) { | ||
const [isAuthenticated, setIsAuthenticated] = useState(!!Auth.isAuthenticated()); | ||
|
||
useEffect(() => { | ||
let isCancelled = false; | ||
Promise.all([Auth.requireSession(), organizationStatus.refresh()]) | ||
.then(() => { | ||
if (!isCancelled) { | ||
setIsAuthenticated(!!Auth.isAuthenticated()); | ||
} | ||
}) | ||
.catch(() => { | ||
if (!isCancelled) { | ||
setIsAuthenticated(false); | ||
} | ||
}); | ||
return () => { | ||
isCancelled = true; | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (bodyClass) { | ||
document.body.classList.toggle(bodyClass, true); | ||
return () => { | ||
document.body.classList.toggle(bodyClass, false); | ||
}; | ||
} | ||
}, [bodyClass]); | ||
|
||
if (!isAuthenticated) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<ApplicationHeader /> | ||
<ErrorBoundary renderError={error => <ErrorMessage error={error} showOriginalMessage={false} />}> | ||
{children} | ||
</ErrorBoundary> | ||
</> | ||
); | ||
} | ||
|
||
AuthenticatedPageWrapper.propTypes = { | ||
bodyClass: PropTypes.string, | ||
children: PropTypes.node, | ||
}; | ||
|
||
AuthenticatedPageWrapper.defaultProps = { | ||
bodyClass: null, | ||
children: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
export default function ErrorMessage({ error, showOriginalMessage }) { | ||
if (!error) { | ||
return null; | ||
} | ||
|
||
console.error(error); | ||
|
||
const message = showOriginalMessage | ||
? error.message | ||
: "It seems like we encountered an error. Try refreshing this page or contact your administrator."; | ||
|
||
return ( | ||
<div className="fixed-container" data-test="ErrorMessage"> | ||
<div className="container"> | ||
<div className="col-md-8 col-md-push-2"> | ||
<div className="error-state bg-white tiled"> | ||
<div className="error-state__icon"> | ||
<i className="zmdi zmdi-alert-circle-o" /> | ||
</div> | ||
<div className="error-state__details"> | ||
<h4>{message}</h4> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
ErrorMessage.propTypes = { | ||
error: PropTypes.object.isRequired, | ||
showOriginalMessage: PropTypes.bool, | ||
}; | ||
|
||
ErrorMessage.defaultProps = { | ||
showOriginalMessage: true, | ||
}; |
Oops, something went wrong.