Skip to content

Commit

Permalink
chore(rethinkdb): ReflectPrompt: Phase 1 (#10193)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick authored Sep 11, 2024
1 parent 7e77d8b commit e48732b
Show file tree
Hide file tree
Showing 40 changed files with 633 additions and 704 deletions.
6 changes: 6 additions & 0 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
"config": {
"contextType": "../graphql#GQLContext",
"mappers": {
"ReflectTemplatePromptUpdateDescriptionPayload": "./types/ReflectTemplatePromptUpdateDescriptionPayload#ReflectTemplatePromptUpdateDescriptionPayloadSource",
"ReflectTemplatePromptUpdateGroupColorPayload": "./types/ReflectTemplatePromptUpdateGroupColorPayload#ReflectTemplatePromptUpdateGroupColorPayloadSource",
"RemoveReflectTemplatePromptPayload": "./types/RemoveReflectTemplatePromptPayload#RemoveReflectTemplatePromptPayloadSource",
"RenameReflectTemplatePromptPayload": "./types/RenameReflectTemplatePromptPayload#RenameReflectTemplatePromptPayloadSource",
"MoveReflectTemplatePromptPayload": "./types/MoveReflectTemplatePromptPayload#MoveReflectTemplatePromptPayloadSource",
"AddReflectTemplatePromptPayload": "./types/AddReflectTemplatePromptPayload#AddReflectTemplatePromptPayloadSource",
"SetSlackNotificationPayload": "./types/SetSlackNotificationPayload#SetSlackNotificationPayloadSource",
"SetDefaultSlackChannelSuccess": "./types/SetDefaultSlackChannelSuccess#SetDefaultSlackChannelSuccessSource",
"AddCommentSuccess": "./types/AddCommentSuccess#AddCommentSuccessSource",
Expand Down
6 changes: 3 additions & 3 deletions packages/server/database/types/RetrospectivePrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Input {
description: string
groupColor: string
removedAt: Date | null
parentPromptId?: string
parentPromptId?: string | null
}

export default class RetrospectivePrompt {
Expand All @@ -22,7 +22,7 @@ export default class RetrospectivePrompt {
question: string
removedAt: Date | null
updatedAt = new Date()
parentPromptId?: string
parentPromptId?: string | null

constructor(input: Input) {
const {
Expand All @@ -43,6 +43,6 @@ export default class RetrospectivePrompt {
this.description = description || ''
this.groupColor = groupColor
this.removedAt = removedAt
this.parentPromptId = parentPromptId
this.parentPromptId = parentPromptId || null
}
}
12 changes: 12 additions & 0 deletions packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
selectAgendaItems,
selectComments,
selectOrganizations,
selectReflectPrompts,
selectRetroReflections,
selectSlackAuths,
selectSlackNotifications,
Expand Down Expand Up @@ -215,3 +216,14 @@ export const commentsByDiscussionId = foreignKeyLoaderMaker(
return selectComments().where('discussionId', 'in', discussionIds).execute()
}
)

export const _pgreflectPromptsByTemplateId = foreignKeyLoaderMaker(
'_pgreflectPrompts',
'templateId',
async (templateIds) => {
return selectReflectPrompts()
.where('templateId', 'in', templateIds)
.orderBy('sortOrder')
.execute()
}
)
5 changes: 5 additions & 0 deletions packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
selectComments,
selectMeetingSettings,
selectOrganizations,
selectReflectPrompts,
selectRetroReflections,
selectSlackAuths,
selectSlackNotifications,
Expand Down Expand Up @@ -110,3 +111,7 @@ export const slackNotifications = primaryKeyLoaderMaker((ids: readonly string[])
export const comments = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectComments().where('id', 'in', ids).execute()
})

export const _pgreflectPrompts = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectReflectPrompts().where('id', 'in', ids).execute()
})
90 changes: 0 additions & 90 deletions packages/server/graphql/mutations/addReflectTemplatePrompt.ts

This file was deleted.

36 changes: 22 additions & 14 deletions packages/server/graphql/mutations/helpers/makeRetroTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {positionAfter} from '../../../../client/shared/sortOrder'
import ReflectTemplate from '../../../database/types/ReflectTemplate'
import RetrospectivePrompt from '../../../database/types/RetrospectivePrompt'
import generateUID from '../../../generateUID'
import {ReflectPrompt} from '../../../postgres/types'
import getTemplateIllustrationUrl from './getTemplateIllustrationUrl'

interface TemplatePrompt {
Expand All @@ -14,7 +16,7 @@ interface TemplateObject {
}

const makeRetroTemplates = (teamId: string, orgId: string, templateObj: TemplateObject) => {
const reflectPrompts: RetrospectivePrompt[] = []
const reflectPrompts: ReflectPrompt[] = []
const templates: ReflectTemplate[] = []
Object.entries(templateObj).forEach(([templateName, promptBase]) => {
const template = new ReflectTemplate({
Expand All @@ -25,18 +27,24 @@ const makeRetroTemplates = (teamId: string, orgId: string, templateObj: Template
mainCategory: 'retrospective'
})

const prompts = promptBase.map(
(prompt, idx) =>
new RetrospectivePrompt({
teamId,
templateId: template.id,
sortOrder: idx,
question: prompt.question,
description: prompt.description,
groupColor: prompt.groupColor,
removedAt: null
})
)
let curSortOrder = positionAfter('')
const prompts = promptBase.map((prompt) => {
curSortOrder = positionAfter(curSortOrder)
return {
id: generateUID(),
teamId,
templateId: template.id,
sortOrder: curSortOrder,
question: prompt.question,
description: prompt.description,
groupColor: prompt.groupColor,
removedAt: null,
parentPromptId: null,
// can remove these after phase 3
createdAt: new Date(),
updatedAt: new Date()
}
})
templates.push(template)
reflectPrompts.push(...prompts)
})
Expand Down
64 changes: 0 additions & 64 deletions packages/server/graphql/mutations/moveReflectTemplatePrompt.ts

This file was deleted.

This file was deleted.

Loading

0 comments on commit e48732b

Please sign in to comment.