Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-meals-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/lib-web": patch
---

UI 扩展当导航栏链接请求失败时,返回上一次请求的结果
13 changes: 10 additions & 3 deletions libs/web/src/layouts/base/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { LinkOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from "@ant-design/icons";
import { Space } from "antd";
import { join } from "path";
import React, { useCallback, useState } from "react";
import React, { useCallback, useRef, useState } from "react";
import { useAsync } from "react-async";
import { ExtensionRouteQuery, isUrl } from "src/extensions/common";
import { NavbarLink, navbarLinksRoute } from "src/extensions/navbarLinks";
Expand Down Expand Up @@ -221,15 +221,22 @@ interface FetcherProps {

const NavbarLinkFetcher = ({ extension, from, routeQuery, onDataFetched }: FetcherProps) => {

const lastResultRef = useRef<NavbarLink[] | undefined>(undefined);

const { reload } = useAsync({
promiseFn: useCallback(async () => {
const resp = await callExtensionRoute(navbarLinksRoute(from), routeQuery, {}, extension.url)
.then((resp) => {
const result = resp[200]?.navbarLinks;
lastResultRef.current = result;
return result;
})
.catch((e) => {
console.warn(`Failed to call navbarLinks of extension ${extension.name ?? extension.url}. Error: `, e);
return { 200: { navbarLinks: [] as NavbarLink[] } };
return lastResultRef.current;
});

const data = resp[200]?.navbarLinks?.map((x) => {
const data = resp?.map((x) => {

if (!isUrl(x.path)) {
const parts = ["/extensions"];
Expand Down