Skip to content

Commit

Permalink
fix: small bugs found in datadog logs (#10414)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <[email protected]>
  • Loading branch information
mattkrick authored Oct 24, 2024
1 parent f67328f commit a60106f
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 46 deletions.
3 changes: 3 additions & 0 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
"NotifyResponseReplied": "../../postgres/types/Notification.d#ResponseRepliedNotification as ResponseRepliedNotificationDB",
"NotifyTaskInvolves": "../../postgres/types/Notification.d#TaskInvolvesNotification as TaskInvolvesNotificationDB",
"NotifyTeamArchived": "../../postgres/types/Notification.d#TeamArchivedNotification as TeamArchivedNotificationDB",
"NotifyTeamsLimitReminder": "../../postgres/types/Notification.d#TeamsLimitReminderNotification as TeamsLimitReminderNotificationDB",
"NotifyTeamsLimitExceeded": "../../postgres/types/Notification.d#TeamsLimitExceededNotification as TeamsLimitExceededNotificationDB",
"NotifyPromptToJoinOrg": "../../postgres/types/Notification.d#PromptToJoinOrgNotification as PromptToJoinOrgNotificationDB",
"Organization": "../../postgres/types/index#Organization as OrganizationDB",
"TemplateScaleValue": "./types/TemplateScaleValue#TemplateScaleValueSource as TemplateScaleValueSourceDB",
"SuggestedAction": "../../postgres/types/index#SuggestedAction as SuggestedActionDB",
Expand Down
7 changes: 7 additions & 0 deletions packages/client/components/NotificationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const typePicker: Record<NotificationEnum, LazyExoticPreload<any>> = {
/* webpackChunkName: 'TeamsLimitReminderNotification' */ './TeamsLimitReminderNotification'
)
),
TEAMS_LIMIT_EXCEEDED: lazyPreload(
() =>
import(
/* webpackChunkName: 'TeamsLimitExceededNotification' */ './TeamsLimitExceededNotification'
)
),
PROMPT_TO_JOIN_ORG: lazyPreload(
() =>
import(/* webpackChunkName: 'PromptToJoinOrgNotification' */ './PromptToJoinOrgNotification')
Expand Down Expand Up @@ -74,6 +80,7 @@ const NotificationPicker = (props: Props) => {
...Mentioned_notification
...ResponseReplied_notification
...TeamsLimitReminderNotification_notification
...TeamsLimitExceededNotification_notification
...PromptToJoinOrgNotification_notification
...RequestToJoinOrgNotification_notification
}
Expand Down
59 changes: 59 additions & 0 deletions packages/client/components/TeamsLimitExceededNotification.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import graphql from 'babel-plugin-relay/macro'
import React, {useEffect} from 'react'
import {useFragment} from 'react-relay'
import {TeamsLimitExceededNotification_notification$key} from '~/__generated__/TeamsLimitExceededNotification_notification.graphql'
import useRouter from '~/hooks/useRouter'
import defaultOrgAvatar from '~/styles/theme/images/avatar-organization.svg'
import useAtmosphere from '../hooks/useAtmosphere'
import {Threshold} from '../types/constEnums'
import SendClientSideEvent from '../utils/SendClientSideEvent'
import NotificationAction from './NotificationAction'
import NotificationTemplate from './NotificationTemplate'

interface Props {
notification: TeamsLimitExceededNotification_notification$key
}

const TeamsLimitExceededNotification = (props: Props) => {
const {notification: notificationRef} = props
const atmosphere = useAtmosphere()
const notification = useFragment(
graphql`
fragment TeamsLimitExceededNotification_notification on NotifyTeamsLimitExceeded {
...NotificationTemplate_notification
id
orgId
orgName
orgPicture
}
`,
notificationRef
)
const {history} = useRouter()
const {orgId, orgName, orgPicture} = notification

useEffect(() => {
SendClientSideEvent(atmosphere, 'Upgrade CTA Viewed', {
upgradeCTALocation: 'teamsLimitExceededNotification',
orgId
})
}, [])

const onActionClick = () => {
SendClientSideEvent(atmosphere, 'Upgrade CTA Clicked', {
upgradeCTALocation: 'teamsLimitExceededNotification'
})
history.push(`/me/organizations/${orgId}`)
}

return (
<NotificationTemplate
avatar={orgPicture || defaultOrgAvatar}
message={`"${orgName}" is over the limit of ${Threshold.MAX_STARTER_TIER_TEAMS} free teams.`}
action={<NotificationAction label={'Upgrade'} onClick={onActionClick} />}
notification={notification}
/>
)
}

export default TeamsLimitExceededNotification
5 changes: 5 additions & 0 deletions packages/server/dataloader/customLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ export const userTasks = (parent: RootDataLoader, dependsOn: RegisterDependsOn)
filterQuery,
includeUnassigned
} = key
if (teamIds.length === 0)
return {
key: serializeUserTasksKey(key),
data: []
}
const hasUserIds = userIds?.length > 0
const hasStatusFilters = statusFilters ? statusFilters.length > 0 : false
const teamTasks = await selectTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const inviteToTeamHelper = async (
return approvalErrors[idx] instanceof Error ? undefined : invitee
})
.filter(isNotNull)
if (newAllowedInvitees.length === 0) {
return {error: {message: 'Email is not approved by organization'}}
}
const tokens = await Promise.all(
newAllowedInvitees.map(async () => (await randomBytes(48)).toString('hex'))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ enum IntegrationProviderAuthStrategyEnum {
oauth2
pat
webhook
sharedSecret
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ enum NotificationEnum {
TEAMS_LIMIT_REMINDER
PROMPT_TO_JOIN_ORG
REQUEST_TO_JOIN_ORG
TEAMS_LIMIT_EXCEEDED
}
3 changes: 2 additions & 1 deletion packages/server/graphql/public/types/EstimateStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ const EstimateStage: EstimateStageResolvers = {
},

task: async ({taskId}, _args, {dataLoader}) => {
return dataLoader.get('tasks').loadNonNull(taskId)
const task = await dataLoader.get('tasks').load(taskId)
return task ?? null
}
}

Expand Down
15 changes: 6 additions & 9 deletions packages/server/graphql/public/types/NewMeetingStage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isValidDate from '../../../../client/utils/isValidDate'
import GenericMeetingStage from '../../../database/types/GenericMeetingStage'
import {Logger} from '../../../utils/Logger'
import {getUserId} from '../../../utils/authorization'
Expand Down Expand Up @@ -33,15 +34,11 @@ const NewMeetingStage: NewMeetingStageResolvers = {
return readyToAdvance.filter((userId: string) => userId !== facilitatorUserId).length
},

timeRemaining: ({scheduledEndTime, id, meetingId}) => {
if (scheduledEndTime) {
if (!(scheduledEndTime instanceof Date)) {
console.log('ENDTIME NOT DATE', scheduledEndTime, id, meetingId)
return null
}
return scheduledEndTime.getTime() - Date.now()
}
return null
timeRemaining: ({scheduledEndTime}) => {
if (!scheduledEndTime) return null
const coercedDate = new Date(scheduledEndTime)
if (!isValidDate(coercedDate)) return null
return coercedDate.getTime() - Date.now()
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/server/graphql/public/types/NotifyTeamsLimitExceeded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {NotifyTeamsLimitExceededResolvers} from '../resolverTypes'

const NotifyTeamsLimitExceeded: NotifyTeamsLimitExceededResolvers = {
__isTypeOf: ({type}) => type === 'TEAMS_LIMIT_EXCEEDED',
orgPicture: async ({orgPicture}, _args, {dataLoader}) => {
if (!orgPicture) return null
return dataLoader.get('fileStoreAsset').load(orgPicture)
}
}

export default NotifyTeamsLimitExceeded
5 changes: 4 additions & 1 deletion packages/server/graphql/public/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,24 @@ const User: ReqResolvers<'User'> = {
const validTeamIds = teamIds
? teamIds.filter((teamId: string) => accessibleTeamIds.includes(teamId))
: accessibleTeamIds
if (validTeamIds.length === 0)
return {error: 'No teams', pageInfo: {hasNextPage: false, hasPreviousPage: false}, edges: []}

if (viewerId !== id && !isSuperUser(authToken))
return {error: 'Not user', pageInfo: {hasNextPage: false, hasPreviousPage: false}, edges: []}
const dbAfter = after ? new Date(after) : new Date('3000-01-01')
const minVal = new Date(0)

const pg = getKysely()
const hasEventTypes = eventTypes ? eventTypes.length > 0 : false
const events = await pg
.selectFrom('TimelineEvent')
.selectAll()
.where('userId', '=', viewerId)
.where((eb) => eb.between('createdAt', minVal, dbAfter))
.where('isActive', '=', true)
.where('teamId', 'in', validTeamIds)
.$if(!!eventTypes, (db) => db.where('type', 'in', eventTypes!))
.$if(hasEventTypes, (db) => db.where('type', 'in', eventTypes!))
.orderBy('createdAt', 'desc')
.limit(first + 1)
.execute()
Expand Down
34 changes: 0 additions & 34 deletions packages/server/graphql/types/NotificationEnum.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/server/utils/atlassian/jiraImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (!serverSecret) {
export const updateJiraImageUrls = (cloudId: string, descriptionHTML: string) => {
const imageUrlToHash = {} as Record<string, string>
const projectBaseUrl = `https://api.atlassian.com/ex/jira/${cloudId}`

if (!descriptionHTML) return {updatedDescription: descriptionHTML, imageUrlToHash}
const $ = cheerio.load(descriptionHTML)
$('body')
.find('img')
Expand Down

0 comments on commit a60106f

Please sign in to comment.