-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMPROVE] Use PaginatedSelectFiltered in department edition (#23054)
* Fix only first 10 channels getting listed in channels autocomplete * Use paginated select component for displaying channel select data * Fix lint issues Co-authored-by: Tiago Evangelista Pinto <tiago.evangelista@rocket.chat> Co-authored-by: Kevin Aleman <kevin.aleman@rocket.chat>
- Loading branch information
1 parent
e72aea4
commit 995c558
Showing
6 changed files
with
148 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
import { IRoom } from '../../../../definition/IRoom'; | ||
import { useEndpoint } from '../../../contexts/ServerContext'; | ||
import { useScrollableRecordList } from '../../../hooks/lists/useScrollableRecordList'; | ||
import { useComponentDidUpdate } from '../../../hooks/useComponentDidUpdate'; | ||
import { RecordList } from '../../../lib/lists/RecordList'; | ||
|
||
type RoomListOptions = { | ||
text: string; | ||
}; | ||
|
||
export const useRoomsList = ( | ||
options: RoomListOptions, | ||
): { | ||
itemsList: RecordList<IRoom>; | ||
initialItemCount: number; | ||
reload: () => void; | ||
loadMoreItems: (start: number, end: number) => void; | ||
} => { | ||
const [itemsList, setItemsList] = useState(() => new RecordList<IRoom>()); | ||
const reload = useCallback(() => setItemsList(new RecordList<IRoom>()), []); | ||
const endpoint = 'rooms.autocomplete.channelAndPrivate.withPagination'; | ||
|
||
const getRooms = useEndpoint('GET', endpoint); | ||
|
||
useComponentDidUpdate(() => { | ||
options && reload(); | ||
}, [options, reload]); | ||
|
||
const fetchData = useCallback( | ||
async (start, end) => { | ||
const { items: rooms, total } = await getRooms({ | ||
selector: JSON.stringify({ name: options.text || '' }), | ||
offset: start, | ||
count: start + end, | ||
sort: JSON.stringify({ name: 1 }), | ||
}); | ||
|
||
const items = rooms.map((room: any) => { | ||
room._updatedAt = new Date(room._updatedAt); | ||
room.label = room.name; | ||
room.value = room.name; | ||
return room; | ||
}); | ||
|
||
return { | ||
items, | ||
itemCount: total, | ||
}; | ||
}, | ||
[getRooms, options.text], | ||
); | ||
|
||
const { loadMoreItems, initialItemCount } = useScrollableRecordList(itemsList, fetchData, 25); | ||
|
||
return { | ||
reload, | ||
itemsList, | ||
loadMoreItems, | ||
initialItemCount, | ||
}; | ||
}; |
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
10 changes: 10 additions & 0 deletions
10
.../contexts/ServerContext/endpoints/v1/rooms/autocompleteChannelAndPrivateWithPagination.ts
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,10 @@ | ||
import { IRoom } from '../../../../../../definition/IRoom'; | ||
|
||
export type AutocompleteChannelAndPrivateEndpointWithPagination = { | ||
GET: (params: { selector: string; offset?: number; count?: number; sort?: string }) => { | ||
items: IRoom[]; | ||
count: number; | ||
offset: number; | ||
total: number; | ||
}; | ||
}; |
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