Skip to content

Commit

Permalink
api ref
Browse files Browse the repository at this point in the history
  • Loading branch information
aelmanaa committed Jan 2, 2025
1 parent 9c43f62 commit 339c775
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 33 deletions.
77 changes: 50 additions & 27 deletions src/components/VersionSelector/base/VersionSelectorClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ export const VersionSelectorClient = <T extends string>({
setIsChanging(true)

try {
// Extract the page path from current URL
const pathMatch = currentPath.match(new RegExp(`/${config.product.name}/api-reference/v[^/]+/(.+)`))
// Extract the page path from current URL with improved regex
const pathMatch = currentPath.match(new RegExp(`/${config.product.name}/api-reference/v[^/]+/(.+?)/?$`))

// If no specific page (e.g., index), proceed normally
if (!pathMatch) {
// If no page path (e.g. index), proceed normally
window.location.href = buildVersionUrl(
{ ...config.product, name: config.product.name as Collection },
currentPath,
Expand All @@ -111,34 +112,56 @@ export const VersionSelectorClient = <T extends string>({
return
}

const pagePath = pathMatch[1].replace(/\/$/, "") // Remove trailing slash
const pagePath = pathMatch[1] // Path without trailing slash
const hasTrailingSlash = currentPath.endsWith("/")
const productAvailability = PAGE_AVAILABILITY[config.product.name]
const pageConfig = productAvailability?.[pagePath]

// Check if page is not available in target version
if (pageConfig?.notAvailableIn?.includes(newVersion)) {
if (pageConfig.redirectTo?.[newVersion]) {
// Build new URL with redirect path
const newPath = currentPath.replace(
new RegExp(`${pagePath}/?$`), // Handle trailing slash
`${pageConfig.redirectTo[newVersion]}/`
)
window.location.href = newPath
return
}

setIsChanging(false)
setError(`This page is not available in version ${newVersion}`)
return
if (productAvailability) {
const pageConfig = productAvailability[pagePath]

// Check version-specific availability
if (pageConfig) {
// Check if page is only available in specific versions
if (pageConfig.onlyAvailableIn && !pageConfig.onlyAvailableIn.includes(newVersion)) {
setIsChanging(false)
setError(`This page is only available in versions: ${pageConfig.onlyAvailableIn.join(", ")}`)
return
}

// Check if page is not available in target version
if (pageConfig.notAvailableIn?.includes(newVersion)) {
if (pageConfig.redirectTo?.[newVersion]) {
const redirectPath =
buildVersionUrl(
{ ...config.product, name: config.product.name as Collection },
currentPath.replace(pagePath, pageConfig.redirectTo[newVersion]),
currentVersion,
newVersion
) + (hasTrailingSlash ? "/" : "")

window.location.href = redirectPath
return
}

setIsChanging(false)
setError(`This page is not available in version ${newVersion}`)
return
}
}
}

// Page is available or not in config (assume available)
const newUrl = buildVersionUrl(
{ ...config.product, name: config.product.name as Collection },
currentPath,
currentVersion,
newVersion
)
// If we get here, either:
// 1. Product has no availability config
// 2. Page has no specific config
// 3. Page exists in target version
const newUrl =
buildVersionUrl(
{ ...config.product, name: config.product.name as Collection },
currentPath,
currentVersion,
newVersion
) + (hasTrailingSlash ? "/" : "")

window.location.href = newUrl
} catch (err) {
setIsChanging(false)
Expand Down
6 changes: 6 additions & 0 deletions src/config/versions/page-availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type RedirectMap = {
type PageAvailability = {
notAvailableIn?: string[]
redirectTo?: RedirectMap
onlyAvailableIn?: string[]
}

export const PAGE_AVAILABILITY: Record<string, Record<string, PageAvailability>> = {
Expand All @@ -19,4 +20,9 @@ export const PAGE_AVAILABILITY: Record<string, Record<string, PageAvailability>>
notAvailableIn: ["v1.5.0"],
},
},
"chainlink-local": {
"mock-evm2evm-offramp": {
onlyAvailableIn: ["v0.2.1"],
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ date: Last Modified
title: "AggregatorV2V3Interface v0.2.1 API Reference"
metadata:
description: "API documentation for AggregatorV2V3Interface in Solidity, version v0.2.1."
canonical: "/chainlink-local/api-reference/v0.2.3/aggregator-v2v3-interface"
canonical: "/chainlink-local/api-reference/v0.2.3/aggregator-v2-v3-interface"
---

import { Aside } from "@components"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ date: Last Modified
title: "AggregatorV2V3Interface v0.2.2 API Reference"
metadata:
description: "API documentation for AggregatorV2V3Interface in Solidity, version v0.2.2."
canonical: "/chainlink-local/api-reference/v0.2.3/aggregator-v2v3-interface"
canonical: "/chainlink-local/api-reference/v0.2.3/aggregator-v2-v3-interface"
---

import { Aside } from "@components"
Expand All @@ -22,8 +22,8 @@ A combined interface that inherits functionality from both AggregatorInterface a

This interface inherits from:

- [`AggregatorInterface`](./aggregator-interface) - Provides basic price feed functionality
- [`AggregatorV3Interface`](./aggregator-v3-interface) - Provides extended price feed functionality
- [`AggregatorInterface`](/chainlink-local/api-reference/v0.2.2/aggregator-interface) - Provides basic price feed functionality
- [`AggregatorV3Interface`](/chainlink-local/api-reference/v0.2.2/aggregator-v3-interface) - Provides extended price feed functionality

<Aside>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A mock implementation of the AggregatorV2V3Interface for testing purposes, provi

This contract inherits from:

- [`AggregatorV2V3Interface`](./aggregator-v2v3-interface) - Combined interface that includes both AggregatorInterface and AggregatorV3Interface functionality
- [`AggregatorV2V3Interface`](/chainlink-local/api-reference/v0.2.2/aggregator-v2-v3-interface) - Combined interface that includes both AggregatorInterface and AggregatorV3Interface functionality

<Aside>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The `it("Should transfer CCIP test tokens from EOA to EOA")` function sets up th

1. Call the source router to estimate the fees.

1. Call the [`requestLinkFromFaucet`](/chainlink-local/api-reference/v0.2.3/ccip-local-simulator-fork-js#requestlinkfromfaucet)
1. Call the [`requestLinkFromFaucet`](/chainlink-local/api-reference/v0.2.3/ccip-local-simulator-fork-js#requestlinkfromthefaucet)
function to request LINK tokens for Alice (sender).

1. Connect to the LINK contract and approve the LINK token for paying CCIP fees.
Expand Down

0 comments on commit 339c775

Please sign in to comment.