chore: remove unused queries on user event types (#11159)

* remove unused queries on user event types

* Fix types
pull/11149/head
alannnc 2023-09-06 01:00:06 -07:00 committed by GitHub
parent 3539693729
commit 829f90b82f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 30 deletions

View File

@ -391,7 +391,9 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
className="relative right-3 top-1"
size="sm"
truncateAfter={4}
items={type.users.map(
items={
type?.users
? type.users.map(
(organizer: { name: string | null; username: string | null }) => ({
alt: organizer.name || "",
image: `${orgBranding?.fullDomain ?? WEBAPP_URL}/${
@ -399,15 +401,17 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
}/avatar.png`,
title: organizer.name || "",
})
)}
)
: []
}
/>
)}
{isManagedEventType && type.children && (
{isManagedEventType && type?.children && type.children?.length > 0 && (
<AvatarGroup
className="relative right-3 top-1"
size="sm"
truncateAfter={4}
items={type.children
items={type?.children
.flatMap((ch) => ch.users)
.map((user: Pick<User, "name" | "username">) => ({
alt: user.name || "",

View File

@ -61,7 +61,9 @@ export default function WorkflowDetailsPage(props: Props) {
...options,
...group.eventTypes.map((eventType) => ({
value: String(eventType.id),
label: `${eventType.title} ${eventType.children.length ? `(+${eventType.children.length})` : ``}`,
label: `${eventType.title} ${
eventType.children && eventType.children.length ? `(+${eventType.children.length})` : ``
}`,
})),
];
}, [] as Option[]) || [],

View File

@ -52,14 +52,6 @@ const userEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
users: {
select: userSelect,
},
// Temporarily putting this back for testing
children: {
include: {
users: {
select: userSelect,
},
},
},
parentId: true,
hosts: {
select: {
@ -74,13 +66,13 @@ const userEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
const teamEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
...userEventTypeSelect,
// children: {
// include: {
// users: {
// select: userSelect,
// },
// },
// },
children: {
include: {
users: {
select: userSelect,
},
},
},
});
export const compareMembership = (mship1: MembershipRole, mship2: MembershipRole) => {
@ -167,11 +159,15 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) =>
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" });
}
const mapEventType = (eventType: (typeof user.eventTypes)[number]) => ({
type UserEventTypes = (typeof user.eventTypes)[number];
type TeamEventTypeChildren = (typeof user.teams)[number]["team"]["eventTypes"][number];
const mapEventType = (eventType: UserEventTypes & Partial<TeamEventTypeChildren>) => ({
...eventType,
safeDescription: markdownToSafeHTML(eventType.description),
users: !!eventType.hosts?.length ? eventType.hosts.map((host) => host.user) : eventType.users,
safeDescription: eventType?.description ? markdownToSafeHTML(eventType.description) : undefined,
users: !!eventType?.hosts?.length ? eventType?.hosts.map((host) => host.user) : eventType.users,
metadata: eventType.metadata ? EventTypeMetaDataSchema.parse(eventType.metadata) : undefined,
children: eventType.children,
});
const userEventTypes = user.eventTypes.map(mapEventType);