@@ -11,44 +11,58 @@ import { useCheckboxTree } from '@/components/chat/hooks/use-checkbox-tree';
1111import { MESSAGE_VARIANTS } from '@/components/chat/lib/animations' ;
1212import { searchViews } from '@/components/chat/lib/views' ;
1313import { useMessagesHandlerContext } from '@/components/chat/provider/messages-handler-provider' ;
14- import { View } from '@/components/chat/types' ;
14+ import { View , ViewLayout } from '@/components/chat/types' ;
1515import { Button } from '@/components/ui/button' ;
1616import { Popover , PopoverContent , PopoverTrigger } from '@/components/ui/popover' ;
1717import { Separator } from '@/components/ui/separator' ;
1818
1919import { Spaces } from './spaces' ;
2020
21+ function collectSelectableViewIds ( views : View [ ] ) : string [ ] {
22+ const ids : string [ ] = [ ] ;
23+ const stack = [ ...views ] ;
2124
25+ while ( stack . length > 0 ) {
26+ const view = stack . pop ( ) ;
2227
23- export function RelatedViews ( ) {
28+ if ( ! view || view . layout === ViewLayout . AIChat ) continue ;
29+
30+ ids . push ( view . view_id ) ;
31+ stack . push ( ...view . children ) ;
32+ }
33+
34+ return ids ;
35+ }
2436
37+ export function RelatedViews ( ) {
2538 const [ searchValue , setSearchValue ] = useState ( '' ) ;
2639 const [ open , setOpen ] = useState ( false ) ;
2740
2841 const { chatSettings, updateChatSettings } = useMessagesHandlerContext ( ) ;
2942
30- const viewIds = useMemo ( ( ) => {
31- return chatSettings ?. rag_ids || [ ] ;
32- } , [ chatSettings ] ) ;
33-
34- const {
35- fetchViews,
36- viewsLoading,
37- } = useViewLoader ( ) ;
43+ const { fetchViews, viewsLoading } = useViewLoader ( ) ;
3844
3945 const [ folder , setFolder ] = useState < View | null > ( null ) ;
4046
4147 useEffect ( ( ) => {
42- void ( async ( ) => {
48+ void ( async ( ) => {
4349 const data = await fetchViews ( ) ;
4450
45- if ( ! data ) return ;
51+ if ( ! data ) return ;
4652 setFolder ( data ) ;
4753 } ) ( ) ;
4854 } , [ fetchViews ] ) ;
4955
56+ const viewIds = useMemo ( ( ) => {
57+ if ( chatSettings ?. full_workspace && folder ) {
58+ return collectSelectableViewIds ( folder . children || [ ] ) ;
59+ }
60+
61+ return chatSettings ?. rag_ids || [ ] ;
62+ } , [ chatSettings , folder ] ) ;
63+
5064 const filteredSpaces = useMemo ( ( ) => {
51- const spaces = folder ?. children . filter ( view => view . extra ?. is_space ) ;
65+ const spaces = folder ?. children . filter ( ( view ) => view . extra ?. is_space ) ;
5266
5367 return searchViews ( spaces || [ ] , searchValue ) ;
5468 } , [ folder , searchValue ] ) ;
@@ -57,19 +71,15 @@ export function RelatedViews() {
5771 return folder ?. children || [ ] ;
5872 } , [ folder ] ) ;
5973
60- const {
61- getSelected,
62- getCheckStatus,
63- toggleNode,
64- getInitialExpand,
65- } = useCheckboxTree ( viewIds , views ) ;
74+ const { getSelected, getCheckStatus, toggleNode, getInitialExpand } = useCheckboxTree ( viewIds , views ) ;
6675
6776 const length = getSelected ( ) . length ;
6877
6978 const handleToggle = useMemo ( ( ) => {
70- return debounce ( async ( ids : string [ ] ) => {
79+ return debounce ( async ( ids : string [ ] ) => {
7180 await updateChatSettings ( {
7281 rag_ids : ids ,
82+ full_workspace : false ,
7383 } ) ;
7484 } , 500 ) ;
7585 } , [ updateChatSettings ] ) ;
@@ -86,37 +96,30 @@ export function RelatedViews() {
8696 >
8797 < DocIcon className = 'h-5 w-5 text-icon-secondary' />
8898 { length }
89- { viewsLoading ? < LoadingDots size = { 12 } /> : < ChevronDown className = 'w-3 h-5' /> }
90-
99+ { viewsLoading ? < LoadingDots size = { 12 } /> : < ChevronDown className = 'h-5 w-3' /> }
91100 </ Button >
92101 </ PopoverTrigger >
93102 < PopoverContent asChild >
94103 < motion . div
95104 variants = { MESSAGE_VARIANTS . getSelectorVariants ( ) }
96- initial = " hidden"
97- animate = { open ? " visible" : " exit" }
98- className = { 'h-fit min -h-[200px] max -h-[360px ] w-[300px] flex flex-col' }
105+ initial = ' hidden'
106+ animate = { open ? ' visible' : ' exit' }
107+ className = { 'flex h-fit max -h-[360px] min -h-[200px ] w-[300px] flex-col' }
99108 data-testid = 'chat-related-views-popover'
100109 >
101- < SearchInput
102- className = 'm-2'
103- value = { searchValue }
104- onChange = { setSearchValue }
105- />
110+ < SearchInput className = 'm-2' value = { searchValue } onChange = { setSearchValue } />
106111 < Separator />
107- < div className = { 'overflow-x-hidden overflow-y-auto flex-1 appflowy-scrollbar p-2' } >
112+ < div className = { 'appflowy-scrollbar flex-1 overflow-y-auto overflow-x-hidden p-2' } >
108113 < Spaces
109114 getInitialExpand = { getInitialExpand }
110115 spaces = { filteredSpaces }
111116 viewsLoading = { viewsLoading }
112117 getCheckStatus = { getCheckStatus }
113- onToggle = {
114- ( view : View ) => {
115- const ids = toggleNode ( view ) ;
118+ onToggle = { ( view : View ) => {
119+ const ids = toggleNode ( view ) ;
116120
117- void handleToggle ( Array . from ( ids ) ) ;
118- }
119- }
121+ void handleToggle ( Array . from ( ids ) ) ;
122+ } }
120123 />
121124 </ div >
122125 </ motion . div >
0 commit comments