Skip to content

Commit

Permalink
chore(rethinkdb): ReflectPhase: Phase 3 (#10209)
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 3fddb97 commit 1131785
Show file tree
Hide file tree
Showing 41 changed files with 104 additions and 382 deletions.
2 changes: 1 addition & 1 deletion codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"RRule": "rrule-rust#RRuleSet",
"Reactable": "../../database/types/Reactable#Reactable",
"Reactji": "../types/Reactji#ReactjiSource",
"ReflectPrompt": "../../database/types/RetrospectivePrompt#default",
"ReflectPrompt": "../../postgres/types/index#ReflectPrompt",
"ReflectTemplate": "../../database/types/ReflectTemplate#default",
"RemoveApprovedOrganizationDomainsSuccess": "./types/RemoveApprovedOrganizationDomainsSuccess#RemoveApprovedOrganizationDomainsSuccessSource",
"RemoveIntegrationSearchQuerySuccess": "./types/RemoveIntegrationSearchQuerySuccess#RemoveIntegrationSearchQuerySuccessSource",
Expand Down
48 changes: 8 additions & 40 deletions packages/client/components/GroupingKanbanColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,15 @@ import {GroupingKanbanColumn_reflectionGroups$key} from '~/__generated__/Groupin
import {useCoverable} from '~/hooks/useControlBarCovers'
import useDeepEqual from '~/hooks/useDeepEqual'
import useSubColumns from '~/hooks/useSubColumns'
import makeMinWidthMediaQuery from '~/utils/makeMinWidthMediaQuery'
import useAtmosphere from '../hooks/useAtmosphere'
import useMutationProps from '../hooks/useMutationProps'
import CreateReflectionMutation from '../mutations/CreateReflectionMutation'
import {PALETTE} from '../styles/paletteV3'
import {
BezierCurve,
Breakpoint,
DragAttribute,
ElementWidth,
MeetingControlBarEnum
} from '../types/constEnums'
import {BezierCurve, DragAttribute, ElementWidth, MeetingControlBarEnum} from '../types/constEnums'
import getNextSortOrder from '../utils/getNextSortOrder'
import {SwipeColumn} from './GroupingKanban'
import GroupingKanbanColumnHeader from './GroupingKanbanColumnHeader'
import ReflectionGroup from './ReflectionGroup/ReflectionGroup'

const Column = styled('div')<{
isLengthExpanded: boolean
isFirstColumn: boolean
isLastColumn: boolean
}>(({isLengthExpanded, isFirstColumn, isLastColumn}) => ({
alignContent: 'flex-start',
background: PALETTE.SLATE_300,
borderRadius: 8,
display: 'flex',
flex: 1,
flexDirection: 'column',
height: '100%',
minWidth: ElementWidth.REFLECTION_COLUMN,
padding: 0,
position: 'relative',
transition: `all 100ms ${BezierCurve.DECELERATE}`,
[makeMinWidthMediaQuery(Breakpoint.SINGLE_REFLECTION_COLUMN)]: {
height: isLengthExpanded ? '100%' : `calc(100% - ${MeetingControlBarEnum.HEIGHT}px)`,
margin: `0 ${isLastColumn ? 16 : 8}px 0px ${isFirstColumn ? 16 : 8}px`,
maxWidth: 'min-content'
}
}))

const ColumnScrollContainer = styled('div')({
display: 'flex',
// must hide X on firefox v84
Expand Down Expand Up @@ -160,8 +129,6 @@ const GroupingKanbanColumn = (props: Props) => {
const isLengthExpanded =
useCoverable(promptId, columnRef, MeetingControlBarEnum.HEIGHT, phaseRef, columnsRef) ||
!!endedAt
const isFirstColumn = prompt.sortOrder === 0
const isLastColumn = Math.round(prompt.sortOrder) === reflectPromptsCount - 1
const groups = useDeepEqual(reflectionGroups)
// group may be undefined because relay could GC before useMemo in the Kanban recomputes >:-(
const filteredReflectionGroups = useMemo(
Expand All @@ -188,12 +155,13 @@ const GroupingKanbanColumn = (props: Props) => {
submitMutation()
CreateReflectionMutation(atmosphere, {input}, {onError, onCompleted})
}

return (
<Column
isLengthExpanded={isLengthExpanded}
isFirstColumn={isFirstColumn}
isLastColumn={isLastColumn}
<div
className={`relative ml-2 mr-2 flex h-full min-w-[320px] flex-1
flex-col content-start rounded-lg bg-slate-300 p-0 transition-all duration-100 ease-out first-of-type:ml-4 last-of-type:mr-4
single-reflection-column:max-w-min
${isLengthExpanded ? '' : 'single-reflection-column:h-[calc(100%-56px)]'}
max-w-min`}
ref={columnRef}
data-cy={`group-column-${question}`}
>
Expand Down Expand Up @@ -240,7 +208,7 @@ const GroupingKanbanColumn = (props: Props) => {
)
})}
</ColumnScrollContainer>
</Column>
</div>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Threshold} from '~/types/constEnums'
import {AddTemplatePrompt_prompts$key} from '../../../__generated__/AddTemplatePrompt_prompts.graphql'
import LinkButton from '../../../components/LinkButton'
import AddReflectTemplatePromptMutation from '../../../mutations/AddReflectTemplatePromptMutation'
import dndNoise from '../../../utils/dndNoise'
import {positionAfter} from '../../../shared/sortOrder'
import withMutationProps, {WithMutationProps} from '../../../utils/relay/withMutationProps'

const AddPromptLink = styled(LinkButton)({
Expand Down Expand Up @@ -51,8 +51,8 @@ const AddTemplatePrompt = (props: Props) => {
const {templateId, onError, onCompleted, submitMutation, submitting} = props
if (submitting) return
submitMutation()
const sortOrders = prompts.map(({sortOrder}) => sortOrder)
const sortOrder = Math.max(0, ...sortOrders) + 1 + dndNoise()
const lastPrompt = prompts.at(-1)!
const sortOrder = positionAfter(lastPrompt.sortOrder)
const promptCount = prompts.length
AddReflectTemplatePromptMutation(
atmosphere,
Expand Down
16 changes: 2 additions & 14 deletions packages/client/modules/meeting/components/TemplatePromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {useFragment} from 'react-relay'
import {TemplatePromptList_prompts$key} from '../../../__generated__/TemplatePromptList_prompts.graphql'
import useAtmosphere from '../../../hooks/useAtmosphere'
import MoveReflectTemplatePromptMutation from '../../../mutations/MoveReflectTemplatePromptMutation'
import {getSortOrder} from '../../../shared/sortOrder'
import {TEMPLATE_PROMPT} from '../../../utils/constants'
import dndNoise from '../../../utils/dndNoise'
import TemplatePromptItem from './TemplatePromptItem'

interface Props {
Expand Down Expand Up @@ -53,19 +53,7 @@ const TemplatePromptList = (props: Props) => {
) {
return
}

let sortOrder
if (destination.index === 0) {
sortOrder = destinationPrompt.sortOrder - 1 + dndNoise()
} else if (destination.index === prompts.length - 1) {
sortOrder = destinationPrompt.sortOrder + 1 + dndNoise()
} else {
const offset = source.index > destination.index ? -1 : 1
sortOrder =
((prompts[destination.index + offset]?.sortOrder ?? 0) + destinationPrompt.sortOrder) / 2 +
dndNoise()
}

const sortOrder = getSortOrder(prompts, source.index, destination.index)
const {id: promptId} = sourcePrompt
const variables = {promptId, sortOrder}
MoveReflectTemplatePromptMutation(atmosphere, variables, {templateId})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import handleAddReflectTemplatePrompt from './handlers/handleAddReflectTemplateP

interface Handlers extends BaseLocalHandlers {
promptCount: number
sortOrder: number
sortOrder: string
}

graphql`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ graphql`
`

const mutation = graphql`
mutation MoveReflectTemplatePromptMutation($promptId: ID!, $sortOrder: Float!) {
mutation MoveReflectTemplatePromptMutation($promptId: ID!, $sortOrder: String!) {
moveReflectTemplatePrompt(promptId: $promptId, sortOrder: $sortOrder) {
error {
message
Expand Down
5 changes: 0 additions & 5 deletions packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ import NotificationTeamArchived from './types/NotificationTeamArchived'
import NotificationTeamInvitation from './types/NotificationTeamInvitation'
import PasswordResetRequest from './types/PasswordResetRequest'
import PushInvitation from './types/PushInvitation'
import RetrospectivePrompt from './types/RetrospectivePrompt'
import Task from './types/Task'

export type RethinkSchema = {
ReflectPrompt: {
type: RetrospectivePrompt
index: 'teamId' | 'templateId'
}
MassInvitation: {
type: MassInvitation
index: 'teamMemberId'
Expand Down
48 changes: 0 additions & 48 deletions packages/server/database/types/RetrospectivePrompt.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ export const commentsByDiscussionId = foreignKeyLoaderMaker(
}
)

export const _pgreflectPromptsByTemplateId = foreignKeyLoaderMaker(
'_pgreflectPrompts',
export const reflectPromptsByTemplateId = foreignKeyLoaderMaker(
'reflectPrompts',
'templateId',
async (templateIds) => {
return selectReflectPrompts()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ export const comments = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectComments().where('id', 'in', ids).execute()
})

export const _pgreflectPrompts = primaryKeyLoaderMaker((ids: readonly string[]) => {
export const reflectPrompts = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectReflectPrompts().where('id', 'in', ids).execute()
})
13 changes: 0 additions & 13 deletions packages/server/dataloader/rethinkForeignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ export const completedMeetingsByTeamId = new RethinkForeignKeyLoaderMaker(
}
)

export const reflectPromptsByTemplateId = new RethinkForeignKeyLoaderMaker(
'reflectPrompts',
'templateId',
async (templateIds) => {
const r = await getRethink()
return r
.table('ReflectPrompt')
.getAll(r.args(templateIds), {index: 'templateId'})
.orderBy('sortOrder')
.run()
}
)

export const massInvitationsByTeamMemberId = new RethinkForeignKeyLoaderMaker(
'massInvitations',
'teamMemberId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import RethinkPrimaryKeyLoaderMaker from './RethinkPrimaryKeyLoaderMaker'
/**
* all rethink dataloader types which also must exist in {@link rethinkDriver/RethinkSchema}
*/
export const reflectPrompts = new RethinkPrimaryKeyLoaderMaker('ReflectPrompt')
export const massInvitations = new RethinkPrimaryKeyLoaderMaker('MassInvitation')
export const meetingMembers = new RethinkPrimaryKeyLoaderMaker('MeetingMember')
export const newMeetings = new RethinkPrimaryKeyLoaderMaker('NewMeeting')
Expand Down
33 changes: 9 additions & 24 deletions packages/server/graphql/mutations/removeReflectTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {GraphQLID, GraphQLNonNull} from 'graphql'
import {sql} from 'kysely'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
Expand All @@ -21,9 +21,7 @@ const removeReflectTemplate = {
{templateId}: {templateId: string},
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
const template = await dataLoader.get('meetingTemplates').load(templateId)
Expand All @@ -46,27 +44,14 @@ const removeReflectTemplate = {

// RESOLUTION
const {id: settingsId} = settings
await Promise.all([
r
.table('ReflectPrompt')
.getAll(teamId, {index: 'teamId'})
.filter({
templateId
})
.update({
removedAt: now,
updatedAt: now
})
.run(),
pg
.with('RemoveTemplate', (qb) =>
qb.updateTable('MeetingTemplate').set({isActive: false}).where('id', '=', templateId)
)
.updateTable('ReflectPrompt')
.set({removedAt: now})
.where('templateId', '=', templateId)
.execute()
])
await pg
.with('RemoveTemplate', (qb) =>
qb.updateTable('MeetingTemplate').set({isActive: false}).where('id', '=', templateId)
)
.updateTable('ReflectPrompt')
.set({removedAt: sql`CURRENT_TIMESTAMP`})
.where('templateId', '=', templateId)
.execute()
dataLoader.clearAll('reflectPrompts')
if (settings.selectedTemplateId === templateId) {
const nextTemplate = templates.find((template) => template.id !== templateId)
Expand Down
30 changes: 13 additions & 17 deletions packages/server/graphql/mutations/updateTemplateScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,19 @@ const updateTemplateScope = {
removedAt: null
}
})
await Promise.all([
pg
.with('MeetingTemplateInsert', (qc) =>
qc.insertInto('MeetingTemplate').values(clonedTemplate)
)
.with('MeetingTemplateDeactivate', (qc) =>
qc.updateTable('MeetingTemplate').set({isActive: false}).where('id', '=', templateId)
)
.with('RemovePrompts', (qc) =>
qc.updateTable('ReflectPrompt').set({removedAt: now}).where('id', 'in', promptIds)
)
.insertInto('ReflectPrompt')
.values(clonedPrompts.map((p) => ({...p, sortOrder: String(p.sortOrder)})))
.execute(),
r.table('ReflectPrompt').insert(clonedPrompts).run(),
r.table('ReflectPrompt').getAll(r.args(promptIds)).update({removedAt: now}).run()
])
await pg
.with('MeetingTemplateInsert', (qc) =>
qc.insertInto('MeetingTemplate').values(clonedTemplate)
)
.with('MeetingTemplateDeactivate', (qc) =>
qc.updateTable('MeetingTemplate').set({isActive: false}).where('id', '=', templateId)
)
.with('RemovePrompts', (qc) =>
qc.updateTable('ReflectPrompt').set({removedAt: now}).where('id', 'in', promptIds)
)
.insertInto('ReflectPrompt')
.values(clonedPrompts.map((p) => ({...p, sortOrder: String(p.sortOrder)})))
.execute()
dataLoader.clearAll(['reflectPrompts', 'meetingTemplates'])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const generateMeetingSummary: MutationResolvers['generateMeetingSummary'] = asyn
rawReflections.map(async (reflection) => {
const {promptId, creatorId, plaintextContent} = reflection
const [prompt, creator] = await Promise.all([
dataLoader.get('reflectPrompts').load(promptId),
dataLoader.get('reflectPrompts').loadNonNull(promptId),
creatorId ? dataLoader.get('users').loadNonNull(creatorId) : null
])
const {question} = prompt
Expand Down
Loading

0 comments on commit 1131785

Please sign in to comment.