Skip to content
Open
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
57 changes: 57 additions & 0 deletions packages/widgets/src/feedback/NotificationQueue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export type NotificationPriority = "low" | "medium" | "high";

export interface Notification {
id: string;
message: string;
priority?: NotificationPriority;
duration?: number;
}

export class NotificationQueue {
private queue: Notification[] = [];
private paused = false;

add(notification: Notification): void {
this.queue.push({
priority: "medium",
duration: 3000,
...notification,
});

this.queue.sort((a, b) => {
const order = {
high: 3,
medium: 2,
low: 1,
};

return order[b.priority!] - order[a.priority!];
});
}

getAll(): Notification[] {
return this.queue;
Comment on lines +32 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

getAll() exposes mutable internal state.

Line 33 returns the backing array directly, so callers can mutate queue contents/order and bypass add() invariants (priority defaults + sorting).

Proposed fix
-    getAll(): Notification[] {
-        return this.queue;
-    }
+    getAll(): ReadonlyArray<Notification> {
+        return [...this.queue];
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
getAll(): Notification[] {
return this.queue;
getAll(): ReadonlyArray<Notification> {
return [...this.queue];
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/feedback/NotificationQueue.ts` around lines 32 - 33, The
getAll() method in NotificationQueue exposes the mutable internal queue array
directly, allowing callers to modify it and bypass the add() method's invariants
like priority defaults and sorting. Fix this by returning a shallow copy of the
queue array instead of returning this.queue directly, using either the spread
operator or the slice() method to create a new array instance that callers can
modify without affecting the internal state.

}

remove(id: string): void {
this.queue = this.queue.filter(
item => item.id !== id
);
}

clear(): void {
this.queue = [];
}

pause(): void {
this.paused = true;
}

resume(): void {
this.paused = false;
}

isPaused(): boolean {
return this.paused;
}
}
7 changes: 7 additions & 0 deletions packages/widgets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ export type { DraggableOptions, DroppableOptions } from './layout/DragAndDrop.js
export { Fill } from './layout/Fill.js';
export type { FillOptions } from './layout/Fill.js';
export { SplitPane } from './layout/SplitPane.js';
export type { SplitPaneOptions } from './layout/SplitPane.js';
export { NotificationQueue } from "./feedback/NotificationQueue.js";

export type {
Notification,
NotificationPriority
} from "./feedback/NotificationQueue.js";
export type { SplitPaneOptions, SplitDirection } from './layout/SplitPane.js';
Comment on lines +132 to 139

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify duplicate SplitPaneOptions type exports in the index module
rg -n "export type \{[^}]*SplitPaneOptions" packages/widgets/src/index.ts

Repository: Karanjot786/TermUI

Length of output: 212


🏁 Script executed:

sed -n '130,141p' packages/widgets/src/index.ts

Repository: Karanjot786/TermUI

Length of output: 536


🏁 Script executed:

# Check for any other duplicate exports in the file
rg "^export (type )?\{ [^}]*\}" packages/widgets/src/index.ts | sort | uniq -d

Repository: Karanjot786/TermUI

Length of output: 44


Remove duplicate SplitPaneOptions type export.

SplitPaneOptions is exported on line 132 and again on line 139. TypeScript will error on the duplicate identifier. Keep the export on line 132 and remove it from line 139.

Fix
 export { SplitPane } from './layout/SplitPane.js';
 export type { SplitPaneOptions } from './layout/SplitPane.js';
 export { NotificationQueue } from "./feedback/NotificationQueue.js";

 export type {
     Notification,
     NotificationPriority
 } from "./feedback/NotificationQueue.js";
-export type { SplitPaneOptions, SplitDirection } from './layout/SplitPane.js';
+export type { SplitDirection } from './layout/SplitPane.js';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export type { SplitPaneOptions } from './layout/SplitPane.js';
export { NotificationQueue } from "./feedback/NotificationQueue.js";
export type {
Notification,
NotificationPriority
} from "./feedback/NotificationQueue.js";
export type { SplitPaneOptions, SplitDirection } from './layout/SplitPane.js';
export type { SplitPaneOptions } from './layout/SplitPane.js';
export { NotificationQueue } from "./feedback/NotificationQueue.js";
export type {
Notification,
NotificationPriority
} from "./feedback/NotificationQueue.js";
export type { SplitDirection } from './layout/SplitPane.js';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/index.ts` around lines 132 - 139, The `SplitPaneOptions`
type is being exported twice from the same source file './layout/SplitPane.js'.
Remove `SplitPaneOptions` from the second export statement (the one that also
exports `SplitDirection`) and keep only `SplitDirection` in that second export.
The first export of `SplitPaneOptions` on line 132 should remain unchanged.


// ── Feedback Widgets ──────────────────────────────────
Expand Down
Loading