Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Nov 26, 2024
1 parent 1936458 commit e2523a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 59 deletions.
11 changes: 0 additions & 11 deletions keep-ui/app/(keep)/alerts/alert-table-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ const invertedSeverityMapping = Object.entries(severityMapping).reduce<{
return acc;
}, {});

const customSeveritySortFn = (rowA: any, rowB: any) => {
// Adjust the way to access severity values according to your data structure
const severityValueA = rowA.original?.severity; // or rowA.severity;
const severityValueB = rowB.original?.severity; // or rowB.severity;

// Use the inverted mapping to get ranks
const rankA = invertedSeverityMapping[severityValueA] || 0;
const rankB = invertedSeverityMapping[severityValueB] || 0;

return rankA > rankB ? 1 : rankA < rankB ? -1 : 0;
};
interface GenerateAlertTableColsArg {
additionalColsToGenerate?: string[];
isCheckboxDisplayed?: boolean;
Expand Down
43 changes: 12 additions & 31 deletions keep-ui/app/(keep)/incidents/[id]/timeline/incident-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,32 +261,6 @@ const IncidentTimelineNoAlerts: React.FC = () => {
);
};

const SeverityLegend: React.FC<{ alerts: AlertDto[] }> = ({ alerts }) => {
const severityCounts = alerts.reduce(
(acc, alert) => {
acc[alert.severity!] = (acc[alert.severity!] || 0) + 1;
return acc;
},
{} as Record<string, number>
);

return (
<div className="flex flex-col gap-2 p-4">
{Object.entries(severityCounts).map(([severity, count]) => (
<div key={severity} className="flex items-center gap-2">
<div
className={`w-4 h-4 rounded-full ${
severityColors[severity as keyof typeof severityColors]
}`}
/>
<span className="capitalize">{severity}</span>
<span className="text-gray-500">({count})</span>
</div>
))}
</div>
);
};

export default function IncidentTimeline({
incident,
}: {
Expand Down Expand Up @@ -339,15 +313,18 @@ export default function IncidentTimeline({
let formatString: string;

// Determine scale and format based on total duration
const durationInDays = differenceInDays(paddedEndTime, startTime);
const durationInDays = Math.ceil(totalDuration / (1000 * 60 * 60 * 24)); // Calculate days including partial days
const durationInHours = differenceInHours(paddedEndTime, startTime);
const durationInMinutes = differenceInMinutes(paddedEndTime, startTime);
console.log(
`Duration in days: ${durationInDays}, duration in hours: ${durationInHours}, duration in minutes: ${durationInMinutes}`
);

if (durationInDays > 3) {
if (durationInDays >= 1) {
timeScale = "days";
formatString = "MMM dd";
intervalCount = Math.min(durationInDays + 1, 12);
} else if (durationInHours > 24) {
} else if (12 < durationInHours && durationInHours < 23) {
timeScale = "hours";
formatString = "MMM dd HH:mm";
intervalCount = Math.min(Math.ceil(durationInHours / 2), 12);
Expand Down Expand Up @@ -472,8 +449,12 @@ export default function IncidentTimeline({
{/* Time labels - Now sticky at bottom */}
<div className="sticky bottom-0 bg-white border-t">
<div
className="relative"
style={{ height: "50px", paddingLeft: "40px" }}
className="relative overflow-hidden"
style={{
height: "50px",
paddingLeft: "40px",
paddingRight: "40px",
}}
>
{intervals.map((time, index) => (
<div
Expand Down
36 changes: 19 additions & 17 deletions keep-ui/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,32 @@ if (authType === AuthType.AZUREAD && proxyUrl) {

// Override profile since it uses fetch without customFetch
provider.profile = async (profile, tokens) => {
const profilePhotoSize = 48;
console.log("Fetching profile photo via proxy");
// @tb: this causes 431 Request Header Fields Too Large
// const profilePhotoSize = 48;
// console.log("Fetching profile photo via proxy");

const response = await proxyFetch(
`https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
{ headers: { Authorization: `Bearer ${tokens.access_token}` } }
);
// const response = await proxyFetch(
// `https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
// { headers: { Authorization: `Bearer ${tokens.access_token}` } }
// );

let image: string | null = null;
if (response.ok && typeof Buffer !== "undefined") {
try {
const pictureBuffer = await response.arrayBuffer();
const pictureBase64 = Buffer.from(pictureBuffer).toString("base64");
image = `data:image/jpeg;base64,${pictureBase64}`;
} catch (error) {
console.error("Error processing profile photo:", error);
}
}
// let image: string | null = null;
// if (response.ok && typeof Buffer !== "undefined") {
// try {
// const pictureBuffer = await response.arrayBuffer();
// const pictureBase64 = Buffer.from(pictureBuffer).toString("base64");
// image = `data:image/jpeg;base64,${pictureBase64}`;
// } catch (error) {
// console.error("Error processing profile photo:", error);
// }
// }
// https://stackoverflow.com/questions/77686104/how-to-resolve-http-error-431-nextjs-next-auth

return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: image ?? null,
image: null,
accessToken: tokens.access_token ?? "",
};
};
Expand Down

0 comments on commit e2523a0

Please sign in to comment.