Skip to content

Commit

Permalink
fix: consolidate organizations sorting logic (#10680)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianrunhe authored Jan 16, 2025
1 parent ce489aa commit 3d9b6d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 2 additions & 9 deletions packages/client/components/DashNavList/DashNavList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {ManageAccounts} from '@mui/icons-material'
import graphql from 'babel-plugin-relay/macro'
import {useFragment} from 'react-relay'
import {DashNavList_organization$key} from '../../__generated__/DashNavList_organization.graphql'
import {TierEnum} from '../../__generated__/OrganizationSubscription.graphql'
import {Tooltip} from '../../ui/Tooltip/Tooltip'
import {TooltipContent} from '../../ui/Tooltip/TooltipContent'
import {TooltipTrigger} from '../../ui/Tooltip/TooltipTrigger'
import sortByTier from '../../utils/sortByTier'
import DashNavListTeams from './DashNavListTeams'

const EmptyTeams = styled('div')({
Expand Down Expand Up @@ -43,14 +43,7 @@ const DashNavList = (props: Props) => {
organizationsRef
)

const TierEnumValues: TierEnum[] = ['enterprise', 'team', 'starter']

const sortedOrgs = organizations.toSorted((a, b) => {
const aTier = TierEnumValues.indexOf(a.tier)
const bTier = TierEnumValues.indexOf(b.tier)
return aTier < bTier ? -1 : aTier > bTier ? 1 : a.name.localeCompare(b.name)
})

const sortedOrgs = sortByTier(organizations)
const teams = organizations.flatMap((org) => org.viewerTeams)

return (
Expand Down
7 changes: 4 additions & 3 deletions packages/server/graphql/public/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MeetingMemberId from 'parabol-client/shared/gqlIds/MeetingMemberId'
import isTaskPrivate from 'parabol-client/utils/isTaskPrivate'
import {isNotNull} from 'parabol-client/utils/predicates'
import toTeamMemberId from 'parabol-client/utils/relay/toTeamMemberId'
import sortByTier from 'parabol-client/utils/sortByTier'
import {
AUTO_GROUPING_THRESHOLD,
MAX_REDUCTION_PERCENTAGE,
Expand Down Expand Up @@ -430,14 +431,14 @@ const User: ReqResolvers<'User'> = {
const organizationUsers = await dataLoader.get('organizationUsersByUserId').load(userId)
const orgIds = organizationUsers.map(({orgId}) => orgId)
const organizations = (await dataLoader.get('organizations').loadMany(orgIds)).filter(isValid)
organizations.sort((a, b) => (a.name > b.name ? 1 : -1))
const sortedOrgs = sortByTier(organizations)
const viewerId = getUserId(authToken)
if (viewerId === userId || isSuperUser(authToken)) {
return organizations
return sortedOrgs
}
const viewerOrganizationUsers = await dataLoader.get('organizationUsersByUserId').load(viewerId)
const viewerOrgIds = viewerOrganizationUsers.map(({orgId}) => orgId)
return organizations.filter((organization) => viewerOrgIds.includes(organization.id))
return sortedOrgs.filter((organization) => viewerOrgIds.includes(organization.id))
},

overLimitCopy: async ({id: userId, overLimitCopy}, _args, {dataLoader}) => {
Expand Down

0 comments on commit 3d9b6d2

Please sign in to comment.