Skip to content

Commit

Permalink
fix: summary does not load indefinitely if there are no votes (#10669)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickoferrall authored Jan 14, 2025
1 parent 18abb1a commit 84b8d60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const WholeMeetingSummary = (props: Props) => {
useAI
}
... on RetrospectiveMeeting {
isLoadingSummary
reflectionGroups(sortBy: voteCount) {
reflections {
id
Expand All @@ -43,11 +44,11 @@ const WholeMeetingSummary = (props: Props) => {
meetingRef
)
if (meeting.__typename === 'RetrospectiveMeeting') {
const {summary: wholeMeetingSummary, reflectionGroups, organization} = meeting
const {reflectionGroups, organization, isLoadingSummary} = meeting
const reflections = reflectionGroups?.flatMap((group) => group.reflections) // reflectionCount hasn't been calculated yet so check reflections length
const hasMoreThanOneReflection = reflections?.length && reflections.length > 1
if (!hasMoreThanOneReflection || !organization.useAI || !hasAiApiKey) return null
if (!wholeMeetingSummary) return <WholeMeetingSummaryLoading />
if (isLoadingSummary) return <WholeMeetingSummaryLoading />
return <WholeMeetingSummaryResult meetingRef={meeting} />
} else if (meeting.__typename === 'TeamPromptMeeting') {
const {summary: wholeMeetingSummary, responses, organization} = meeting
Expand Down
16 changes: 13 additions & 3 deletions packages/server/graphql/mutations/helpers/generateRetroSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {DataLoaderWorker} from '../../graphql'
import canAccessAI from './canAccessAI'
import {transformRetroToAIFormat} from './transformRetroToAIFormat'

const setSummaryToNull = async (meetingId: string) => {
const pg = getKysely()
await pg.updateTable('NewMeeting').set({summary: null}).where('id', '=', meetingId).execute()
return null
}

export const generateRetroSummary = async (
meetingId: string,
dataLoader: DataLoaderWorker,
Expand All @@ -15,11 +21,13 @@ export const generateRetroSummary = async (

const team = await dataLoader.get('teams').loadNonNull(teamId)
const isAISummaryAccessible = await canAccessAI(team, 'retrospective', dataLoader)
if (!isAISummaryAccessible) return null
if (!isAISummaryAccessible) {
return setSummaryToNull(meetingId)
}

const transformedMeeting = await transformRetroToAIFormat(meetingId, dataLoader)
if (!transformedMeeting || transformedMeeting.length === 0) {
return null
return setSummaryToNull(meetingId)
}

const yamlData = yaml.dump(transformedMeeting, {
Expand All @@ -28,7 +36,9 @@ export const generateRetroSummary = async (

const manager = new OpenAIServerManager()
const newSummary = await manager.generateSummary(yamlData, prompt)
if (!newSummary) return null
if (!newSummary) {
return setSummaryToNull(meetingId)
}

const pg = getKysely()
await pg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ const safeEndRetrospective = async ({
endedAt: sql`CURRENT_TIMESTAMP`,
phases: JSON.stringify(phases),
usedReactjis: JSON.stringify(insights.usedReactjis),
engagement: insights.engagement
engagement: insights.engagement,
summary: '<loading>' // set as "<loading>" while the AI summary is being generated
})
.where('id', '=', meetingId)
.executeTakeFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ type RetrospectiveMeeting implements NewMeeting {
"""
facilitator: TeamMember!

"""
If the AI generated summary is loading
"""
isLoadingSummary: Boolean!

"""
The team members that were active during the time of the meeting
"""
Expand Down
2 changes: 2 additions & 0 deletions packages/server/graphql/public/types/RetrospectiveMeeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const RetrospectiveMeeting: RetrospectiveMeetingResolvers = {
const res = await dataLoader.get('meetingMembersByMeetingId').load(meetingId)
return res as RetroMeetingMember[]
},
summary: ({summary}) => (summary === '<loading>' ? null : summary),
isLoadingSummary: ({summary}) => summary === '<loading>',
reflectionCount: ({reflectionCount}) => reflectionCount || 0,
reflectionGroup: async ({id: meetingId}, {reflectionGroupId}, {dataLoader}) => {
const reflectionGroup = await dataLoader.get('retroReflectionGroups').load(reflectionGroupId)
Expand Down

0 comments on commit 84b8d60

Please sign in to comment.