Skip to content

Commit

Permalink
feat: update userId handling in IncidentFeed and AlertFeed services; …
Browse files Browse the repository at this point in the history
…increase LIMIT_PER_PROJECT to 10000; refactor User class to UserUtil; add IncidentFeedElement component
  • Loading branch information
simlarsen committed Jan 13, 2025
1 parent caa4103 commit 52c35c1
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 272 deletions.
3 changes: 1 addition & 2 deletions Common/Server/Services/AlertFeedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export class Service extends DatabaseService<Model> {
data.displayColor = Blue500;
}


if(data.userId) {
if (data.userId) {
alertFeed.userId = data.userId;
}

Expand Down
2 changes: 1 addition & 1 deletion Common/Server/Services/IncidentFeedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Service extends DatabaseService<Model> {
incidentFeed.incidentFeedEventType = data.incidentFeedEventType;
incidentFeed.projectId = data.projectId;

if(data.userId) {
if (data.userId) {
incidentFeed.userId = data.userId;
}

Expand Down
25 changes: 4 additions & 21 deletions Common/Server/Services/IncidentInternalNoteService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import User from "../../Models/DatabaseModels/User";
import ObjectID from "../../Types/ObjectID";
import DatabaseService from "./DatabaseService";
import Model from "Common/Models/DatabaseModels/IncidentInternalNote";
import UserService from "./UserService";
import { OnCreate } from "../Types/Database/Hooks";
import IncidentFeedService from "./IncidentFeedService";
import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed";
Expand All @@ -19,31 +17,16 @@ export class Service extends DatabaseService<Model> {
): Promise<Model> {
const userId: ObjectID | null | undefined =
createdItem.createdByUserId || createdItem.createdByUser?.id;
let userName: string | null = null;

if (userId) {
const user: User | null = await UserService.findOneById({
id: userId,
select: {
name: true,
email: true,
},
props: {
isRoot: true,
},
});

if (user && user.name && user.name.toString()) {
userName = user.name.toString();
}
}


await IncidentFeedService.createIncidentFeed({
incidentId: createdItem.id!,
projectId: createdItem.projectId!,
incidentFeedEventType: IncidentFeedEventType.PrivateNote,
displayColor: Blue500,
feedInfoInMarkdown: `**Private (Internal) Note Posted${userName ? " by " + userName.toString() : ""}**
userId: userId || undefined,

feedInfoInMarkdown: `**Posted Internal Note**
${createdItem.note}
`,
Expand Down
23 changes: 2 additions & 21 deletions Common/Server/Services/IncidentPublicNoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import IncidentFeedService from "./IncidentFeedService";
import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed";
import { Blue500 } from "../../Types/BrandColors";
import ObjectID from "../../Types/ObjectID";
import User from "../../Models/DatabaseModels/User";
import UserService from "./UserService";

export class Service extends DatabaseService<Model> {
public constructor() {
Expand All @@ -34,31 +32,14 @@ export class Service extends DatabaseService<Model> {
): Promise<Model> {
const userId: ObjectID | null | undefined =
createdItem.createdByUserId || createdItem.createdByUser?.id;
let userName: string | null = null;

if (userId) {
const user: User | null = await UserService.findOneById({
id: userId,
select: {
name: true,
email: true,
},
props: {
isRoot: true,
},
});

if (user && user.name) {
userName = user.name.toString();
}
}

await IncidentFeedService.createIncidentFeed({
incidentId: createdItem.id!,
projectId: createdItem.projectId!,
incidentFeedEventType: IncidentFeedEventType.PublicNote,
displayColor: Blue500,
feedInfoInMarkdown: `**Note Posted on Status Page${userName ? " by " + userName.toString() : ""}**
userId: userId || undefined,
feedInfoInMarkdown: `**Posted Public Note on Status Page**
${createdItem.note}
`,
Expand Down
2 changes: 1 addition & 1 deletion Common/Types/Database/LimitMax.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const LIMIT_MAX: number = 10000;
export const LIMIT_PER_PROJECT: number = 1000;
export const LIMIT_PER_PROJECT: number = 10000;
export const LIMIT_INFINITY: number = 999999999;
export const DEFAULT_LIMIT: number = 10;
export default LIMIT_MAX;
223 changes: 10 additions & 213 deletions Common/UI/Components/Feed/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,226 +1,23 @@
import React, { FunctionComponent, ReactElement } from "react";
import FeedItem, {ComponentProps as FeedItemProps} from "./FeedItem";

export interface ComponentProps {
id: string;
items: Array<FeedItemProps>;
}

const Feed: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
return (
<div className="flow-root" id={props.id}>
<div className="flow-root">
<ul role="list" className="-mb-8">
<li>
<div className="relative pb-8">
<span
className="absolute left-5 top-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
<div className="relative flex items-start space-x-3">
<div className="relative">
<img
className="flex size-10 items-center justify-center rounded-full bg-gray-400 ring-8 ring-white"
src="https://images.unsplash.com/photo-1520785643438-5bf77931f493?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80"
alt=""
/>

<span className="absolute -bottom-0.5 -right-1 rounded-tl bg-white px-0.5 py-px">
<svg
className="size-5 text-gray-400"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
data-slot="icon"
>
<path
fillRule="evenodd"
d="M10 2c-2.236 0-4.43.18-6.57.524C1.993 2.755 1 4.014 1 5.426v5.148c0 1.413.993 2.67 2.43 2.902.848.137 1.705.248 2.57.331v3.443a.75.75 0 0 0 1.28.53l3.58-3.579a.78.78 0 0 1 .527-.224 41.202 41.202 0 0 0 5.183-.5c1.437-.232 2.43-1.49 2.43-2.903V5.426c0-1.413-.993-2.67-2.43-2.902A41.289 41.289 0 0 0 10 2Zm0 7a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM8 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm5 1a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
clipRule="evenodd"
/>
</svg>
</span>
</div>
<div className="min-w-0 flex-1">
<div>
<div className="text-sm">
<a href="#" className="font-medium text-gray-900">
Eduardo Benz
</a>
</div>
<p className="mt-0.5 text-sm text-gray-500">
Commented 6d ago
</p>
</div>
<div className="mt-2 text-sm text-gray-700">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Tincidunt nunc ipsum tempor purus vitae id. Morbi in
vestibulum nec varius. Et diam cursus quis sed purus nam.
</p>
</div>
</div>
</div>
</div>
</li>
<li>
<div className="relative pb-8">
<span
className="absolute left-5 top-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
<div className="relative flex items-start space-x-3">
<div>
<div className="relative px-1">
<div className="flex size-8 items-center justify-center rounded-full bg-gray-100 ring-8 ring-white">
<svg
className="size-5 text-gray-500"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
data-slot="icon"
>
<path
fillRule="evenodd"
d="M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0Zm-5.5-2.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0ZM10 12a5.99 5.99 0 0 0-4.793 2.39A6.483 6.483 0 0 0 10 16.5a6.483 6.483 0 0 0 4.793-2.11A5.99 5.99 0 0 0 10 12Z"
clipRule="evenodd"
/>
</svg>
</div>
</div>
</div>
<div className="min-w-0 flex-1 py-1.5">
<div className="text-sm text-gray-500">
<a href="#" className="font-medium text-gray-900">
Hilary Mahy
</a>
assigned
<a href="#" className="font-medium text-gray-900">
Kristin Watson
</a>
<span className="whitespace-nowrap">2d ago</span>
</div>
</div>
</div>
</div>
</li>
<li>
<div className="relative pb-8">
<span
className="absolute left-5 top-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
<div className="relative flex items-start space-x-3">
<div>
<div className="relative px-1">
<div className="flex size-8 items-center justify-center rounded-full bg-gray-100 ring-8 ring-white">
<svg
className="size-5 text-gray-500"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
data-slot="icon"
>
<path
fillRule="evenodd"
d="M4.5 2A2.5 2.5 0 0 0 2 4.5v3.879a2.5 2.5 0 0 0 .732 1.767l7.5 7.5a2.5 2.5 0 0 0 3.536 0l3.878-3.878a2.5 2.5 0 0 0 0-3.536l-7.5-7.5A2.5 2.5 0 0 0 8.38 2H4.5ZM5 6a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
clipRule="evenodd"
/>
</svg>
</div>
</div>
</div>
<div className="min-w-0 flex-1 py-0">
<div className="text-sm/8 text-gray-500">
<span className="mr-0.5">
<a href="#" className="font-medium text-gray-900">
Hilary Mahy
</a>
added tags
</span>
<span className="mr-0.5">
<a
href="#"
className="inline-flex items-center gap-x-1.5 rounded-full px-2 py-1 text-xs font-medium text-gray-900 ring-1 ring-inset ring-gray-200"
>
<svg
className="size-1.5 fill-red-500"
viewBox="0 0 6 6"
aria-hidden="true"
>
<circle cx="3" cy="3" r="3" />
</svg>
Bug
</a>
<a
href="#"
className="inline-flex items-center gap-x-1.5 rounded-full px-2 py-1 text-xs font-medium text-gray-900 ring-1 ring-inset ring-gray-200"
>
<svg
className="size-1.5 fill-indigo-500"
viewBox="0 0 6 6"
aria-hidden="true"
>
<circle cx="3" cy="3" r="3" />
</svg>
Accessibility
</a>
</span>
<span className="whitespace-nowrap">6h ago</span>
</div>
</div>
</div>
</div>
</li>
<li>
<div className="relative pb-8">
<div className="relative flex items-start space-x-3">
<div className="relative">
<img
className="flex size-10 items-center justify-center rounded-full bg-gray-400 ring-8 ring-white"
src="https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80"
alt=""
/>

<span className="absolute -bottom-0.5 -right-1 rounded-tl bg-white px-0.5 py-px">
<svg
className="size-5 text-gray-400"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
data-slot="icon"
>
<path
fillRule="evenodd"
d="M10 2c-2.236 0-4.43.18-6.57.524C1.993 2.755 1 4.014 1 5.426v5.148c0 1.413.993 2.67 2.43 2.902.848.137 1.705.248 2.57.331v3.443a.75.75 0 0 0 1.28.53l3.58-3.579a.78.78 0 0 1 .527-.224 41.202 41.202 0 0 0 5.183-.5c1.437-.232 2.43-1.49 2.43-2.903V5.426c0-1.413-.993-2.67-2.43-2.902A41.289 41.289 0 0 0 10 2Zm0 7a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM8 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm5 1a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
clipRule="evenodd"
/>
</svg>
</span>
</div>
<div className="min-w-0 flex-1">
<div>
<div className="text-sm">
<a href="#" className="font-medium text-gray-900">
Jason Meyers
</a>
</div>
<p className="mt-0.5 text-sm text-gray-500">
Commented 2h ago
</p>
</div>
<div className="mt-2 text-sm text-gray-700">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Tincidunt nunc ipsum tempor purus vitae id. Morbi in
vestibulum nec varius. Et diam cursus quis sed purus nam.
Scelerisque amet elit non sit ut tincidunt condimentum. Nisl
ultrices eu venenatis diam.
</p>
</div>
</div>
</div>
</div>
</li>
{props.items.map((item: FeedItemProps) => {
return (
<FeedItem
{...item}
/>
);
})}
</ul>
</div>
);
Expand Down
Loading

0 comments on commit 52c35c1

Please sign in to comment.