|
@@ -1,10 +1,11 @@
|
|
|
-import {InjectedRouter} from 'react-router';
|
|
|
+import {browserHistory, InjectedRouter} from 'react-router';
|
|
|
import {Location} from 'history';
|
|
|
|
|
|
import {Client} from 'sentry/api';
|
|
|
import AsyncComponent from 'sentry/components/asyncComponent';
|
|
|
import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
|
|
|
import {Organization, PageFilters, SavedQuery} from 'sentry/types';
|
|
|
+import EventView from 'sentry/utils/discover/eventView';
|
|
|
import withApi from 'sentry/utils/withApi';
|
|
|
import withOrganization from 'sentry/utils/withOrganization';
|
|
|
import withPageFilters from 'sentry/utils/withPageFilters';
|
|
@@ -19,20 +20,36 @@ type Props = {
|
|
|
router: InjectedRouter;
|
|
|
selection: PageFilters;
|
|
|
setSavedQuery: (savedQuery: SavedQuery) => void;
|
|
|
- homepageQuery?: SavedQuery;
|
|
|
- savedQuery?: SavedQuery;
|
|
|
};
|
|
|
|
|
|
type HomepageQueryState = AsyncComponent['state'] & {
|
|
|
- key: number;
|
|
|
savedQuery?: SavedQuery | null;
|
|
|
};
|
|
|
|
|
|
class HomepageQueryAPI extends AsyncComponent<Props, HomepageQueryState> {
|
|
|
shouldReload = true;
|
|
|
|
|
|
+ componentDidUpdate(prevProps, prevState) {
|
|
|
+ const hasFetchedSavedQuery = !prevState.savedQuery && this.state.savedQuery;
|
|
|
+ const hasInitiallyLoaded = prevState.loading && !this.state.loading;
|
|
|
+ const sidebarClicked = this.state.savedQuery && this.props.location.search === '';
|
|
|
+ const hasValidEventViewInURL = EventView.fromLocation(this.props.location).isValid();
|
|
|
+
|
|
|
+ if (
|
|
|
+ this.state.savedQuery &&
|
|
|
+ ((hasInitiallyLoaded && hasFetchedSavedQuery && !hasValidEventViewInURL) ||
|
|
|
+ sidebarClicked)
|
|
|
+ ) {
|
|
|
+ const eventView = EventView.fromSavedQuery(this.state.savedQuery);
|
|
|
+ browserHistory.replace(
|
|
|
+ eventView.getResultsViewUrlTarget(this.props.organization.slug, true)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ super.componentDidUpdate(prevProps, prevState);
|
|
|
+ }
|
|
|
+
|
|
|
getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
|
|
|
- const {organization, location} = this.props;
|
|
|
+ const {organization} = this.props;
|
|
|
|
|
|
const endpoints: ReturnType<AsyncComponent['getEndpoints']> = [];
|
|
|
if (
|
|
@@ -44,12 +61,6 @@ class HomepageQueryAPI extends AsyncComponent<Props, HomepageQueryState> {
|
|
|
`/organizations/${organization.slug}/discover/homepage/`,
|
|
|
]);
|
|
|
}
|
|
|
- // HACK: We're using state here to manage a component key so we can force remounting the entire discover result
|
|
|
- // This is because we need <Results> to rerun its constructor with the new homepage query to get it to display properly
|
|
|
- // We're checking to see that location.search is empty because that is the only time we should be fetching the homepage query
|
|
|
- if (location.search === '' && this.state) {
|
|
|
- this.setState({key: Date.now()});
|
|
|
- }
|
|
|
return endpoints;
|
|
|
}
|
|
|
|
|
@@ -73,7 +84,6 @@ class HomepageQueryAPI extends AsyncComponent<Props, HomepageQueryState> {
|
|
|
loading={loading}
|
|
|
setSavedQuery={this.setSavedQuery}
|
|
|
isHomepage
|
|
|
- key={`results-${this.state.key}`}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
@@ -82,9 +92,8 @@ class HomepageQueryAPI extends AsyncComponent<Props, HomepageQueryState> {
|
|
|
function HomepageContainer(props: Props) {
|
|
|
return (
|
|
|
<PageFiltersContainer
|
|
|
- skipLoadLastUsed={
|
|
|
- props.organization.features.includes('global-views') && !!props.savedQuery
|
|
|
- }
|
|
|
+ skipLoadLastUsed={props.organization.features.includes('global-views')}
|
|
|
+ skipInitializeUrlParams
|
|
|
>
|
|
|
<HomepageQueryAPI {...props} />
|
|
|
</PageFiltersContainer>
|