Skip to content
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

chore(rethinkdb): SuggestedAction: Phase 3 #10043

Merged
merged 19 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"Comment": "../../database/types/Comment#default as CommentDB",
"Company": "./types/Company#CompanySource",
"CreateGcalEventInput": "./types/CreateGcalEventInput#default",
"CreateGcalEventInput": "./types/CreateGcalEventInput#default",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove duplicate entry for CreateGcalEventInput.

The entry for CreateGcalEventInput is duplicated, which can cause confusion and potential errors in the code generation process.

- "CreateGcalEventInput": "./types/CreateGcalEventInput#default",

Committable suggestion was skipped due to low confidence.

"CreateImposterTokenPayload": "./types/CreateImposterTokenPayload#CreateImposterTokenPayloadSource",
"CreateStripeSubscriptionSuccess": "./types/CreateStripeSubscriptionSuccess#CreateStripeSubscriptionSuccessSource",
"CreateTaskPayload": "./types/CreateTaskPayload#CreateTaskPayloadSource",
Expand Down Expand Up @@ -112,6 +113,7 @@
"NotifyTeamArchived": "../../database/types/NotificationTeamArchived#default",
"Organization": "./types/Organization#OrganizationSource",
"TemplateScaleValue": "./types/TemplateScaleValue#TemplateScaleValueSource as TemplateScaleValueSourceDB",
"SuggestedAction": "../../postgres/types/index#SuggestedAction as SuggestedActionDB",
"TemplateScale": "../../postgres/types/index#TemplateScale as TemplateScaleDB",
"TemplateScaleRef": "../../postgres/types/index#TemplateScaleRef as TemplateScaleRefDB",
"OrganizationUser": "../../postgres/types/index#OrganizationUser as OrganizationUserDB",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MeetingSummaryEmail from './SummaryEmail/MeetingSummaryEmail/MeetingSumma
const query = graphql`
query MeetingSummaryEmailRootSSRQuery($meetingId: ID!) {
viewer {
newMeeting(meetingId: $meetingId) {
meeting(meetingId: $meetingId) {
meetingType
team {
id
Expand Down Expand Up @@ -42,9 +42,9 @@ const MeetingSummaryEmailRootSSR = (props: Props) => {
// viewer will be null on initial SSR render
if (!data?.viewer) return null
const {viewer} = data
const {newMeeting} = viewer
if (!newMeeting) return null
const {team} = newMeeting
const {meeting} = viewer
if (!meeting) return null
const {team} = meeting
const {id: teamId} = team
const options = {searchParams: meetingSummaryUrlParams}
const referrerUrl = makeAppURL(appOrigin, `new-summary/${meetingId}`, options)
Expand All @@ -53,7 +53,7 @@ const MeetingSummaryEmailRootSSR = (props: Props) => {
const emailCSVUrl = makeAppURL(appOrigin, `new-summary/${meetingId}/csv`, options)
return (
<MeetingSummaryEmail
meeting={newMeeting}
meeting={meeting}
referrer={'email'}
teamDashUrl={teamDashUrl}
meetingUrl={meetingUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Props extends WithMutationProps {
const query = graphql`
query ExportToCSVQuery($meetingId: ID!) {
viewer {
newMeeting(meetingId: $meetingId) {
meeting(meetingId: $meetingId) {
meetingType
team {
name
Expand Down Expand Up @@ -116,7 +116,7 @@ const query = graphql`
}
`

type Meeting = NonNullable<NonNullable<ExportToCSVQuery['response']['viewer']>['newMeeting']>
type Meeting = NonNullable<NonNullable<ExportToCSVQuery['response']['viewer']>['meeting']>
type ExportableTypeName = 'Task' | 'Reflection' | 'Comment' | 'Reply'

interface CSVPokerRow {
Expand Down Expand Up @@ -326,7 +326,7 @@ const ExportToCSV = (props: Props) => {
onCompleted()
if (!data) return
const {viewer} = data
const {newMeeting} = viewer
const {meeting: newMeeting} = viewer
if (!newMeeting) return
const rows = getRows(newMeeting)
if (rows.length === 0) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const query = graphql`
...DashTopBar_query
viewer {
...DashSidebar_viewer
newMeeting(meetingId: $meetingId) {
meeting(meetingId: $meetingId) {
...MeetingSummaryEmail_meeting
...MeetingLockedOverlay_meeting
id
Expand All @@ -49,7 +49,7 @@ const NewMeetingSummary = (props: Props) => {
const {urlAction, queryRef} = props
const data = usePreloadedQuery<NewMeetingSummaryQuery>(query, queryRef)
const {viewer} = data
const {newMeeting, teams} = viewer
const {meeting: newMeeting, teams} = viewer
const activeMeetings = teams.flatMap((team) => team.activeMeetings).filter(Boolean)
const {history} = useRouter()
useEffect(() => {
Expand Down
22 changes: 12 additions & 10 deletions packages/server/__tests__/autoJoin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import faker from 'faker'
import getRethink from '../database/rethinkDriver'
import createEmailVerification from '../email/createEmailVerification'
import getKysely from '../postgres/getKysely'
import {getUserTeams, sendIntranet, sendPublic} from './common'

const signUpVerified = async (email: string) => {
Expand All @@ -23,12 +23,14 @@ const signUpVerified = async (email: string) => {
// manually generate verification token so also the founder can be verified
await createEmailVerification({email, password})

const r = await getRethink()
const verificationToken = await r
.table('EmailVerification')
.getAll(email, {index: 'email'})
.nth(0)('token')
.run()
const pg = getKysely()
const verificationToken = (
await pg
.selectFrom('EmailVerification')
.select('token')
.where('email', '=', email)
.executeTakeFirstOrThrow(() => new Error(`No verification token found for ${email}`))
).token

const verifyEmail = await sendPublic({
query: `
Expand All @@ -55,9 +57,9 @@ const signUpVerified = async (email: string) => {
expect(verifyEmail).toMatchObject({
data: {
verifyEmail: {
authToken: expect.toBeString(),
authToken: expect.any(String),
user: {
id: expect.toBeString()
id: expect.any(String)
}
}
}
Expand Down Expand Up @@ -153,7 +155,7 @@ test.skip('autoJoin on multiple teams does not create duplicate `OrganizationUse
const newEmail = `${faker.internet.userName()}@${domain}`.toLowerCase()
const {user: newUser} = await signUpVerified(newEmail)

expect(newUser.tms).toIncludeSameMembers(teamIds)
expect(newUser.tms).toEqual(expect.arrayContaining(teamIds))
expect(newUser.organizations).toMatchObject([
{
id: orgId
Expand Down
9 changes: 0 additions & 9 deletions packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import NotificationTeamInvitation from './types/NotificationTeamInvitation'
import PasswordResetRequest from './types/PasswordResetRequest'
import PushInvitation from './types/PushInvitation'
import RetrospectivePrompt from './types/RetrospectivePrompt'
import SuggestedActionCreateNewTeam from './types/SuggestedActionCreateNewTeam'
import SuggestedActionInviteYourTeam from './types/SuggestedActionInviteYourTeam'
import SuggestedActionTryTheDemo from './types/SuggestedActionTryTheDemo'
import Task from './types/Task'

export type RethinkSchema = {
Expand Down Expand Up @@ -127,12 +124,6 @@ export type RethinkSchema = {
type: SlackNotification
index: 'teamId' | 'userId'
}
SuggestedAction: {
// tryRetroMeeting = 'tryRetroMeeting',
// tryActionMeeting = 'tryActionMeeting'
type: SuggestedActionCreateNewTeam | SuggestedActionInviteYourTeam | SuggestedActionTryTheDemo
index: 'userId' | 'teamId'
}
Task: {
type: Task
index:
Expand Down
32 changes: 0 additions & 32 deletions packages/server/database/types/EmailVerification.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/server/database/types/SuggestedAction.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/server/database/types/SuggestedActionCreateNewTeam.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/server/database/types/SuggestedActionInviteYourTeam.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/server/database/types/SuggestedActionTryTheDemo.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/server/dataloader/customLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export interface ReactablesKey {

export interface UserTasksKey {
first: number
after?: Date
after?: Date | null
userIds: string[]
teamIds: string[]
archived?: boolean
statusFilters: TaskStatusEnum[]
filterQuery?: string
statusFilters?: TaskStatusEnum[] | null
filterQuery?: string | null
includeUnassigned?: boolean
}

Expand Down
14 changes: 13 additions & 1 deletion packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import getKysely from '../postgres/getKysely'
import {selectTemplateDimension, selectTemplateScale} from '../postgres/select'
import {
selectSuggestedAction,
selectTemplateDimension,
selectTemplateScale
} from '../postgres/select'
import {foreignKeyLoaderMaker} from './foreignKeyLoaderMaker'
import {selectOrganizations, selectRetroReflections, selectTeams} from './primaryKeyLoaderMakers'

Expand Down Expand Up @@ -151,3 +155,11 @@ export const templateDimensionsByScaleId = foreignKeyLoaderMaker(
return selectTemplateDimension().where('scaleId', 'in', scaleIds).orderBy('sortOrder').execute()
}
)

export const suggestedActionsByUserId = foreignKeyLoaderMaker(
'suggestedActions',
'userId',
async (userIds) => {
return selectSuggestedAction().where('userId', 'in', userIds).execute()
}
)
10 changes: 9 additions & 1 deletion packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ 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 {selectTemplateDimension, selectTemplateScale} from '../postgres/select'
import {
selectSuggestedAction,
selectTemplateDimension,
selectTemplateScale
} from '../postgres/select'
import {primaryKeyLoaderMaker} from './primaryKeyLoaderMaker'

export const users = primaryKeyLoaderMaker(getUsersByIds)
Expand Down Expand Up @@ -159,3 +163,7 @@ export const templateScales = primaryKeyLoaderMaker((ids: readonly string[]) =>
export const templateDimensions = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectTemplateDimension().where('id', 'in', ids).execute()
})

export const suggestedActions = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectSuggestedAction().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 @@ -134,19 +134,6 @@ export const slackNotificationsByTeamId = new RethinkForeignKeyLoaderMaker(
}
)

export const suggestedActionsByUserId = new RethinkForeignKeyLoaderMaker(
'suggestedActions',
'userId',
async (userIds) => {
const r = await getRethink()
return r
.table('SuggestedAction')
.getAll(r.args(userIds), {index: 'userId'})
.filter({removedAt: null})
.run()
}
)

export const tasksByDiscussionId = new RethinkForeignKeyLoaderMaker(
'tasks',
'discussionId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ export const newFeatures = new RethinkPrimaryKeyLoaderMaker('NewFeature')
export const notifications = new RethinkPrimaryKeyLoaderMaker('Notification')
export const slackAuths = new RethinkPrimaryKeyLoaderMaker('SlackAuth')
export const slackNotifications = new RethinkPrimaryKeyLoaderMaker('SlackNotification')
export const suggestedActions = new RethinkPrimaryKeyLoaderMaker('SuggestedAction')
export const tasks = new RethinkPrimaryKeyLoaderMaker('Task')
export const teamInvitations = new RethinkPrimaryKeyLoaderMaker('TeamInvitation')
Loading
Loading