55
66import { RuntimeConfig , stripTrailingSlash } from "@orch-ui/utils" ;
77
8+ /**
9+ * Extracts major.minor version from orchestrator version string
10+ * @param {string } version - Version string like "v3.0.1-dev-b21fb28"
11+ * @returns {string } - Major.minor version like "3.0" or "main" if invalid
12+ */
13+ function extractDocumentationVersion ( version : string ) {
14+ let docVersion = "main" ;
15+
16+ if ( ! version ) {
17+ return docVersion ;
18+ }
19+
20+ // Remove "v" prefix if present
21+ let cleanVersion = version ;
22+ if ( version . startsWith ( "v" ) ) {
23+ cleanVersion = version . substring ( 1 ) ; // removes "v" prefix
24+ } else {
25+ // if orchestrator version is received other than "v" format return default
26+ return docVersion ;
27+ }
28+
29+ // Split by "-" to separate version from metadata
30+ const versionParts = cleanVersion . split ( "-" ) ; //returns [3.0.1, dev, b21fb28]
31+
32+ if ( versionParts . length > 0 ) {
33+ // Split the version numbers by "."
34+ const numbers = versionParts [ 0 ] . split ( "." ) ; //returns [3, 0, 1]
35+
36+ // Check if we have at least major and minor version
37+ if ( numbers . length >= 2 ) {
38+ docVersion = `${ numbers [ 0 ] } .${ numbers [ 1 ] } ` ; // returns `3.0`
39+ }
40+ }
41+
42+ return docVersion ;
43+ }
44+
845/**
946 * Method to transform from url to doc link
1047 * @param url - pathname without search params (location.pathname)
1148 */
1249export const getDocsForUrl = ( url : string ) => {
50+ // this is where documentation is hoisted and same value is received
51+ // ...in documentationUrl but concatenated with `/main`
52+ const docHost = "https://docs.openedgeplatform.intel.com/edge-manage-docs" ;
1353 const urlParts = url . substring ( 1 ) . split ( "/" ) ;
14-
15- const docsUrl = stripTrailingSlash ( RuntimeConfig . documentationUrl ) ;
54+ let docVersion ;
55+ if (
56+ window . __RUNTIME_CONFIG__ ?. VERSIONS . orchestrator &&
57+ RuntimeConfig . getComponentVersion ( "orchestrator" )
58+ ) {
59+ docVersion = extractDocumentationVersion (
60+ RuntimeConfig . getComponentVersion ( "orchestrator" ) ,
61+ ) ;
62+ }
63+ let docsUrl = stripTrailingSlash ( RuntimeConfig . documentationUrl ) ;
1664 let docsMapper = RuntimeConfig . documentation ;
17-
1865 // looking for matches part (url segment) by part
1966 // takes browser url, e.g. /test/aa/bb/cc and test against mapper values, segment by segment
2067 // if values from the same segment index from url and mapper key are different we dont grab this mapping
@@ -31,7 +78,6 @@ export const getDocsForUrl = (url: string) => {
3178 [ urlParts [ index ] , "*" ] . includes ( part ) ,
3279 ) ,
3380 ) ;
34-
3581 // if we get more than one match it means that we get match against static address and segment with path parameter
3682 // e.g. /test/aa/bb and /test/*/bb or /test/aa/*
3783 // then we need to pick key with the least number of path parameters (*)
@@ -56,11 +102,25 @@ export const getDocsForUrl = (url: string) => {
56102 ] ;
57103 }
58104
59- // when mapper contains only one entry, we are ready to read the docs address
105+ try {
106+ const docsUrlObj = new URL ( docsUrl ) ;
107+ const docHostObj = new URL ( docHost ) ;
108+ // fail safe check to ensure documentation host
109+ if (
110+ docsUrlObj . host === docHostObj . host &&
111+ docsUrlObj . protocol === docHostObj . protocol &&
112+ docVersion
113+ ) {
114+ // concatenating the release version with docsUrl
115+ docsUrl = `${ docHost } /${ docVersion } ` ;
116+ }
117+ } catch ( e ) {
118+ // fallback: do nothing, keep docsUrl as is
119+ }
120+
60121 if ( docsMapper . length === 1 ) {
61122 return `${ docsUrl } ${ docsMapper [ 0 ] . dest } ` ;
62123 }
63-
64124 // default option
65125 const defaultDocsAddress =
66126 RuntimeConfig . documentation [ 0 ] ?. dest ?? `${ window . location . origin } /docs` ;
0 commit comments