1
- import { Fragment } from 'react' ;
1
+ import { Fragment , useState } from 'react' ;
2
2
import { css } from '@emotion/react' ;
3
3
import styled from '@emotion/styled' ;
4
+ import orderBy from 'lodash/orderBy' ;
4
5
5
6
import { openModal } from 'sentry/actionCreators/modal' ;
6
7
import Button from 'sentry/components/button' ;
@@ -40,6 +41,8 @@ type CreateNewSavedSearchButtonProps = Pick<
40
41
'query' | 'sort' | 'organization'
41
42
> ;
42
43
44
+ const MAX_SHOWN_SEARCHES = 5 ;
45
+
43
46
const SavedSearchItem = ( {
44
47
organization,
45
48
onSavedSearchDelete,
@@ -149,6 +152,8 @@ const SavedIssueSearches = ({
149
152
query,
150
153
sort,
151
154
} : SavedIssueSearchesProps ) => {
155
+ const [ showAll , setShowAll ] = useState ( false ) ;
156
+
152
157
if ( ! isOpen ) {
153
158
return null ;
154
159
}
@@ -165,11 +170,17 @@ const SavedIssueSearches = ({
165
170
) ;
166
171
}
167
172
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'
170
177
) ;
171
178
const recommendedSavedSearches = savedSearches . filter ( search => search . isGlobal ) ;
172
179
180
+ const shownOrgSavedSearches = showAll
181
+ ? orgSavedSearches
182
+ : orgSavedSearches . slice ( 0 , MAX_SHOWN_SEARCHES ) ;
183
+
173
184
return (
174
185
< StyledSidebar >
175
186
{ orgSavedSearches . length > 0 && (
@@ -179,7 +190,7 @@ const SavedIssueSearches = ({
179
190
< CreateNewSavedSearchButton { ...{ organization, query, sort} } />
180
191
</ HeadingContainer >
181
192
< SearchesContainer >
182
- { orgSavedSearches . map ( item => (
193
+ { shownOrgSavedSearches . map ( item => (
183
194
< SavedSearchItem
184
195
key = { item . id }
185
196
organization = { organization }
@@ -189,6 +200,11 @@ const SavedIssueSearches = ({
189
200
/>
190
201
) ) }
191
202
</ 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
+ ) }
192
208
</ Fragment >
193
209
) }
194
210
{ recommendedSavedSearches . length > 0 && (
@@ -297,4 +313,15 @@ const OverflowMenu = styled(DropdownMenuControl)`
297
313
right: ${ space ( 1 ) } ;
298
314
` ;
299
315
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
+
300
327
export default SavedIssueSearches ;
0 commit comments