-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
project: Move field report title generation logic to server #1470
Merged
frozenhelium
merged 6 commits into
develop
from
fix/field-report-title-server-generation
Jan 29, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f96e177
fix: move field report title generation logic to server
samshara b846509
fix: show server generated `summary` field for field report
samshara 45b33a0
feat: preview generated title for field report
samshara bbbcaa5
chore: update pnpm to the latest v8 release
samshara 0686327
chore: add translation migrations
samshara d613c14
feat: use debounced variables for field report title generation
samshara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"go-web-app": patch | ||
--- | ||
|
||
Move field report / emergency title generation logic from client to server |
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
8 changes: 8 additions & 0 deletions
8
app/src/views/FieldReportForm/ContextFields/TitlePreview/i18n.json
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,8 @@ | ||
{ | ||
"namespace": "fieldReportForm", | ||
"strings": { | ||
"titlePreview": "Title Preview", | ||
"failedToGenerateTitle": "Failed To Generate the Field Report Title" | ||
} | ||
} | ||
|
70 changes: 70 additions & 0 deletions
70
app/src/views/FieldReportForm/ContextFields/TitlePreview/index.tsx
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,70 @@ | ||
import { useMemo } from 'react'; | ||
import { TextOutput } from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
|
||
import useAlert from '#hooks/useAlert'; | ||
import useDebouncedValue from '#hooks/useDebouncedValue'; | ||
import { useRequest } from '#utils/restRequest'; | ||
|
||
import i18n from './i18n.json'; | ||
|
||
interface Props { | ||
country: number; | ||
disasterType: number; | ||
event?: number; | ||
isCovidReport?: boolean; | ||
startDate?: string; | ||
title: string; | ||
} | ||
|
||
function TitlePreview(props: Props) { | ||
const { | ||
country, | ||
disasterType, | ||
event, | ||
isCovidReport, | ||
startDate, | ||
title, | ||
} = props; | ||
|
||
const strings = useTranslation(i18n); | ||
const alert = useAlert(); | ||
|
||
const variables = useMemo(() => ({ | ||
countries: [country], | ||
is_covid_report: isCovidReport, | ||
start_date: startDate, | ||
dtype: disasterType, | ||
event, | ||
title, | ||
}), [country, isCovidReport, startDate, disasterType, event, title]); | ||
|
||
const debouncedVariables = useDebouncedValue(variables); | ||
|
||
const { | ||
response: generateTitleResponse, | ||
} = useRequest({ | ||
url: '/api/v2/field-report/generate-title/', | ||
method: 'POST', | ||
body: debouncedVariables, | ||
preserveResponse: true, | ||
onFailure: () => { | ||
alert.show( | ||
strings.failedToGenerateTitle, | ||
{ | ||
variant: 'danger', | ||
}, | ||
); | ||
}, | ||
}); | ||
|
||
return ( | ||
<TextOutput | ||
value={generateTitleResponse?.title} | ||
label={strings.titlePreview} | ||
strongLabel | ||
/> | ||
); | ||
} | ||
|
||
export default TitlePreview; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets debounce the variables to avoid too many requests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the latest commit