Skip to content

Commit

Permalink
patch: fix up terraform version selector sort (#2227)
Browse files Browse the repository at this point in the history
  • Loading branch information
kendallstrautman authored Nov 10, 2023
1 parent 5c43f51 commit bdaab6f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/version-context-switcher/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ const VersionContextSwitcher = ({
options,
}: VersionContextSwitcherProps): ReactElement => {
const currentProduct = useCurrentProduct()
const [selectedVersion, setSelectedVersion] =
useState<ContextSwitcherOption['value']>(initialValue)
let latestVersion = options[0].value
/** Update `latestVersion` to the latest version of the product
* that has been released if it can be determined. This is needed
* because not all products have `latest` listed as the first item
* in the sorted array. E.g. `vault-enterprise` lists `+ent.hsm.fips1402`
* variants first.
*/
for (let i = 0; i < options.length; i++) {
const versionLabel = options[i].label
const versionValue = options[i].value
if (versionLabel.indexOf('(latest)') >= 0) {
latestVersion = versionValue
break
}
}

const [selectedVersion, setSelectedVersion] = useState<
ContextSwitcherOption['value']
>(initialValue || latestVersion)

/**
* Handle change event for switcher, invoking the `onChange` function last if
Expand Down

1 comment on commit bdaab6f

@vercel
Copy link

@vercel vercel bot commented on bdaab6f Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.