-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support specific ds library version and cache locally
- Loading branch information
Showing
11 changed files
with
153 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Select } from 'noya-designsystem'; | ||
import React, { useMemo, useState } from 'react'; | ||
|
||
interface Props { | ||
libraryName: string; | ||
version: string; | ||
onChange: (version: string) => void; | ||
} | ||
|
||
export function LibraryVersionPicker({ | ||
libraryName, | ||
version, | ||
onChange, | ||
}: Props) { | ||
const [availableVersions, setAvailableVersions] = useState<string[]>([]); | ||
|
||
const options = useMemo(() => { | ||
return [ | ||
...(!availableVersions.includes(version) ? [version] : []), | ||
...availableVersions, | ||
]; | ||
}, [availableVersions, version]); | ||
|
||
useMemo(() => { | ||
fetchAvailableVersions(libraryName).then(setAvailableVersions); | ||
}, [libraryName]); | ||
|
||
return ( | ||
<Select<string> | ||
id="select-version" | ||
value={version} | ||
onChange={onChange} | ||
options={options} | ||
/> | ||
); | ||
} | ||
|
||
async function fetchAvailableVersions(libraryName: string) { | ||
const response = await fetch(`https://registry.npmjs.org/${libraryName}`); | ||
const data = await response.json(); | ||
const versions = Object.keys(data.versions); | ||
|
||
// Sort with newest versions first | ||
versions.sort((a, b) => { | ||
const aDate = new Date(data.time[a]); | ||
const bDate = new Date(data.time[b]); | ||
|
||
return bDate.getTime() - aDate.getTime(); | ||
}); | ||
|
||
return versions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters