Skip to content

Commit

Permalink
chore(rethinkdb): TemplateScale: One-shot (#10021)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <[email protected]>
  • Loading branch information
mattkrick authored Jul 25, 2024
1 parent 1e6c0b4 commit 0c6c8e7
Show file tree
Hide file tree
Showing 41 changed files with 569 additions and 502 deletions.
3 changes: 3 additions & 0 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
"NotifyTaskInvolves": "../../database/types/NotificationTaskInvolves#default",
"NotifyTeamArchived": "../../database/types/NotificationTeamArchived#default",
"Organization": "./types/Organization#OrganizationSource",
"TemplateScaleValue": "./types/TemplateScaleValue#TemplateScaleValueSource as TemplateScaleValueSourceDB",
"TemplateScale": "../../postgres/types/index#TemplateScale as TemplateScaleDB",
"TemplateScaleRef": "../../postgres/types/index#TemplateScaleRef as TemplateScaleRefDB",
"OrganizationUser": "../../postgres/types/index#OrganizationUser as OrganizationUserDB",
"PokerMeeting": "../../database/types/MeetingPoker#default as MeetingPoker",
"PokerMeetingMember": "../../database/types/MeetingPokerMeetingMember#default as PokerMeetingMemberDB",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const SelectScaleDropdown = (props: Props) => {
scales {
id
isStarter
name
...ScaleDropdownMenuItem_scale
}
}
Expand All @@ -70,8 +71,11 @@ const SelectScaleDropdown = (props: Props) => {
const {selectedScale, team} = dimension
const {id: seletedScaleId} = selectedScale
const {id: teamId, scales} = team
const sortedScales = scales.toSorted((a, b) => {
return a.isStarter !== b.isStarter ? (a.isStarter ? 1 : -1) : a.name.localeCompare(b.name)
})
const defaultActiveIdx = useMemo(
() => scales.findIndex(({id}) => id === seletedScaleId),
() => sortedScales.findIndex(({id}) => id === seletedScaleId),
[dimension]
)

Expand All @@ -98,17 +102,17 @@ const SelectScaleDropdown = (props: Props) => {
{...menuProps}
defaultActiveIdx={defaultActiveIdx}
>
{scales.map((scale) => (
{sortedScales.map((scale) => (
<ScaleDropdownMenuItem
key={scale.id}
scale={scale}
dimension={dimension}
scaleCount={scales.length}
scaleCount={sortedScales.length}
closePortal={closePortal}
/>
))}
<MenuItemHR key='HR1' />
{scales.length < Threshold.MAX_POKER_TEMPLATE_SCALES && (
{sortedScales.length < Threshold.MAX_POKER_TEMPLATE_SCALES && (
<MenuItem
key='create'
label={
Expand Down
1 change: 1 addition & 0 deletions packages/client/mutations/AddPokerTemplateScaleMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import handleAddPokerTemplateScale from './handlers/handleAddPokerTemplateScale'
graphql`
fragment AddPokerTemplateScaleMutation_scale on AddPokerTemplateScalePayload {
scale {
...ScaleDropdownMenuItem_scale
id
name
values {
Expand Down
6 changes: 3 additions & 3 deletions packages/client/mutations/RemovePokerTemplateScaleMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ graphql`
...ScaleDropdownMenuItem_scale
id
teamId
}
dimensions {
...PokerTemplateScalePicker_dimension
dimensions {
...PokerTemplateScalePicker_dimension
}
}
}
`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {RecordProxy, RecordSourceSelectorProxy} from 'relay-runtime'
import addNodeToArray from '../../utils/relay/addNodeToArray'

const handleAddPokerTemplateScale = (
newNode: RecordProxy | null,
Expand All @@ -9,7 +8,8 @@ const handleAddPokerTemplateScale = (
const teamId = newNode.getValue('teamId') as string
const team = store.get(teamId)
if (!team) return
addNodeToArray(newNode, team, 'scales', 'teamId')
const existingScales = team.getLinkedRecords('scales') || []
team.setLinkedRecords([newNode, ...existingScales], 'scales')
}

export default handleAddPokerTemplateScale
1 change: 1 addition & 0 deletions packages/client/utils/dndNoise.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// DEPRECATED. Sorting by floats has resulted in a lot of bugs. Please use sortOrder.ts & sort lexicographically
// return a little noise so we never have a sort order conflict between tasks
export default function dndNoise() {
return Math.random() / 1e15 - 5e-16
Expand Down
2 changes: 1 addition & 1 deletion packages/embedder/indexing/meetingTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const createTextFromPokerMeetingTemplate = async (
const dimensionsText = (
await Promise.all(
dimensions.map(async ({name, description, scaleId}) => {
const scale = await dataLoader.get('templateScales').load(scaleId)
const scale = await dataLoader.get('templateScales').loadNonNull(scaleId)
const scaleValues = scale.values.map(({label}) => label).join(', ')
return `${name}\n${description ?? ''}\n${scale.name}\n${scaleValues}`
})
Expand Down
10 changes: 0 additions & 10 deletions packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import FailedAuthRequest from './types/FailedAuthRequest'
import Invoice from './types/Invoice'
import InvoiceItemHook from './types/InvoiceItemHook'
import MassInvitation from './types/MassInvitation'
import MeetingTemplate from './types/MeetingTemplate'
import NotificationKickedOut from './types/NotificationKickedOut'
import NotificationMeetingStageTimeLimitEnd from './types/NotificationMeetingStageTimeLimitEnd'
import NotificationMentioned from './types/NotificationMentioned'
Expand All @@ -32,7 +31,6 @@ import SuggestedActionInviteYourTeam from './types/SuggestedActionInviteYourTeam
import SuggestedActionTryTheDemo from './types/SuggestedActionTryTheDemo'
import Task from './types/Task'
import TemplateDimension from './types/TemplateDimension'
import TemplateScale from './types/TemplateScale'

export type RethinkSchema = {
AgendaItem: {
Expand Down Expand Up @@ -118,10 +116,6 @@ export type RethinkSchema = {
type: PushInvitation
index: 'userId'
}
MeetingTemplate: {
type: MeetingTemplate
index: 'teamId' | 'orgId'
}
ScheduledJob: {
type: ScheduledJobUnion
index: 'runAt' | 'type'
Expand Down Expand Up @@ -159,10 +153,6 @@ export type RethinkSchema = {
type: TemplateDimension
index: 'teamId' | 'templateId' | 'scaleId'
}
TemplateScale: {
type: TemplateScale
index: 'teamId'
}
}

export type DBType = {
Expand Down
48 changes: 0 additions & 48 deletions packages/server/database/types/TemplateScale.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/server/dataloader/customRedisQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ const customRedisQueries = {
)

return publicTemplatesByType
},
starterScales: async (teamIds: string[]) => {
const r = await getRethink()

const starterScales = await Promise.all(
teamIds.map((teamId) => {
return r
.table('TemplateScale')
.getAll(teamId, {index: 'teamId'})
.filter({isStarter: true})
.filter((row: RDatum) => row('removedAt').default(null).eq(null))
.run()
})
)

return starterScales
}
} as const

Expand Down
8 changes: 8 additions & 0 deletions packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getKysely from '../postgres/getKysely'
import {selectTemplateScale} from '../postgres/select'
import {foreignKeyLoaderMaker} from './foreignKeyLoaderMaker'
import {selectOrganizations, selectRetroReflections, selectTeams} from './primaryKeyLoaderMakers'

Expand Down Expand Up @@ -124,3 +125,10 @@ export const organizationUsersByOrgId = foreignKeyLoaderMaker(
.execute()
}
)

export const scalesByTeamId = foreignKeyLoaderMaker('templateScales', 'teamId', async (teamIds) => {
return selectTemplateScale()
.where('teamId', 'in', teamIds)
.orderBy(['isStarter', 'name'])
.execute()
})
5 changes: 5 additions & 0 deletions packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {getTeamPromptResponsesByIds} from '../postgres/queries/getTeamPromptResp
import getTemplateRefsByIds from '../postgres/queries/getTemplateRefsByIds'
import getTemplateScaleRefsByIds from '../postgres/queries/getTemplateScaleRefsByIds'
import {getUsersByIds} from '../postgres/queries/getUsersByIds'
import {selectTemplateScale} from '../postgres/select'
import {primaryKeyLoaderMaker} from './primaryKeyLoaderMaker'

export const users = primaryKeyLoaderMaker(getUsersByIds)
Expand Down Expand Up @@ -150,3 +151,7 @@ export const organizationUsers = primaryKeyLoaderMaker((ids: readonly string[])
export const teamMembers = primaryKeyLoaderMaker((ids: readonly string[]) => {
return getKysely().selectFrom('TeamMember').selectAll().where('id', 'in', ids).execute()
})

export const templateScales = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectTemplateScale().where('TemplateScale.id', 'in', ids).execute()
})
14 changes: 0 additions & 14 deletions packages/server/dataloader/rethinkForeignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,6 @@ export const meetingMembersByUserId = new RethinkForeignKeyLoaderMaker(
}
)

export const scalesByTeamId = new RethinkForeignKeyLoaderMaker(
'templateScales',
'teamId',
async (teamIds) => {
const r = await getRethink()
return r
.table('TemplateScale')
.getAll(r.args(teamIds), {index: 'teamId'})
.filter((row: RDatum) => row('removedAt').default(null).eq(null))
.orderBy('sortOrder')
.run()
}
)

export const templateDimensionsByTemplateId = new RethinkForeignKeyLoaderMaker(
'templateDimensions',
'templateId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const meetingMembers = new RethinkPrimaryKeyLoaderMaker('MeetingMember')
export const newMeetings = new RethinkPrimaryKeyLoaderMaker('NewMeeting')
export const newFeatures = new RethinkPrimaryKeyLoaderMaker('NewFeature')
export const notifications = new RethinkPrimaryKeyLoaderMaker('Notification')
export const templateScales = new RethinkPrimaryKeyLoaderMaker('TemplateScale')
export const slackAuths = new RethinkPrimaryKeyLoaderMaker('SlackAuth')
export const slackNotifications = new RethinkPrimaryKeyLoaderMaker('SlackNotification')
export const suggestedActions = new RethinkPrimaryKeyLoaderMaker('SuggestedAction')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ const addPokerTemplateDimension = {
// RESOLUTION
const sortOrder =
Math.max(0, ...activeDimensions.map((dimension) => dimension.sortOrder)) + 1 + dndNoise()

const availableScales = await r
.table('TemplateScale')
.filter({teamId})
.filter((row: RDatum) => row('removedAt').default(null).eq(null))
.orderBy(r.desc('updatedAt'))
.run()
const rawAvailableScales = await dataLoader.get('scalesByTeamId').load(teamId)
const availableScales = rawAvailableScales.sort((a, b) => (a.updatedAt > b.updatedAt ? -1 : 1))
const defaultScaleId =
availableScales.length > 0
? availableScales.map((teamScale) => teamScale.id)[0]
Expand Down
Loading

0 comments on commit 0c6c8e7

Please sign in to comment.