Skip to content

Commit e464d61

Browse files
authored
feat(saved-searches): Add 'show more' button when there are many saved searches (getsentry#40990)
1 parent 4890581 commit e464d61

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

static/app/views/issueList/savedIssueSearches.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ describe('SavedIssueSearches', function () {
5050
expect(container).toSnapshot();
5151
});
5252

53+
it('hides saves searches by default past first 5', function () {
54+
render(
55+
<SavedIssueSearches
56+
{...defaultProps}
57+
savedSearches={[...new Array(6)].map((_, i) => ({
58+
...orgSearch,
59+
name: 'Test Search',
60+
id: i,
61+
}))}
62+
/>
63+
);
64+
65+
expect(screen.getAllByText('Test Search')).toHaveLength(5);
66+
userEvent.click(screen.getByRole('button', {name: /show all 6 saved searches/i}));
67+
expect(screen.getAllByText('Test Search')).toHaveLength(6);
68+
});
69+
5370
it('can select a saved search', function () {
5471
render(<SavedIssueSearches {...defaultProps} />);
5572

static/app/views/issueList/savedIssueSearches.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {Fragment} from 'react';
1+
import {Fragment, useState} from 'react';
22
import {css} from '@emotion/react';
33
import styled from '@emotion/styled';
4+
import orderBy from 'lodash/orderBy';
45

56
import {openModal} from 'sentry/actionCreators/modal';
67
import Button from 'sentry/components/button';
@@ -40,6 +41,8 @@ type CreateNewSavedSearchButtonProps = Pick<
4041
'query' | 'sort' | 'organization'
4142
>;
4243

44+
const MAX_SHOWN_SEARCHES = 5;
45+
4346
const SavedSearchItem = ({
4447
organization,
4548
onSavedSearchDelete,
@@ -149,6 +152,8 @@ const SavedIssueSearches = ({
149152
query,
150153
sort,
151154
}: SavedIssueSearchesProps) => {
155+
const [showAll, setShowAll] = useState(false);
156+
152157
if (!isOpen) {
153158
return null;
154159
}
@@ -165,11 +170,17 @@ const SavedIssueSearches = ({
165170
);
166171
}
167172

168-
const orgSavedSearches = savedSearches.filter(
169-
search => !search.isGlobal && !search.isPinned
173+
const orgSavedSearches = orderBy(
174+
savedSearches.filter(search => !search.isGlobal && !search.isPinned),
175+
'dateCreated',
176+
'desc'
170177
);
171178
const recommendedSavedSearches = savedSearches.filter(search => search.isGlobal);
172179

180+
const shownOrgSavedSearches = showAll
181+
? orgSavedSearches
182+
: orgSavedSearches.slice(0, MAX_SHOWN_SEARCHES);
183+
173184
return (
174185
<StyledSidebar>
175186
{orgSavedSearches.length > 0 && (
@@ -179,7 +190,7 @@ const SavedIssueSearches = ({
179190
<CreateNewSavedSearchButton {...{organization, query, sort}} />
180191
</HeadingContainer>
181192
<SearchesContainer>
182-
{orgSavedSearches.map(item => (
193+
{shownOrgSavedSearches.map(item => (
183194
<SavedSearchItem
184195
key={item.id}
185196
organization={organization}
@@ -189,6 +200,11 @@ const SavedIssueSearches = ({
189200
/>
190201
))}
191202
</SearchesContainer>
203+
{orgSavedSearches.length > shownOrgSavedSearches.length && (
204+
<ShowAllButton size="zero" borderless onClick={() => setShowAll(true)}>
205+
{t('Show all %s saved searches', orgSavedSearches.length.toLocaleString())}
206+
</ShowAllButton>
207+
)}
192208
</Fragment>
193209
)}
194210
{recommendedSavedSearches.length > 0 && (
@@ -297,4 +313,15 @@ const OverflowMenu = styled(DropdownMenuControl)`
297313
right: ${space(1)};
298314
`;
299315

316+
const ShowAllButton = styled(Button)`
317+
color: ${p => p.theme.linkColor};
318+
font-weight: normal;
319+
margin-top: 2px;
320+
padding: ${space(1)} ${space(2)};
321+
322+
&:hover {
323+
color: ${p => p.theme.linkHoverColor};
324+
}
325+
`;
326+
300327
export default SavedIssueSearches;

0 commit comments

Comments
 (0)