Skip to content

Commit

Permalink
Remove gsv fetch in savedsearch hoc + other fixes/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSun48 committed Aug 15, 2024
1 parent be665e2 commit 22a449d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 39 deletions.
16 changes: 4 additions & 12 deletions static/app/utils/withSavedSearches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import type {RouteComponentProps} from 'react-router';
import type {SavedSearch} from 'sentry/types/group';
import useOrganization from 'sentry/utils/useOrganization';
import {useParams} from 'sentry/utils/useParams';
import {useFetchGroupSearchViews} from 'sentry/views/issueList/queries/useFetchGroupSearchViews';
import {useFetchSavedSearchesForOrg} from 'sentry/views/issueList/queries/useFetchSavedSearchesForOrg';
import type {GroupSearchView} from 'sentry/views/issueList/types';
import {useSelectedSavedSearch} from 'sentry/views/issueList/utils/useSelectedSavedSearch';

type InjectedSavedSearchesProps = {
groupSearchView: GroupSearchView | null;
savedSearch: SavedSearch | null;
savedSearchLoading: boolean;
savedSearches: SavedSearch[];
Expand All @@ -34,24 +31,19 @@ function withSavedSearches<P extends InjectedSavedSearchesProps>(
{enabled: !organization.features.includes('issue-stream-custom-views')}
);

const {data: groupSearchViews} = useFetchGroupSearchViews(
{
orgSlug: organization.slug,
},
{enabled: organization.features.includes('issue-stream-custom-views')}
);

const params = useParams();
const selectedSavedSearch = useSelectedSavedSearch();

return (
<WrappedComponent
{...(props as P)}
savedSearches={props.savedSearches ?? savedSearches}
savedSearchLoading={props.savedSearchLoading ?? isLoading}
savedSearchLoading={
!organization.features.includes('issue-stream-custom-views') &&
(props.savedSearchLoading ?? isLoading)
}
savedSearch={props.savedSearch ?? selectedSavedSearch}
selectedSearchId={params.searchId ?? null}
groupSearchView={groupSearchViews?.[0] ?? null}
/>
);
};
Expand Down
49 changes: 25 additions & 24 deletions static/app/views/issueList/customViewsHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useState} from 'react';
import {useEffect, useMemo, useState} from 'react';
import type {InjectedRouter} from 'react-router';
import styled from '@emotion/styled';
import {debounce} from 'lodash';
Expand Down Expand Up @@ -26,7 +26,6 @@ type CustomViewsIssueListHeaderProps = {
queryCounts: QueryCounts;
router: InjectedRouter;
selectedProjectIds: number[];
initalView?: GroupSearchView;
};

type CustomViewsIssueListHeaderTabsContentProps = {
Expand All @@ -36,10 +35,13 @@ type CustomViewsIssueListHeaderTabsContentProps = {
views: GroupSearchView[];
};

function CustomViewsIssueListHeader({...props}: CustomViewsIssueListHeaderProps) {
function CustomViewsIssueListHeader({
selectedProjectIds,
...props
}: CustomViewsIssueListHeaderProps) {
const {projects} = useProjects();
const selectedProjects = projects.filter(({id}) =>
props.selectedProjectIds.includes(Number(id))
selectedProjectIds.includes(Number(id))
);

const {data: groupSearchViews} = useFetchGroupSearchViews({
Expand Down Expand Up @@ -132,20 +134,24 @@ function CustomViewsIssueListHeaderTabsContent({

const {mutate: updateViews} = useUpdateGroupSearchViews();

const debounceUpdateViews = debounce((newTabs: Tab[]) => {
if (newTabs) {
updateViews({
orgSlug: organization.slug,
groupSearchViews: newTabs.map(tab => ({
// Do not send over an ID if it's a temporary id
...(tab.id[0] !== '_' ? {id: tab.id} : {}),
name: tab.label,
query: tab.query,
querySort: tab.querySort,
})),
});
}
}, 500);
const debounceUpdateViews = useMemo(
() =>
debounce((newTabs: Tab[]) => {
if (newTabs) {
updateViews({
orgSlug: organization.slug,
groupSearchViews: newTabs.map(tab => ({
// Do not send over an ID if it's a temporary id
...(tab.id[0] !== '_' ? {id: tab.id} : {}),
name: tab.label,
query: tab.query,
querySort: tab.querySort,
})),
});
}
}, 500),
[organization.slug, updateViews]
);

useEffect(() => {
// If no query, sort, or viewId is present, set the first tab as the selected tab, update query accordingly
Expand Down Expand Up @@ -262,7 +268,7 @@ function CustomViewsIssueListHeaderTabsContent({
}, [queryCounts]);

return (
<StyledDraggableTabBar
<DraggableTabBar
selectedTabKey={selectedTabKey}
setSelectedTabKey={setSelectedTabKey}
tabs={draggableTabs}
Expand Down Expand Up @@ -294,8 +300,3 @@ const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
margin-bottom: 0;
}
`;

const StyledDraggableTabBar = styled(DraggableTabBar)`
border: none;
font: Rubik;
`;
4 changes: 1 addition & 3 deletions static/app/views/issueList/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import withPageFilters from 'sentry/utils/withPageFilters';
import withSavedSearches from 'sentry/utils/withSavedSearches';
import CustomViewsIssueListHeader from 'sentry/views/issueList/customViewsHeader';
import SavedIssueSearches from 'sentry/views/issueList/savedIssueSearches';
import type {GroupSearchView, IssueUpdateData} from 'sentry/views/issueList/types';
import type {IssueUpdateData} from 'sentry/views/issueList/types';
import {parseIssuePrioritySearch} from 'sentry/views/issueList/utils/parseIssuePrioritySearch';

import IssueListActions from './actions';
Expand Down Expand Up @@ -95,7 +95,6 @@ type Params = {

type Props = {
api: Client;
groupSearchView: GroupSearchView | null;
location: Location;
organization: Organization;
params: Params;
Expand Down Expand Up @@ -1229,7 +1228,6 @@ class IssueListOverview extends Component<Props, State> {
{organization.features.includes('issue-stream-custom-views') ? (
<CustomViewsIssueListHeader
organization={organization}
initalView={this.props.groupSearchView ?? undefined}
queryCounts={queryCounts}
router={router}
selectedProjectIds={selection.projects}
Expand Down

0 comments on commit 22a449d

Please sign in to comment.