-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: use server-side rendering for incident list
- Loading branch information
Showing
12 changed files
with
146 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ pids | |
*.pid | ||
*.seed | ||
|
||
!lib | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { PaginatedIncidentsDto } from "@/app/incidents/models"; | ||
import { fetcher } from "@/utils/fetcher"; | ||
import { Session } from "next-auth"; | ||
|
||
interface Filters { | ||
status: string[]; | ||
severity: string[]; | ||
assignees: string[]; | ||
sources: string[]; | ||
affected_services: string[]; | ||
} | ||
|
||
export type GetIncidentsParams = { | ||
confirmed: boolean; | ||
limit: number; | ||
offset: number; | ||
sorting: { id: string; desc: boolean }; | ||
filters: Filters | {}; | ||
}; | ||
|
||
export function buildIncidentsUrl(apiUrl: string, params: GetIncidentsParams) { | ||
const filtersParams = new URLSearchParams(); | ||
|
||
Object.entries(params.filters).forEach(([key, value]) => { | ||
if (value.length == 0) { | ||
filtersParams.delete(key as string); | ||
} else { | ||
value.forEach((s: string) => { | ||
filtersParams.append(key, s); | ||
}); | ||
} | ||
}); | ||
|
||
return `${apiUrl}/incidents?confirmed=${params.confirmed}&limit=${params.limit}&offset=${params.offset}&sorting=${ | ||
params.sorting.desc ? "-" : "" | ||
}${params.sorting.id}&${filtersParams.toString()}`; | ||
} | ||
|
||
export async function getIncidents( | ||
apiUrl: string, | ||
session: Session | null, | ||
params: GetIncidentsParams | ||
) { | ||
if (!session) { | ||
return null; | ||
} | ||
const url = buildIncidentsUrl(apiUrl, params); | ||
return (await fetcher( | ||
url, | ||
session.accessToken | ||
)) as Promise<PaginatedIncidentsDto>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Custom Error Class | ||
|
||
export class KeepApiError extends Error { | ||
url: string; | ||
proposedResolution: string; | ||
statusCode: number | undefined; | ||
|
||
constructor( | ||
message: string, | ||
url: string, | ||
proposedResolution: string, | ||
statusCode?: number | ||
) { | ||
super(message); | ||
this.name = "KeepApiError"; | ||
this.url = url; | ||
this.proposedResolution = proposedResolution; | ||
this.statusCode = statusCode; | ||
} | ||
|
||
toString() { | ||
return `${this.name}: ${this.message} - ${this.url} - ${this.proposedResolution} - ${this.statusCode}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters