-
Notifications
You must be signed in to change notification settings - Fork 0
feat(layout): scheduling SignalR client, topbar notification panel, batch queued copy #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| export * from "./panel"; | ||
| export * from "./scheduling-hub"; |
This file contains hidden or 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,5 @@ | ||
| export { NotificationPanelMenu } from "./notification-panel-menu"; | ||
| export { | ||
| useNotificationPanelStore, | ||
| type NotificationPanelEntry, | ||
| } from "./notification-panel.store"; |
105 changes: 105 additions & 0 deletions
105
src/infra/theme/components/notifications/panel/notification-panel-menu.tsx
This file contains hidden or 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,105 @@ | ||
| /** | ||
| * Bell + menu listing notification history from $app.notifications (via notification-panel store). | ||
| */ | ||
|
|
||
| import { | ||
| ActionIcon, | ||
| Indicator, | ||
| Menu, | ||
| ScrollArea, | ||
| Stack, | ||
| Text, | ||
| } from "@mantine/core"; | ||
| import { FaBell } from "react-icons/fa"; | ||
| import { useNotificationPanelStore } from "./notification-panel.store"; | ||
|
|
||
| function typeColor(type: string): string | undefined { | ||
| switch (type) { | ||
| case "success": | ||
| return "green"; | ||
| case "error": | ||
| return "red"; | ||
| case "warning": | ||
| return "yellow"; | ||
| case "info": | ||
| return "blue"; | ||
| default: | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| export function NotificationPanelMenu() { | ||
| const entries = useNotificationPanelStore((s) => s.entries); | ||
| const removeEntry = useNotificationPanelStore((s) => s.removeEntry); | ||
| const clearEntries = useNotificationPanelStore((s) => s.clearEntries); | ||
|
|
||
| return ( | ||
| <Menu shadow="md" width={320} position="bottom-end"> | ||
| <Menu.Target> | ||
| <Indicator | ||
| inline | ||
| disabled={entries.length === 0} | ||
| label={entries.length} | ||
| size={18} | ||
| > | ||
| <ActionIcon | ||
| variant="subtle" | ||
| aria-label="Notifications" | ||
| size="lg" | ||
| > | ||
| <FaBell size={20} /> | ||
| </ActionIcon> | ||
| </Indicator> | ||
| </Menu.Target> | ||
| <Menu.Dropdown> | ||
| <Menu.Label>Notifications</Menu.Label> | ||
| {entries.length === 0 ? ( | ||
| <Text size="sm" c="dimmed" px="sm" py="xs"> | ||
| No notifications yet | ||
| </Text> | ||
| ) : ( | ||
| <ScrollArea h={280}> | ||
| <Stack gap={4} p="xs"> | ||
| {entries.map((entry) => ( | ||
| <div key={entry.id}> | ||
| <Text | ||
| size="sm" | ||
| fw={500} | ||
| lineClamp={2} | ||
| c={typeColor(entry.type)} | ||
| > | ||
| {entry.title} | ||
| </Text> | ||
| {entry.message ? ( | ||
| <Text size="sm" lineClamp={4}> | ||
| {entry.message} | ||
| </Text> | ||
| ) : null} | ||
| <Text size="xs" c="dimmed"> | ||
| {new Date(entry.at).toLocaleString()} | ||
| </Text> | ||
| <Text | ||
| size="xs" | ||
| c="blue" | ||
|
noamarg marked this conversation as resolved.
Outdated
|
||
| style={{ cursor: "pointer" }} | ||
| onClick={() => removeEntry(entry.id)} | ||
| > | ||
| Dismiss | ||
| </Text> | ||
| </div> | ||
| ))} | ||
| </Stack> | ||
| </ScrollArea> | ||
| )} | ||
| {entries.length > 0 ? ( | ||
| <> | ||
| <Menu.Divider /> | ||
| <Menu.Item onClick={clearEntries}> | ||
| Clear history | ||
| </Menu.Item> | ||
| </> | ||
| ) : null} | ||
| </Menu.Dropdown> | ||
| </Menu> | ||
| ); | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/infra/theme/components/notifications/panel/notification-panel.store.ts
This file contains hidden or 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,34 @@ | ||
| import { create } from "zustand"; | ||
| import type { NotificationType } from "@/infra/service/notification/notification.types"; | ||
|
|
||
| export interface NotificationPanelEntry { | ||
| id: string; | ||
| title: string; | ||
| message?: string; | ||
| type: NotificationType; | ||
| at: number; | ||
| } | ||
|
|
||
| interface NotificationPanelStore { | ||
| entries: NotificationPanelEntry[]; | ||
| addEntry: (entry: NotificationPanelEntry) => void; | ||
| removeEntry: (id: string) => void; | ||
| clearEntries: () => void; | ||
| } | ||
|
|
||
| const maxEntries = 50; | ||
|
|
||
| export const useNotificationPanelStore = create<NotificationPanelStore>( | ||
| (set) => ({ | ||
| entries: [], | ||
| addEntry: (entry) => | ||
| set((s) => ({ | ||
| entries: [entry, ...s.entries].slice(0, maxEntries), | ||
| })), | ||
| removeEntry: (id) => | ||
| set((s) => ({ | ||
| entries: s.entries.filter((e) => e.id !== id), | ||
| })), | ||
| clearEntries: () => set({ entries: [] }), | ||
| }), | ||
| ); |
26 changes: 26 additions & 0 deletions
26
src/infra/theme/components/notifications/scheduling-hub/create-scheduling-hub-connection.ts
This file contains hidden or 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,26 @@ | ||
| import * as signalR from "@microsoft/signalr"; | ||
| import { tokenService } from "@/infra/service/ajax/token.service"; | ||
| import type { SchedulingCompletedPayload } from "./scheduling-hub.types"; | ||
|
|
||
| function apiBaseUrl(): string { | ||
| return ( | ||
| window.__ENV__?.VITE_API_BASE_URL || | ||
| import.meta.env.VITE_API_BASE_URL || | ||
| "http://localhost:5000/" | ||
| ); | ||
| } | ||
|
aaron-iz marked this conversation as resolved.
Outdated
|
||
|
|
||
| export function createSchedulingHubConnection( | ||
| onCompleted: (payload: SchedulingCompletedPayload) => void, | ||
| ): signalR.HubConnection { | ||
| const base = apiBaseUrl().replace(/\/$/, ""); | ||
| const conn = new signalR.HubConnectionBuilder() | ||
| .withUrl(`${base}/hubs/scheduling`, { | ||
|
aaron-iz marked this conversation as resolved.
Outdated
|
||
| accessTokenFactory: () => tokenService.getToken() ?? "", | ||
| }) | ||
| .withAutomaticReconnect() | ||
| .build(); | ||
|
|
||
| conn.on("SchedulingCompleted", onCompleted); | ||
| return conn; | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
src/infra/theme/components/notifications/scheduling-hub/index.ts
This file contains hidden or 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,4 @@ | ||
| export { SchedulingHubConnector } from "./scheduling-hub-connector"; | ||
| export { useSchedulingHubConnection } from "./use-scheduling-hub-connection"; | ||
| export { createSchedulingHubConnection } from "./create-scheduling-hub-connection"; | ||
| export type { SchedulingCompletedPayload } from "./scheduling-hub.types"; |
9 changes: 9 additions & 0 deletions
9
src/infra/theme/components/notifications/scheduling-hub/scheduling-hub-connector.tsx
This file contains hidden or 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,9 @@ | ||
| import { useSchedulingHubConnection } from "./use-scheduling-hub-connection"; | ||
|
|
||
| /** | ||
| * Renders nothing; mounts the scheduling SignalR subscription for authenticated layout shells. | ||
| */ | ||
| export function SchedulingHubConnector() { | ||
| useSchedulingHubConnection(); | ||
| return null; | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/infra/theme/components/notifications/scheduling-hub/scheduling-hub.types.ts
This file contains hidden or 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,8 @@ | ||
| export interface SchedulingCompletedPayload { | ||
| requestId: string; | ||
| success: boolean; | ||
| assignmentsCreated: number; | ||
| assignmentsModified: number; | ||
| unscheduledActivityIds: string[]; | ||
| failureReason: string | null; | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/infra/theme/components/notifications/scheduling-hub/use-scheduling-hub-connection.ts
This file contains hidden or 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,43 @@ | ||
| import { useEffect } from "react"; | ||
| import { $app } from "@/infra/service"; | ||
| import { createSchedulingHubConnection } from "./create-scheduling-hub-connection"; | ||
| import type { SchedulingCompletedPayload } from "./scheduling-hub.types"; | ||
|
|
||
| function schedulingSummary(payload: SchedulingCompletedPayload): string { | ||
| if (!payload.success) { | ||
| return payload.failureReason ?? "Scheduling failed"; | ||
| } | ||
| let s = `Assignments created: ${payload.assignmentsCreated}, modified: ${payload.assignmentsModified}`; | ||
| if (payload.unscheduledActivityIds?.length) { | ||
| s += `. Could not schedule ${payload.unscheduledActivityIds.length} activities.`; | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| /** | ||
| * Subscribes to scheduling completion events and surfaces them through | ||
| * {@link $app.notifications} (toasts + top bar history). | ||
| */ | ||
| export function useSchedulingHubConnection(): void { | ||
| useEffect(() => { | ||
| const conn = createSchedulingHubConnection((payload) => { | ||
| const summary = schedulingSummary(payload); | ||
| if (payload.success) { | ||
| $app.notifications.showSuccess("Scheduling complete", summary); | ||
| } else { | ||
| $app.notifications.showError( | ||
| "Scheduling failed", | ||
| payload.failureReason ?? summary, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| void conn.start().catch((err) => { | ||
| console.error("[scheduling hub]", err); | ||
| }); | ||
|
|
||
| return () => { | ||
| void conn.stop(); | ||
| }; | ||
| }, []); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.