Skip to content

Commit 1acf842

Browse files
authored
Merge pull request #249 from dotCMS/changelog-singleton-fix
fixed the v param for evergreen versions
2 parents 75eafa9 + d71ff36 commit 1acf842

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

components/changelogs/ChangeLogList.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
import OnThisPage from "../navigation/OnThisPage";
44
import ChangeLogEntry from "./ChangeLogEntry";
55
import Link from "next/link";
6-
import { useSearchParams, useRouter } from "next/navigation";
6+
import { useSearchParams } from "next/navigation";
77
import { extractDateForTables } from '../../util/formatDate'
88
import { useChangelog } from "@/hooks/useChangelog";
99
import { ChevronLeft, ChevronRight, Loader2 } from "lucide-react";
1010
import Breadcrumbs from "../navigation/Breadcrumbs";
1111
import PaginationBar from "../PaginationBar";
1212
import Dropdown from "../shared/dropdown";
13-
import { useState, useEffect } from "react";
13+
import { useEffect } from "react";
1414

1515
export default function ChangeLogContainer({ sideNav, slug }) {
1616
//const router = useRouter(); // see removal of router in handleVersionChange
1717
const searchParams = useSearchParams();
1818
const paramLts = searchParams.get("lts");
19-
20-
const [singleVersion, setSingleVersion] = useState(searchParams.get("v"));
19+
/** Always read from URL (useState initial value can miss ?v= on first paint). */
20+
const vParam = searchParams.get("v") ?? "";
2121

2222
let isLts = paramLts && paramLts !== "false";
2323
let vLts = "";
@@ -29,7 +29,7 @@ export default function ChangeLogContainer({ sideNav, slug }) {
2929
const { data, loading, error, hasNextPage, hasPrevPage } = useChangelog(
3030
currentPage,
3131
paramLts,
32-
singleVersion,
32+
vParam,
3333
);
3434

3535
// Handle hash scrolling after data is loaded
@@ -192,6 +192,19 @@ export default function ChangeLogContainer({ sideNav, slug }) {
192192
<ChangeLogEntry key={item?.identifier || index} item={item} index={index} />
193193
))}
194194

195+
{vParam && (
196+
<p className="mt-8 pl-1 text-base leading-7 text-foreground">
197+
Want to browse every release?{" "}
198+
<Link
199+
href="/docs/changelogs"
200+
className="text-primary-purple hover:opacity-80 underline hover:no-underline"
201+
>
202+
Visit the full changelog
203+
</Link>
204+
.
205+
</p>
206+
)}
207+
195208
<div className="mt-8 mb-12">
196209
<PaginationBar pagination={data.pagination} currentPage={data.pagination.page} additionalQueryParams={isLts ? `&lts=${isLts}` : ""} />
197210
</div>

hooks/useChangelog.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export function useChangelog(currentPage: number = 1, vLts: string = "false", si
1818
const [error, setError] = useState<Error | null>(null);
1919
const [page, setPage] = useState(currentPage);
2020

21+
useEffect(() => {
22+
setPage(currentPage);
23+
}, [currentPage]);
24+
2125
const handleNextPage = () => setPage(prev => prev + 1);
2226
const handlePrevPage = () => setPage(prev => Math.max(1, prev - 1));
2327

@@ -39,7 +43,7 @@ export function useChangelog(currentPage: number = 1, vLts: string = "false", si
3943
}
4044

4145
fetchChangelog();
42-
}, [page, vLts]);
46+
}, [page, vLts, singleVersion]);
4347

4448
return {
4549
data,

services/docs/getChangelog/getChangelog.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import { SIZE_PAGE } from './config';
22
import { logRequest } from '@/util/logRequest';
33
import { graphqlResults } from '@/services/gql';
44

5-
export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "", limit = SIZE_PAGE }) => {
6-
const assembleQuery = (buildQuery:string, ltsQuery:string, ltsMajVersion:string, singleVersion:string,
7-
limit:number, page:number, sortBy:string) => {
8-
return `query ContentAPI {
5+
/** Escape a value for use inside Lucene quoted term (query_string). */
6+
function luceneQuotedTerm(value: string): string {
7+
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
8+
}
9+
10+
/**
11+
* Embed full Lucene query in GraphQL string literal — inner " must be escaped.
12+
*/
13+
function assembleQuery(luceneQuery: string, limit: number, page: number, sortBy: string) {
14+
const escaped = luceneQuery.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
15+
return `query ContentAPI {
916
DotcmsbuildsCollection(
10-
query: "${buildQuery} ${ltsQuery} ${ltsMajVersion} ${singleVersion}"
17+
query: "${escaped}"
1118
limit: ${limit}
1219
page: ${page}
1320
sortBy: "${sortBy}"
@@ -42,16 +49,17 @@ export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "
4249
offset
4350
}
4451
}`;
45-
};
46-
52+
}
53+
54+
export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "", limit = SIZE_PAGE }) => {
4755
//Basic type info for querying any changelogs at all
4856
const buildQuery =
4957
'+contentType:Dotcmsbuilds +Dotcmsbuilds.released:true +Dotcmsbuilds.showInChangeLog:true +live:true';
5058

5159
//Build query components to grab one of each of the LTS major versions, for reference
5260
const ltsQueryMaj = '+Dotcmsbuilds.lts:1';
5361
const sortByEol = 'Dotcmsbuilds.eolDate desc';
54-
const ltsMajorQuery = assembleQuery(buildQuery, ltsQueryMaj, "", "", limit, page, sortByEol);
62+
const ltsMajorQuery = assembleQuery(`${buildQuery} ${ltsQueryMaj}`, limit, page, sortByEol);
5563
const ltsMajorResults = await logRequest(async () => graphqlResults(ltsMajorQuery), 'getLTSMajorVersions');
5664
const ltsMajorResult = ltsMajorResults?.data;
5765

@@ -61,9 +69,11 @@ export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "
6169
throw new Error(ltsMajorResults.errors[0].message);
6270
}
6371

64-
//if singleVersion is provided, check if it's an LTS patch version
72+
// If singleVersion is provided while already scoped to LTS (lts=…), detect patch lines
73+
// (e.g. 23.1.2 under tag 23.1). Skip when v is used alone on "current" — otherwise short
74+
// tags like "26" match calver minors such as 26.03.23-01 and we drop the minor filter.
6575
let ltsPatchVersion = "";
66-
if(singleVersion){
76+
if (singleVersion && vLts && vLts !== "false") {
6777
for(const item of ltsMajorResult.DotcmsbuildsCollection){
6878
for (const vTag of item.tags){
6979
if(singleVersion.startsWith(vTag) && singleVersion !== vTag){
@@ -95,7 +105,13 @@ export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "
95105
const ltsMajVersion = sussOutLatestMajor(ltsMajorResult.DotcmsbuildsCollection[0], vLts);
96106
//console.log("sussed as:", ltsMajVersion);
97107
const sortBy = 'Dotcmsbuilds.releasedDate desc, Dotcmsbuilds.minor desc';
98-
const query = assembleQuery(buildQuery, ltsQuery, ltsMajVersion, (singleVersion && !ltsPatchVersion) ? `+Dotcmsbuilds.minor:${singleVersion}` : "", (ltsMajVersion ? 20 : limit), page, sortBy);
108+
// Quote minor so hyphens (e.g. 26.03.23-01) are not parsed as Lucene operators.
109+
const minorClause =
110+
singleVersion && !ltsPatchVersion
111+
? `+Dotcmsbuilds.minor:"${luceneQuotedTerm(singleVersion)}"`
112+
: '';
113+
const luceneQuery = `${buildQuery} ${ltsQuery} ${ltsMajVersion} ${minorClause}`.trim();
114+
const query = assembleQuery(luceneQuery, ltsMajVersion ? 20 : limit, page, sortBy);
99115
const result = await logRequest(async () => graphqlResults(query), 'getChangelog');
100116

101117
if (result?.errors && result.errors.length > 0) {

0 commit comments

Comments
 (0)