Skip to content

Commit

Permalink
Fix documentation links.
Browse files Browse the repository at this point in the history
Links to documentation on Read the Docs for subjects, metrics, or sources with hyphens in their name wouldn't scroll to the right location.

Fixes #10843.
  • Loading branch information
fniessink committed Feb 18, 2025
1 parent e10e0ed commit 2b648d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/frontend/src/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export function dropdownOptions(options) {

export function referenceDocumentationURL(name) {
// Return a URL to the documentation for the metric/subject/source name
const slug = `${name?.toLowerCase().replaceAll(" ", "-").replaceAll(/[()/]/g, "")}`
const slug = `${name?.toLowerCase().replaceAll(" ", "-").replaceAll("_", "-").replaceAll(/[()/]/g, "")}`
return `${DOCUMENTATION_URL}/reference.html#${slug}`
}

Expand Down
16 changes: 16 additions & 0 deletions components/frontend/src/utils.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EDIT_ENTITY_PERMISSION, EDIT_REPORT_PERMISSION } from "./context/Permissions"
import { defaultDesiredResponseTimes } from "./defaults"
import {
DOCUMENTATION_URL,
addCounts,
capitalize,
getMetricResponseDeadline,
Expand All @@ -19,6 +20,7 @@ import {
niceNumber,
nrMetricsInReport,
nrMetricsInReports,
referenceDocumentationURL,
scaledNumber,
sortWithLocaleCompare,
sum,
Expand Down Expand Up @@ -514,3 +516,17 @@ it("returns whether a metric's measurement is outdated", () => {
// A metric with an outdated measurement is outdated:
expect(isMeasurementOutdated({ latest_measurement: { outdated: true } })).toBe(true)
})

it("returns the reference documentation URL", () => {
const url = `${DOCUMENTATION_URL}/reference.html`
// Simple name
expect(referenceDocumentationURL("name")).toBe(`${url}#name`)
// Name with spaces
expect(referenceDocumentationURL("name with space")).toBe(`${url}#name-with-space`)
// Name with underscores
expect(referenceDocumentationURL("name_with_underscore")).toBe(`${url}#name-with-underscore`)
// Name with brackets
expect(referenceDocumentationURL("(bracketed)")).toBe(`${url}#bracketed`)
// Name with forward slash
expect(referenceDocumentationURL("forward/slash")).toBe(`${url}#forwardslash`)
})
6 changes: 6 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ If your currently installed *Quality-time* version is not the latest version, pl

<!-- The line "## <square-bracket>Unreleased</square-bracket>" is replaced by the release/release.py script with the new release version and release date. -->

### [Unreleased]

### Fixed

- Links to documentation on Read the Docs for subjects, metrics, or sources with hyphens in their name wouldn't scroll to the right location. Fixes [#10843](https://github.com/ICTU/quality-time/issues/10843).

## v5.25.0 - 2025-02-14

### Added
Expand Down

0 comments on commit 2b648d5

Please sign in to comment.