Skip to content

Commit 3fd95ea

Browse files
Export button disabled when section API's are in progress
1 parent ff584d6 commit 3fd95ea

File tree

9 files changed

+45
-37
lines changed

9 files changed

+45
-37
lines changed

src/frontend/src/components/ChatHistory/ChatHistoryList.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { AppStateContext } from '../../state/AppProvider';
44
import ChatHistoryList from './ChatHistoryList';
55
import { Conversation } from '../../api/models';
66
import { ChatHistoryLoadingState } from '../../api/models';
7+
import {defaultMockState} from '../../test/test.utils';
8+
79

810
const mockDispatch = jest.fn();
911

1012
const mockState = {
13+
...defaultMockState,
1114
isChatHistoryOpen: false,
1215
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
1316
isCosmosDBAvailable: {
@@ -27,8 +30,7 @@ const mockState = {
2730
isRequestInitiated: false,
2831
failedSections : [],
2932
isFailedReqInitiated : false,
30-
isLoading : false,
31-
isLoadedSections : []
33+
isLoading : false
3234
};
3335

3436
const renderChatHistoryList = (stateOverride = {}) => {

src/frontend/src/components/ChatHistory/ChatHistoryPanel.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { AppStateContext } from '../../state/AppProvider';
44
import { ChatHistoryPanel } from './ChatHistoryPanel';
55
import { ChatHistoryLoadingState, ChatMessage, Conversation, CosmosDBStatus, Feedback, historyDeleteAll,historyList } from '../../api';
66
import * as api from '../../api';
7+
import {defaultMockState} from '../../test/test.utils';
8+
79

810
// Mock the API function
911
jest.mock('../../api/api', () => ({
@@ -37,6 +39,7 @@ const mockConversation: Conversation = {
3739

3840
// Mock initial state for the context
3941
const mockState = {
42+
...defaultMockState,
4043
chatHistoryLoadingState: ChatHistoryLoadingState.Success,
4144
isCosmosDBAvailable: { cosmosDB: true, status: CosmosDBStatus.NotConfigured },
4245
chatHistory: [mockConversation], // Added mock chat history here
@@ -54,8 +57,7 @@ const mockState = {
5457
isRequestInitiated: false,
5558
failedSections : [],
5659
isFailedReqInitiated : false,
57-
isLoading : false,
58-
isLoadedSections: []
60+
isLoading : false
5961
};
6062

6163
const mockDispatch = jest.fn();

src/frontend/src/components/DraftCards/SectionCard.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { MemoryRouter } from 'react-router-dom'
99
import { ChatHistoryLoadingState } from '../../api/models'
1010
import { act } from 'react-dom/test-utils'
1111

12+
import {defaultMockState} from '../../test/test.utils';
13+
1214
// Mock the API
1315
jest.mock('../../api/api', () => ({
1416
sectionGenerate: jest.fn(() =>
@@ -26,6 +28,7 @@ jest.mock('../../assets/Generate.svg', () => 'mocked-generate-icon')
2628

2729
const mockDispatch = jest.fn()
2830
const mockState = {
31+
...defaultMockState,
2932
draftedDocument: {
3033
title: 'Draft Document',
3134
sections: [
@@ -56,8 +59,7 @@ const mockState = {
5659
isRequestInitiated: false,
5760
failedSections : [],
5861
isFailedReqInitiated : false,
59-
isLoading : false,
60-
isLoadedSections: []
62+
isLoading : false
6163
}
6264

6365
const renderWithContext = (idx = 0) =>

src/frontend/src/components/DraftCards/SectionCard.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
142142

143143
useEffect(() => {
144144
if (appStateContext.state?.failedSections.length >0 && appStateContext.state?.failedSections[0].title === sectionTitle && isLoading && !appStateContext.state.isFailedReqInitiated) {
145-
console.log("appStateContext.state?.failedSections", appStateContext.state?.failedSections);
146145
const tempItem = {
147146
title: sectionTitle,
148147
description: sectionDescription,
@@ -159,13 +158,13 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
159158
async function fetchSectionContent(sectionTitle: string, sectionDescription: string , isReqFrom = '') {
160159
setIsLoading(true)
161160
//onLoadingChange(true)
161+
162162
const sectionGenerateRequest: SectionGenerateRequest = { sectionTitle, sectionDescription }
163163

164164
const response = await sectionGenerate(sectionGenerateRequest)
165165
const responseBody = await response.json()
166166

167167
if(responseBody?.error?.includes("429")) {
168-
console.log("retriggerd !!!")
169168
const failedSectionItems = {
170169
title: sectionTitle,
171170
description: sectionDescription,
@@ -212,6 +211,11 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
212211
useEffect(() => {
213212
if (sectionContent === '' && !isLoading && !isManuallyCleared) {
214213
fetchSectionContent(sectionTitle, sectionDescription)
214+
}else {
215+
if(sectionContent!='' && !isLoading){
216+
const updatedSection: Section = {...section}
217+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : updatedSection} })
218+
}
215219
}
216220
}, [sectionContent, isLoading, isManuallyCleared])
217221

@@ -261,6 +265,7 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
261265
console.error('Section description is empty')
262266
return
263267
}
268+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : null, 'title' : sectionTitle ,'act' :'removeItem' } })
264269

265270
setIsPopoverOpen(false)
266271
fetchSectionContent(sectionTitle, updatedSectionDescription)

src/frontend/src/components/Sidebar/Sidebar.test.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Sidebar from './Sidebar';
55
import { ChatHistoryLoadingState } from '../../api/models';
66
import { BrowserRouter as Router, useLocation ,useNavigate} from 'react-router-dom';
77
import { getUserInfo } from '../../api';
8+
import {defaultMockState} from '../../test/test.utils';
89

910
const mockDispatch = jest.fn();
1011
beforeEach(() => {
@@ -35,6 +36,7 @@ jest.mock('react-router-dom', () => ({
3536
useLocation: jest.fn(),
3637
}));
3738
const mockState = {
39+
...defaultMockState,
3840
isChatHistoryOpen: false,
3941
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
4042
isCosmosDBAvailable: {
@@ -55,25 +57,8 @@ const mockState = {
5557
failedSections : [],
5658
isFailedReqInitiated : false,
5759
isLoading : false,
58-
isLoadedSections : []
59-
};
60-
const mockState2 = {
61-
isChatHistoryOpen: false,
62-
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
63-
chatHistory: null,
64-
filteredChatHistory: [],
65-
currentChat: null,
66-
browseChat: null,
67-
generateChat: null,
68-
isCosmosDBAvailable: {
69-
cosmosDB: false,
70-
status: 'NotConfigured'
71-
},
72-
frontendSettings: { auth_enabled: false },
73-
feedbackState: {},
74-
draftedDocument: null,
75-
draftedDocumentTitle: ''
7660
};
61+
7762
const renderSidebar = (stateOverride = {}, pathname = '/') => {
7863

7964
(useLocation as jest.Mock).mockReturnValue({ pathname });

src/frontend/src/pages/draft/Draft.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ const Draft = (): JSX.Element => {
4141
}, index * 500);
4242
});
4343

44-
//appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : null, 'act': 'removeAll' } })
45-
44+
return ()=>{
45+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : null, 'act': 'removeAll' } })
46+
}
4647
}, []);
4748

4849
useEffect(()=>{

src/frontend/src/state/AppProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type Action =
6767
| { type: 'REMOVED_FAILED_SECTION'; payload: {section : Section} }
6868
| { type: 'UPDATE_SECTION_API_REQ_STATUS'; payload: boolean }
6969
| { type: 'SET_LOADING'; payload: boolean }
70-
| { type: 'UPDATE_IS_LOADED_SECTIONS'; payload: {section : Section | null ,'act'?: string} }
70+
| { type: 'UPDATE_IS_LOADED_SECTIONS'; payload: {section : Section | null , title ? : string , 'act'?: string} }
7171

7272
const initialState: AppState = {
7373
isChatHistoryOpen: false,

src/frontend/src/state/AppReducer.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,25 @@ export const appStateReducer = (state: AppState, action: Action): AppState => {
122122

123123
case 'UPDATE_IS_LOADED_SECTIONS' :
124124
let tempLoadedSection:any = [];
125-
if(action.payload.act === 'removeAll')
126-
{
127-
tempLoadedSection = [];
128-
}else
129-
{
130-
tempLoadedSection = [...state.isLoadedSections];
131-
tempLoadedSection.push(action.payload.section)
125+
console.log("action.payload", action.payload);
126+
127+
switch(action.payload.act){
128+
case 'removeAll':
129+
tempLoadedSection = [];
130+
break;
131+
case 'removeItem' :
132+
tempLoadedSection = state.isLoadedSections.filter((item) => item.title !== action.payload.title);
133+
break;
134+
default :
135+
const exists = state.isLoadedSections.some((item) => item.title === action.payload.section?.title);
136+
console.log("exists", exists);
137+
tempLoadedSection = [...state.isLoadedSections];
138+
if(!exists){
139+
tempLoadedSection.push(action.payload.section);
140+
}
141+
break;
132142
}
143+
133144
return {...state, isLoadedSections: tempLoadedSection}
134145

135146
default:

src/frontend/src/test/test.utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { render, RenderResult } from '@testing-library/react';
44
import { AppStateContext } from '../state/AppProvider';
55
import { Conversation, ChatHistoryLoadingState } from '../api/models';
66
// Default mock state
7-
const defaultMockState = {
7+
export const defaultMockState = {
88
isChatHistoryOpen: true,
99
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
1010
isCosmosDBAvailable: { cosmosDB: true, status: 'success' },

0 commit comments

Comments
 (0)