Skip to content

Commit 2e13ac8

Browse files
committed
Corrected a bug where the incident list was not updated properly (when going from the search page)
1 parent 7451d97 commit 2e13ac8

File tree

5 files changed

+94
-57
lines changed

5 files changed

+94
-57
lines changed

src/Server/Coderr.Server.Web/ClientApp/components/analyze/home/home.vue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="col">
55
<h1>Analyze</h1>
66
<p class="lead">This section allows you to analyze the incidents that you have decided to work with.</p>
7-
<p class="lead">But since you have not reported any errors yet, there is nothing to see here..</p>
7+
<p class="lead">To see incidents here, go to "Discover" and assign one or more incidents to yourself.</p>
88
<a href="https://coderr.io/documentation/features/analyze/" target="documentation" class="btn btn-primary">Learn more about this feature</a>
99
<a href="https://coderr.io/documentation" target="documentation" class="btn btn-primary">Read the reporting error guide</a>
1010
</div>

src/Server/Coderr.Server.Web/ClientApp/components/analyze/menu.ts

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface IRouteNavigation {
88
url: string;
99
setMenu(name: String): void;
1010
}
11+
1112
type NavigationCallback = (context: IRouteNavigation) => void;
1213

1314
@Component
@@ -20,14 +21,7 @@ export default class AnalyzeMenuComponent extends Vue {
2021

2122
created() {
2223
MyIncidents.Instance.subscribeOnSelectedIncident(this.onIncidentSelected);
23-
MyIncidents.Instance.subscribeOnListChanges(x => {
24-
this.incidents = MyIncidents.Instance.myIncidents;
25-
if (!this.incidentId && this.incidents.length > 0) {
26-
this.incidentId = this.incidents[0].incidentId;
27-
MyIncidents.Instance.switchIncident(this.incidentId);
28-
this.$router.push({ name: 'analyzeIncident', params: { incidentId: this.incidentId.toString() } });
29-
}
30-
});
24+
MyIncidents.Instance.subscribeOnListChanges(this.onListChanged);
3125
MyIncidents.Instance.ready()
3226
.then(x => {
3327
this.incidents = MyIncidents.Instance.myIncidents;
@@ -39,6 +33,38 @@ export default class AnalyzeMenuComponent extends Vue {
3933
}
4034
}
4135

36+
mounted() {
37+
MyIncidents.Instance.ready().then(() => {
38+
if (!this.$route.params.incidentId) {
39+
if (MyIncidents.Instance.myIncidents.length === 0) {
40+
return;
41+
}
42+
43+
var incident = MyIncidents.Instance.myIncidents[0];
44+
this.$router.push({ name: 'analyzeIncident', params: { incidentId: incident.incidentId.toString() } });
45+
return;
46+
}
47+
48+
if (this.incidentId) {
49+
MyIncidents.Instance.switchIncident(this.incidentId);
50+
}
51+
});
52+
}
53+
54+
destroyed() {
55+
MyIncidents.Instance.unsubscribe(this.onIncidentSelected);
56+
MyIncidents.Instance.unsubscribe(this.onListChanged);
57+
}
58+
59+
private onListChanged() {
60+
this.incidents = MyIncidents.Instance.myIncidents;
61+
if (!this.incidentId && this.incidents.length > 0) {
62+
this.incidentId = this.incidents[0].incidentId;
63+
MyIncidents.Instance.switchIncident(this.incidentId);
64+
this.$router.push({ name: 'analyzeIncident', params: { incidentId: this.incidentId.toString() } });
65+
}
66+
}
67+
4268
private onIncidentSelected(incident: IMyIncident | null) {
4369
if (incident == null) {
4470
this.title = '(Select an incident)';
@@ -60,31 +86,18 @@ export default class AnalyzeMenuComponent extends Vue {
6086
if (this.$route.fullPath.indexOf('/analyze/') === -1) {
6187
return;
6288
}
63-
64-
var newIncidentId = parseInt(value, 10);
65-
66-
//ignore subroutes to same incident.
67-
if (this.incidentId === newIncidentId) {
89+
if (!value) {
90+
this.incidentId = null;
6891
return;
69-
}
70-
71-
this.incidentId = newIncidentId;
72-
MyIncidents.Instance.switchIncident(newIncidentId);
73-
}
74-
75-
mounted() {
76-
MyIncidents.Instance.ready().then(() => {
77-
if (!this.$route.params.incidentId) {
78-
if (MyIncidents.Instance.myIncidents.length === 0) {
79-
return;
80-
}
81-
82-
var incident = MyIncidents.Instance.myIncidents[0];
83-
this.$router.push({ name: 'analyzeIncident', params: { incidentId: incident.incidentId.toString() } });
92+
} else {
93+
var newIncidentId = parseInt(value, 10);
94+
if (this.incidentId === newIncidentId) {
8495
return;
8596
}
97+
this.incidentId = newIncidentId;
98+
}
8699

87-
MyIncidents.Instance.switchIncident(this.incidentId);
88-
});
100+
MyIncidents.Instance.switchIncident(this.incidentId);
89101
}
90-
}
102+
103+
}

src/Server/Coderr.Server.Web/ClientApp/components/analyze/myincidents.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export class MyIncidents {
3333
public static Instance = new MyIncidents();
3434
private allMyIncidents$: IMyIncident[] = [];
3535
private selectedCallbacks$: incidentSelectedCallback[] = [];
36-
private changedCallbacks$: incidentListChanged[] = [];
36+
private listChangedCallback$: incidentListChanged[] = [];
3737
private loadPromise$: Promise<any>;
38-
38+
3939
myIncidents: IMyIncident[] = [];
4040
selectedIncident: IMyIncident | null;
4141
menuTitle = '';
@@ -71,6 +71,7 @@ export class MyIncidents {
7171
*/
7272
async switchApplication(applicationId: number) {
7373
await this.loadPromise$;
74+
7475
if (applicationId === 0) {
7576
this.selectedApplicationId = null;
7677
} else {
@@ -90,7 +91,10 @@ export class MyIncidents {
9091
}
9192

9293
async switchIncident(incidentId: number) {
93-
await this.loadPromise$;
94+
if (this.loadPromise$) {
95+
await this.loadPromise$;
96+
}
97+
9498
var incident = await this.getIncident(incidentId);
9599
if (incident == null) {
96100
this.getNextIncident();
@@ -116,10 +120,16 @@ export class MyIncidents {
116120
* @returns The incident that was selected when the subscribe method was invoked (null if none was selected)
117121
*/
118122
public subscribeOnListChanges(callback: incidentListChanged): IMyIncident {
119-
this.changedCallbacks$.push(callback);
123+
this.listChangedCallback$.push(callback);
120124
return this.selectedIncident;
121125
}
122126

127+
unsubscribe(callback: any) {
128+
this.selectedCallbacks$ = this.selectedCallbacks$.filter(x => x !== callback);
129+
this.listChangedCallback$ = this.listChangedCallback$.filter(x => x !== callback);
130+
}
131+
132+
123133
private onIncidentAssigned(msgContext: MessageContext) {
124134
var msg = <IncidentAssigned>msgContext.message.body;
125135
AppRoot.Instance.incidentService.get(msg.incidentId)
@@ -140,7 +150,7 @@ export class MyIncidents {
140150
}
141151

142152
private triggerIncidentListCallbacks(incidentId?: number, added?: boolean) {
143-
this.changedCallbacks$.forEach(x => {
153+
this.listChangedCallback$.forEach(x => {
144154
x({ incidentId, added });
145155
});
146156
}
@@ -155,15 +165,12 @@ export class MyIncidents {
155165
if (mine.length === 0) {
156166
return;
157167
}
158-
159168
mine.forEach(dto => {
160169
if (!this.allMyIncidents$.find(item => item.incidentId === dto.Id)) {
161170
var item = this.createItem(dto.Id, parseInt(dto.ApplicationId, 10), dto.Name);
162171
this.allMyIncidents$.push(item);
163172
}
164173
});
165-
166-
this.filterMyIncidents();
167174
}
168175

169176
private filterMyIncidents() {

src/Server/Coderr.Server.Web/ClientApp/components/home/navmenu/navmenu.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class NavMenuComponent extends Vue {
2828
isDiscoverActive: boolean = true;
2929
isAnalyzeActive: boolean = false;
3030
isDeploymentActive: boolean = false;
31-
31+
lastPublishedId$ = 0;
3232
onboarding: boolean = false;
3333

3434
discoverLink: string = '/discover/';
@@ -113,10 +113,10 @@ export default class NavMenuComponent extends Vue {
113113
if (paramCount === 1 && currentRoute.params.hasOwnProperty('applicationId')) {
114114
if (applicationId == null) {
115115
this.$router.push({ name: currentRoute.name });
116-
PubSubService.Instance.publish(MenuApi.MessagingTopics.ApplicationChanged, { applicationId: null });
116+
this.publishApplicationChanged(null);
117117
} else {
118118
this.$router.push({ name: currentRoute.name, params: { applicationId: applicationId.toString() } });
119-
PubSubService.Instance.publish(MenuApi.MessagingTopics.ApplicationChanged, { applicationId: applicationId });
119+
this.publishApplicationChanged(applicationId);
120120
}
121121
return;
122122
}
@@ -138,34 +138,37 @@ export default class NavMenuComponent extends Vue {
138138
this.$router.push(route);
139139
}
140140

141-
PubSubService.Instance.publish(MenuApi.MessagingTopics.ApplicationChanged, { applicationId: applicationId });
141+
this.publishApplicationChanged(applicationId);
142142
}
143143

144144
private askCallbacksForWhichMenu(route: Router.Route): string {
145145
var chosenMenu = "";
146-
var ctx: IRouteNavigation = {
146+
const ctx: IRouteNavigation = {
147147
routeName: <string>route.name,
148148
url: route.fullPath,
149149
setMenu: (menuName: string) => {
150150
chosenMenu = menuName;
151151
}
152-
}
153-
for (var i = 0; i < this.callbacks.length; i++) {
152+
};
153+
for (let i = 0; i < this.callbacks.length; i++) {
154154
this.callbacks[i](ctx);
155155
if (chosenMenu !== "") {
156156
return chosenMenu;
157157
}
158158
}
159159

160-
return '';
160+
return "";
161161
}
162162

163163

164164
private updateCurrent(applicationId: number) {
165165
if (applicationId === 0) {
166166
this.currentApplicationName = "All applications";
167167
this.currentApplicationId = null;
168-
this.discoverLink = '/discover/';
168+
this.discoverLink = "/discover/";
169+
const msg = new MenuApi.ApplicationChanged();
170+
msg.applicationId = applicationId;
171+
this.publishApplicationChanged(null);
169172
return;
170173
}
171174

@@ -175,10 +178,13 @@ export default class NavMenuComponent extends Vue {
175178

176179
var title = app.title;
177180
if (title.length > 20) {
178-
title = title.substr(0, 15) + '[...]';
181+
title = title.substr(0, 15) + "[...]";
179182
}
180183
this.currentApplicationName = title;
181-
this.discoverLink = '/discover/' + applicationId;
184+
this.discoverLink = `/discover/${applicationId}`;
185+
var msg = new MenuApi.ApplicationChanged();
186+
msg.applicationId = applicationId;
187+
this.publishApplicationChanged(applicationId);
182188
});
183189
}
184190

@@ -189,11 +195,11 @@ export default class NavMenuComponent extends Vue {
189195
}
190196

191197
const app: MenuApi.MenuItem =
192-
{
193-
title: name,
194-
url: '',
195-
tag: applicationId
196-
};
198+
{
199+
title: name,
200+
url: '',
201+
tag: applicationId
202+
};
197203
return app;
198204

199205
}
@@ -207,4 +213,15 @@ export default class NavMenuComponent extends Vue {
207213
throw new Error('Failed to find application ' + applicationId + ".\r\n" + JSON.stringify(this.myApplications));
208214
}
209215

216+
private publishApplicationChanged(applicationId: number) {
217+
if (applicationId === this.lastPublishedId$) {
218+
return;
219+
}
220+
221+
this.lastPublishedId$ = applicationId;
222+
var msg = new MenuApi.ApplicationChanged();
223+
msg.applicationId = applicationId;
224+
PubSubService.Instance.publish(MenuApi.MessagingTopics.ApplicationChanged, msg);
225+
}
226+
210227
}

src/Server/Coderr.Server.Web/ClientApp/services/PubSub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ class Topic {
9393
}
9494

9595
unsubscribe(callback: ListenerCallback) {
96-
this.listeners = this.listeners.filter(x => x === callback);
96+
this.listeners = this.listeners.filter(x => x !== callback);
9797
}
9898
}

0 commit comments

Comments
 (0)