1- import { computed , watchEffect } from "vue" ;
1+ import { computed } from "vue" ;
22import { CapabilityStatus , StatusIndicator } from "@/components/platformcapabilities/types" ;
33import useIsAllMessagesSupported , { minimumSCVersionForAllMessages } from "@/components/audit/isAllMessagesSupported" ;
44import { storeToRefs } from "pinia" ;
5- import { useAuditStore } from "@/stores/AuditStore" ;
6- import { MessageStatus } from "@/resources/Message" ;
7- import { type CapabilityComposable , useCapabilityBase } from "./BaseCapability" ;
8- import { useRemoteInstancesStore } from "@/stores/RemoteInstancesStore" ;
5+ import { type CapabilityComposable , type CapabilityStatusToStringMap , useCapabilityBase } from "./BaseCapability" ;
6+ import useRemoteInstancesAutoRefresh from "@/composables/useRemoteInstancesAutoRefresh" ;
7+ import useAuditStoreAutoRefresh from "@/composables/useAuditStoreAutoRefresh" ;
98import { RemoteInstanceStatus , type RemoteInstance } from "@/resources/RemoteInstance" ;
109
11- enum AuditingCardDescription {
12- NotConfigured = "Auditing instance is connected but no successful messages have been processed yet or you don't have auditing enabled for any endpoints." ,
13- Unavailable = "All Auditing instances are configured but not responding." ,
14- PartiallyUnavailable = "Some Auditing instances are not responding. Check individual instance status below." ,
15- NotSupported = `Auditing instance is connected but the "All Messages" feature requires ServiceControl ${ minimumSCVersionForAllMessages } or higher.` ,
16- Available = "Auditing is available and processing successful messages." ,
17- }
10+ const AuditingDescriptions : CapabilityStatusToStringMap = {
11+ [ CapabilityStatus . EndpointsNotConfigured ] :
12+ "A ServiceControl Auditing instance is connected but no successful messages have been processed yet or you don't have auditing enabled for any endpoints. Click 'Learn More' to find out how to set up auditing for your endpoints." ,
13+ [ CapabilityStatus . InstanceNotConfigured ] : "A ServiceControl Auditing instance has not been configured. Click 'Get Started' to learn more about setting up auditing." ,
14+ [ CapabilityStatus . Unavailable ] : "All ServiceControl Auditing instances are configured but not responding." ,
15+ [ CapabilityStatus . PartiallyUnavailable ] : "Some ServiceControl Auditing instances are not responding." ,
16+ [ CapabilityStatus . Available ] : "All ServiceControl Auditing instances are available and endpoints have been configured to send audit messages." ,
17+ } ;
18+
19+ const AuditingHelpButtonText : CapabilityStatusToStringMap = {
20+ [ CapabilityStatus . EndpointsNotConfigured ] : "Learn More" ,
21+ [ CapabilityStatus . InstanceNotConfigured ] : "Get Started" ,
22+ [ CapabilityStatus . Available ] : "View Messages" ,
23+ } ;
24+
25+ const AuditingHelpButtonUrl : CapabilityStatusToStringMap = {
26+ [ CapabilityStatus . EndpointsNotConfigured ] : "https://docs.particular.net/nservicebus/operations/auditing" ,
27+ [ CapabilityStatus . InstanceNotConfigured ] : "https://docs.particular.net/servicecontrol/audit-instances/" ,
28+ [ CapabilityStatus . Available ] : "#/messages" ,
29+ } ;
1830
1931enum AuditingIndicatorTooltip {
2032 InstanceAvailable = "Auditing instance is configured and available" ,
@@ -65,34 +77,26 @@ function hasPartiallyUnavailableAuditInstances(instances: RemoteInstance[] | nul
6577}
6678
6779export function useAuditingCapability ( ) : CapabilityComposable {
68- const { getIconForStatus, createIndicator } = useCapabilityBase ( ) ;
80+ const { getIconForStatus, getDescriptionForStatus , getHelpButtonTextForStatus , getHelpButtonUrlForStatus , createIndicator } = useCapabilityBase ( ) ;
6981
7082 // This gives us the list of remote instances configured in ServiceControl.
71- const remoteInstancesStore = useRemoteInstancesStore ( ) ;
83+ // Uses auto-refresh to periodically check status (every 5 seconds)
84+ const { store : remoteInstancesStore } = useRemoteInstancesAutoRefresh ( ) ;
7285 const { remoteInstances } = storeToRefs ( remoteInstancesStore ) ;
7386
74- // This gives us the messages array which includes all messages (successful and failed).
75- const auditStore = useAuditStore ( ) ;
76- const { messages } = storeToRefs ( auditStore ) ;
77- const successfulMessageCount = computed ( ( ) => {
78- return messages . value . filter ( ( msg ) => msg . status === MessageStatus . Successful || msg . status === MessageStatus . ResolvedSuccessfully ) . length ;
79- } ) ;
87+ // This gives us the hasSuccessfulMessages flag which indicates if any successful messages exist.
88+ // Uses auto-refresh (minimal) to periodically check for at least 1 successful message (every 5 seconds)
89+ const { store : auditStore } = useAuditStoreAutoRefresh ( ) ;
90+ const { hasSuccessfulMessages } = storeToRefs ( auditStore ) ;
8091
92+ // This tells us if the "All Messages" feature is supported by checking the SC version
8193 const isAllMessagesSupported = useIsAllMessagesSupported ( ) ;
8294
83- watchEffect ( ( ) => {
84- // Trigger initial load of audit messages if audit is configured
85- if ( hasAvailableAuditInstances ( remoteInstances . value ) ) {
86- // TODO: This is not auto refreshed. User will need to manually refresh the page to get updated data. Ideally this would auto refresh periodically.
87- auditStore . refresh ( ) ;
88- }
89- } ) ;
90-
9195 // Determine overall auditing status
9296 const auditStatus = computed ( ( ) => {
9397 // 1. Check if there are any audit instances configured.
9498 if ( ! remoteInstances . value || remoteInstances . value . length === 0 ) {
95- return CapabilityStatus . NotConfigured ;
99+ return CapabilityStatus . InstanceNotConfigured ;
96100 }
97101
98102 // 2. Check if all audit instances are unavailable
@@ -105,9 +109,9 @@ export function useAuditingCapability(): CapabilityComposable {
105109 return CapabilityStatus . PartiallyUnavailable ;
106110 }
107111
108- // 4. Check if all messages feature is supported and there are successful messages
109- if ( ! isAllMessagesSupported . value || successfulMessageCount . value === 0 ) {
110- return CapabilityStatus . NotConfigured ;
112+ // 4. Check if the 'All Messages' feature is not supported OR there are no successful messages
113+ if ( ! isAllMessagesSupported . value || ! hasSuccessfulMessages . value ) {
114+ return CapabilityStatus . EndpointsNotConfigured ;
111115 }
112116
113117 // 5. Audit instance is available and there are successful audit messages
@@ -118,22 +122,13 @@ export function useAuditingCapability(): CapabilityComposable {
118122 const auditIcon = computed ( ( ) => getIconForStatus ( auditStatus . value ) ) ;
119123
120124 // Determine description based on status
121- const auditDescription = computed ( ( ) => {
122- if ( auditStatus . value === CapabilityStatus . NotConfigured ) {
123- return AuditingCardDescription . NotConfigured ;
124- }
125+ const auditDescription = computed ( ( ) => getDescriptionForStatus ( auditStatus . value , AuditingDescriptions ) ) ;
125126
126- if ( auditStatus . value === CapabilityStatus . Available ) {
127- return AuditingCardDescription . Available ;
128- }
127+ // Determine help button text based on status
128+ const auditHelpButtonText = computed ( ( ) => getHelpButtonTextForStatus ( auditStatus . value , AuditingHelpButtonText ) ) ;
129129
130- if ( auditStatus . value === CapabilityStatus . PartiallyUnavailable ) {
131- return AuditingCardDescription . PartiallyUnavailable ;
132- }
133-
134- // Unavailable
135- return AuditingCardDescription . Unavailable ;
136- } ) ;
130+ // Determine help button URL based on status
131+ const auditHelpButtonUrl = computed ( ( ) => getHelpButtonUrlForStatus ( auditStatus . value , AuditingHelpButtonUrl ) ) ;
137132
138133 // Determine indicators
139134 const auditIndicators = computed ( ( ) => {
@@ -152,7 +147,7 @@ export function useAuditingCapability(): CapabilityComposable {
152147
153148 // Messages available indicator - show if at least one instance is available
154149 if ( hasAvailableAuditInstances ( remoteInstances . value ) ) {
155- const messagesAvailable = isAllMessagesSupported . value && successfulMessageCount . value > 0 ;
150+ const messagesAvailable = isAllMessagesSupported . value && hasSuccessfulMessages . value ;
156151
157152 let messageTooltip = "" ;
158153 if ( messagesAvailable ) {
@@ -163,7 +158,7 @@ export function useAuditingCapability(): CapabilityComposable {
163158 messageTooltip = AuditingIndicatorTooltip . MessagesUnavailable ;
164159 }
165160
166- indicators . push ( createIndicator ( "Messages" , messagesAvailable ? CapabilityStatus . Available : CapabilityStatus . NotConfigured , messageTooltip ) ) ;
161+ indicators . push ( createIndicator ( "Messages" , messagesAvailable ? CapabilityStatus . Available : CapabilityStatus . EndpointsNotConfigured , messageTooltip ) ) ;
167162 }
168163
169164 return indicators ;
@@ -178,5 +173,7 @@ export function useAuditingCapability(): CapabilityComposable {
178173 description : auditDescription ,
179174 indicators : auditIndicators ,
180175 isLoading,
176+ helpButtonText : auditHelpButtonText ,
177+ helpButtonUrl : auditHelpButtonUrl ,
181178 } ;
182179}
0 commit comments