Skip to content

Commit 28952b0

Browse files
committed
Chack and redirect to search query from 404 page, if results exist
1 parent 14d9f3c commit 28952b0

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

frontend/src/static/js/components/webstatus-feature-page.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
TEST_COUNT_METRIC_VIEW,
3131
SUBTEST_COUNT_METRIC_VIEW,
3232
DEFAULT_TEST_VIEW,
33+
FeatureSortOrderType,
3334
} from '../api/client.js';
3435
import {
3536
formatFeaturePageUrl,
@@ -238,17 +239,36 @@ export class FeaturePage extends BaseChartsPage {
238239
this.location.params['featureId']?.toString() || 'undefined';
239240
}
240241

242+
private async handleNotFound(featureId: string): Promise<void> {
243+
try {
244+
const response = await this.apiClient.getFeatures(
245+
featureId,
246+
'' as FeatureSortOrderType,
247+
undefined,
248+
0,
249+
1,
250+
);
251+
252+
const data = response.data;
253+
254+
// TODO: cannot use navigateToUrl because it creates a
255+
// circular dependency.
256+
// For now use the window href and revisit when navigateToUrl
257+
// is move to another location.
258+
const queryParam = Array.isArray(data) && data.length > 0 ? `?q=${featureId}` : "";
259+
window.location.href = `/errors-404/feature-not-found${queryParam}`;
260+
} catch (error) {
261+
window.location.href = `/errors-404/feature-not-found`;
262+
}
263+
}
264+
241265
render(): TemplateResult {
242266
return html`
243267
${this._loadingTask?.render({
244268
complete: () => this.renderWhenComplete(),
245269
error: error => {
246270
if (error instanceof NotFoundError) {
247-
// TODO: cannot use navigateToUrl because it creates a
248-
// circular dependency.
249-
// For now use the window href and revisit when navigateToUrl
250-
// is move to another location.
251-
window.location.href = '/errors-404/feature-not-found';
271+
this.handleNotFound(this.featureId);
252272
}
253273
return this.renderWhenError();
254274
},

frontend/src/static/js/components/webstatus-notfound-error-page.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export class WebstatusNotFoundErrorPage extends LitElement {
9797
];
9898
}
9999
protected render(): TemplateResult {
100+
// Extract query params
101+
const params = new URLSearchParams(window.location.search);
102+
const badId = params.get('q');
103+
100104
return html`
101105
<div id="error-container">
102106
<div id="error-header">
@@ -108,16 +112,34 @@ export class WebstatusNotFoundErrorPage extends LitElement {
108112
</div>
109113
110114
<div id="error-actions">
111-
<div id="error-action-home">
112-
<sl-button id="error-action-home-btn" variant="primary" href="/"
113-
>Go back home</sl-button
114-
>
115-
</div>
115+
${badId
116+
? html`
117+
<div id="error-action-search">
118+
<sl-button
119+
id="error-action-search-btn"
120+
variant="primary"
121+
href="/?q=${badId}"
122+
>
123+
Search for Similar names
124+
</sl-button>
125+
</div>
126+
`
127+
: html`
128+
<div id="error-action-home">
129+
<sl-button
130+
id="error-action-home-btn"
131+
variant="primary"
132+
href="/"
133+
>
134+
Go back home
135+
</sl-button>
136+
</div>
137+
`}
116138
<div id="error-action-report">
117139
<sl-icon name="github"></sl-icon>
118-
<a href="${GITHUB_REPO_ISSUE_LINK}" target="_blank"
119-
>Report an issue</a
120-
>
140+
<a href="${GITHUB_REPO_ISSUE_LINK}" target="_blank">
141+
Report an issue
142+
</a>
121143
</div>
122144
</div>
123145
</div>

0 commit comments

Comments
 (0)