Skip to content

Commit

Permalink
fix: rollback FunixFunctionList.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Oct 31, 2023
1 parent 42201d5 commit 494bfc3
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions frontend/src/components/FunixFunctionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,17 @@ const FunixFunctionList: React.FC<FunctionListProps> = ({ backend }) => {
setTree(list.some((f) => typeof f.module === "string"));
if (list.length === 1) {
handleFetchFunctionDetail(list[0]);
setRadioGroupValue(list[0].name);
setRadioGroupValue(list[0].path);
} else {
if (default_function !== null) {
const preview = list.filter(
(preview) => preview.id === default_function
);
if (preview.length === 1) {
handleFetchFunctionDetail(preview[0]);
setRadioGroupValue(preview[0].path);
}
}
}
}
queryData().then();
Expand Down Expand Up @@ -171,13 +181,9 @@ const FunixFunctionList: React.FC<FunctionListProps> = ({ backend }) => {
};

useEffect(() => {
const pathParams = pathname.split("/").filter((value) => value !== "");
if (
pathParams.length !== 0 &&
state.length !== 0 &&
pathParams[0] !== radioGroupValue
) {
const functionName = decodeURIComponent(pathParams[0]);
const pathParam = pathname.substring(1);
if (pathParam !== radioGroupValue) {
const functionPath = decodeURIComponent(pathParam);
const selectedFunctionPreview = state.filter(
(preview) => preview.path === functionPath
);
Expand Down Expand Up @@ -244,23 +250,29 @@ const FunixFunctionList: React.FC<FunctionListProps> = ({ backend }) => {

const treeList = treeToList(fileTree);

const renderNodeString = (node: string, now: number) => (
<ListItemButton
onClick={() => {
changeRadioGroupValue(node);
}}
key={node}
selected={radioGroupValue === node}
sx={{
paddingLeft: `${2 + now}rem`,
}}
>
<ListItemText
primary={<MarkdownDiv markdown={node} isRenderInline={true} />}
disableTypography
/>
</ListItemButton>
);
const renderNodeString = (node: string, now: number) => {
const [name, path] = node.split("#");

return (
<ListItemButton
onClick={() => {
changeRadioGroupValueByPath(path);
}}
key={node}
selected={radioGroupValue === path}
sx={{
paddingLeft: `${2 + now}rem`,
}}
>
<ListItemText
primary={<MarkdownDiv markdown={name} isRenderInline={true} />}
sx={{
wordWrap: "break-word",
}}
/>
</ListItemButton>
);
};

const renderNode = (node: any, now: number) => {
if (typeof node === "string") {
Expand Down

0 comments on commit 494bfc3

Please sign in to comment.