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

fix: consolidate organizations sorting logic #10680

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading