Skip to content

Commit b58e130

Browse files
feat: packages list
1 parent 568b4fb commit b58e130

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

examples/playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@navigraph/auth": "*",
1616
"@navigraph/charts": "*",
1717
"@navigraph/leaflet": "*",
18+
"@navigraph/packages": "*",
1819
"@tanstack/react-query": "^5.52.2",
1920
"clsx": "^2.1.1",
2021
"leaflet": "^1.9.4",

examples/playground/src/Root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Auth from "./pages/Auth"
88
import Tiles from "./pages/Tiles"
99
import Charts from "./pages/Charts"
1010
import Amdb from "./pages/Amdb"
11+
import Packages from "./pages/Packages"
1112

1213
function Root() {
1314
useAppConfigLoader();
@@ -22,6 +23,7 @@ function Root() {
2223
<Route path="/tiles" element={<Tiles />} />
2324
<Route path="/charts" element={<Charts />} />
2425
<Route path="/amdb/*" element={<Amdb />} />
26+
<Route path="/packages" element={<Packages />} />
2527
</Routes>
2628
<Outlet />
2729
<MainWindow />

examples/playground/src/components/SideBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import clsx from "clsx";
22
import { IconType } from "react-icons";
3-
import { FaDatabase, FaGlobe, FaMap, FaUser } from "react-icons/fa";
3+
import { FaDatabase, FaDownload, FaGlobe, FaMap, FaUser } from "react-icons/fa";
44
import { MdOutlineSettings } from "react-icons/md";
55
import { NavLink } from "react-router-dom";
66
import { appState } from "../state/app";
@@ -40,6 +40,7 @@ export default function SideBar() {
4040
<SideBarLink path="/tiles" icon={FaGlobe} disabled={!user?.scope.includes(Scope.TILES)}>Tiles</SideBarLink>
4141
<SideBarLink path="/charts" icon={FaMap} disabled={!user?.scope.includes(Scope.CHARTS)}>Charts</SideBarLink>
4242
<SideBarLink path="/amdb" icon={FaDatabase} disabled={!user?.scope.includes(Scope.AMDB)}>AMDB</SideBarLink>
43+
<SideBarLink path="/packages" icon={FaDownload} disabled={!user?.scope.includes(Scope.FMSDATA)}>Packages</SideBarLink>
4344
</div >
4445
)
4546
}

examples/playground/src/components/map/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ function NavigraphTiles({ auth }: { auth: NavigraphAuth }) {
8383

8484
const preset = useMemo<PresetConfig>(() => createPreset(source, theme, faa, tac), [source, theme, faa, tac]);
8585

86-
console.log(preset)
87-
8886
const ngLayer = useRef(new NavigraphTileLayer(auth, preset));
8987

9088
useEffect(() => {

examples/playground/src/components/protectedPage.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { Scope } from "@navigraph/app";
77
import { ReactNode } from "react";
88
import { getChartsAPI } from "@navigraph/charts";
99
import { getAmdbAPI } from "@navigraph/amdb";
10+
import { getPackagesAPI } from "@navigraph/packages";
1011

1112
interface PropsStruct {
12-
[Scope.CHARTS]: ReturnType<typeof getChartsAPI>
1313
[Scope.AMDB]: ReturnType<typeof getAmdbAPI>
14+
[Scope.CHARTS]: ReturnType<typeof getChartsAPI>
15+
[Scope.FMSDATA]: ReturnType<typeof getPackagesAPI>
1416
}
1517

1618
export function protectedPage<P extends {}, S extends Scope[]>(Component: (props: P & { auth: NavigraphAuth, user: User } & Pick<PropsStruct, Extract<S[number], keyof PropsStruct>>) => ReactNode, requiredScopes: S) {
@@ -26,9 +28,10 @@ export function protectedPage<P extends {}, S extends Scope[]>(Component: (props
2628
return null
2729
}
2830

29-
const charts = user.scope.includes(Scope.CHARTS) ? getChartsAPI() : undefined;
3031
const amdb = user.scope.includes(Scope.AMDB) ? getAmdbAPI() : undefined;
32+
const charts = user.scope.includes(Scope.CHARTS) ? getChartsAPI() : undefined;
33+
const fmsdata = user.scope.includes(Scope.FMSDATA) ? getPackagesAPI() : undefined;
3134

32-
return <Component user={user} auth={app.auth} amdb={amdb} charts={charts} {...props as unknown as any} />;
35+
return <Component user={user} auth={app.auth} amdb={amdb} charts={charts} fmsdata={fmsdata} {...props as unknown as any} />;
3336
};
3437
}

examples/playground/src/pages/Auth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { appState } from "../state/app";
55
import { redirect } from "react-router-dom";
66
import { userState } from "../state/user";
77
import { authState } from "../state/auth";
8-
import { DeviceFlowTokenExpiredError } from "@navigraph/app";
8+
import { DeviceFlowTokenExpiredError, InvalidScopeError } from "@navigraph/app";
99
import JsonView from "../components/JsonView";
1010

1111
export default function Auth() {
@@ -45,7 +45,7 @@ export default function Auth() {
4545

4646
{error && (
4747
<div className="text-red-500">
48-
{error instanceof DeviceFlowTokenExpiredError ? "Session expired, try again!" : error.message}
48+
{error instanceof DeviceFlowTokenExpiredError ? "Session expired, try again!" : error instanceof InvalidScopeError ? "Invalid scope provided, perhaps the configured client does not have permission for all requested scopes" : error.message}
4949
</div>
5050
)}
5151

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import JsonView from "../components/JsonView";
2+
import { protectedPage } from "../components/protectedPage";
3+
import { Scope } from "@navigraph/app";
4+
import { useQuery } from "@tanstack/react-query";
5+
import { Link } from "react-router-dom";
6+
import SpinningCircles from "react-loading-icons/dist/esm/components/spinning-circles";
7+
8+
const Packages = protectedPage(({ fmsdata }) => {
9+
const { data, isLoading } = useQuery({
10+
queryKey: ['packages-list'],
11+
queryFn: () => fmsdata.listPackages(),
12+
})
13+
14+
return (
15+
<div className="page-container flex flex-col items-center gap-3 px-3">
16+
<h1>Available Packages</h1>
17+
18+
{isLoading && <SpinningCircles />}
19+
20+
{data &&
21+
<>
22+
<span className="text-sm text-gray-100">Note that this is only a list of packages available for this client</span>
23+
<div className="flex flex-col gap-3 overflow-auto px-3 self-stretch">
24+
{data.map((item) =>
25+
<Link to={item.file.url} download>
26+
<JsonView onClick={() => null} content={item} />
27+
</Link>
28+
)}
29+
</div>
30+
</>
31+
}
32+
</div>
33+
)
34+
}, [Scope.FMSDATA]);
35+
36+
export default Packages;

0 commit comments

Comments
 (0)