Skip to content

Commit 0da6530

Browse files
Merge pull request #433 from microsoft/psl-bug-17683
fix: Document gets generated without title, if title is not added pre-export.
2 parents 44d64da + 1bb6abd commit 0da6530

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ describe('Draft Component', () => {
124124
isLoadedSections: [{ title: 'Section 1', content: 'Content of section 1' },
125125
{ title: 'Section 2', content: 'Content of section 2.' }
126126
],
127+
draftedDocument: {
128+
sections: [
129+
{ title: 'Section 1', content: 'Content of section 1' },
130+
{ title: 'Section 2', content: 'Content of section 2.' }
131+
]
132+
},
133+
draftedDocumentTitle: '', // this must be explicitly ''
127134
}
128135
renderComponent(mockStateWithIncompleteLoad)
129136
await waitFor(() => {
@@ -139,6 +146,13 @@ describe('Draft Component', () => {
139146
isLoadedSections: [{ title: 'Section 1', content: 'Content of section 1' },
140147
{ title: 'Section 2', content: 'Content of section 2.' }
141148
],
149+
draftedDocument: {
150+
sections: [
151+
{ title: 'Section 1', content: 'Content of section 1' },
152+
{ title: 'Section 2', content: 'Content of section 2.' }
153+
]
154+
},
155+
draftedDocumentTitle: '', // critical for button to be enabled
142156
}
143157
renderComponent(mockStateWithIncompleteLoad)
144158

@@ -231,6 +245,13 @@ describe('Draft Component', () => {
231245
isLoadedSections: [{ title: 'Section 1', content: 'Content of section 1' },
232246
{ title: 'Section 2', content: 'Content of section 2.' }
233247
], // One section not loaded
248+
draftedDocument: {
249+
sections: [
250+
{ title: 'Section 1', content: 'Content of section 1' },
251+
{ title: 'Section 2', content: 'Content of section 2.' }
252+
]
253+
},
254+
draftedDocumentTitle: '', // must be empty string
234255
}
235256
renderComponent(mockStateWithIncompleteLoad)
236257

@@ -253,7 +274,13 @@ describe('Draft Component', () => {
253274
isLoadedSections: [{ title: 'Section 1', content: 'Content of section 1' },
254275
{ title: 'Section 2', content: 'Content of section 2.' }
255276
],
256-
draftedDocumentTitle: null
277+
draftedDocument: {
278+
sections: [
279+
{ title: 'Section 1', content: 'Content of section 1' },
280+
{ title: 'Section 2', content: 'Content of section 2.' }
281+
]
282+
},
283+
draftedDocumentTitle: null // allow null here
257284
}
258285
renderComponent(mockStateWithIncompleteLoad)
259286
await waitFor(async () => {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useContext, useEffect, useState } from 'react'
1+
import { useContext, useEffect, useMemo, useState } from 'react'
22
import styles from './Draft.module.css'
33
import { useLocation, useNavigate } from 'react-router-dom'
44
import TitleCard from '../../components/DraftCards/TitleCard'
@@ -16,6 +16,8 @@ const Draft = (): JSX.Element => {
1616

1717
// get draftedDocument from context
1818
const draftedDocument = appStateContext?.state.draftedDocument
19+
const currentChat = appStateContext?.state.currentChat
20+
const draftedDocumentTitle = appStateContext?.state.draftedDocumentTitle;
1921
const sections = draftedDocument?.sections ?? []
2022

2123
const isLoadedSections = appStateContext?.state.isLoadedSections
@@ -27,7 +29,9 @@ const Draft = (): JSX.Element => {
2729

2830
const [isExportButtonDisable, setIsExportButtonDisable] = useState<boolean>(false)
2931

30-
32+
useMemo(() => {
33+
currentChat?.title && appStateContext?.dispatch({ type: 'UPDATE_DRAFTED_DOCUMENT_TITLE', payload: currentChat.title })
34+
}, [currentChat?.title])
3135

3236
useEffect(() => {
3337
sections.forEach((item, index) => {
@@ -45,13 +49,14 @@ const Draft = (): JSX.Element => {
4549

4650

4751
useEffect(() => {
48-
if (isLoadedSections?.length === sections.length) {
52+
const title = draftedDocumentTitle ?? '' // Normalize null to ''
53+
if (isLoadedSections?.length === sections.length && title === '') {
4954
setIsExportButtonDisable(false);
5055
}
5156
else {
5257
setIsExportButtonDisable(true);
5358
}
54-
}, [isLoadedSections])
59+
}, [isLoadedSections, draftedDocumentTitle])
5560

5661

5762
if (!draftedDocument) {

0 commit comments

Comments
 (0)