Skip to content

Commit

Permalink
feat: Modify error page infiniflow#1841
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 committed Oct 15, 2024
1 parent 04dd952 commit dc364e5
Show file tree
Hide file tree
Showing 28 changed files with 197 additions and 510 deletions.
33 changes: 17 additions & 16 deletions gui/app/(dashboard)/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import {
ITableSegment
} from '@/lib/databse-interface';
import { drop, get, post } from '@/lib/request';
import { isResponseListExist } from '@/lib/utils';
import { unstable_rethrow } from 'next/navigation';

export const listDatabase = async () => {
try {
const x = await get(`${ApiUrl.databases}`);
console.log('🚀 ~ x:', x);
return x;
} catch (error) {
console.log('🚀 ~ error:', error);
unstable_rethrow(error);
return { databases: [] };
}
};

Expand Down Expand Up @@ -142,6 +145,8 @@ export const showConfigs = async () => {
return x;
} catch (error) {
console.log('🚀 ~ error:', error);
unstable_rethrow(error);
return {};
}
};

Expand All @@ -150,16 +155,9 @@ export const showVariables = async () => {
const x = await get(`${ApiUrl.variables}/global`);
return x;
} catch (error) {
unstable_rethrow(error);
console.log('🚀 ~ error:', error);
}
};

export const showCurrentNode = async () => {
try {
const x = await get(`${ApiUrl.variables}/global`);
return x;
} catch (error) {
console.log('🚀 ~ error:', error);
return {};
}
};

Expand All @@ -174,11 +172,12 @@ export const showTableColumns = async ({
const x = await get(
`${ApiUrl.databases}/${database_name}/${ApiUrl.tables}/${table_name}/${ApiUrl.columns}`
);
if (x.error_code === 0) {
if (isResponseListExist(x, 'columns')) {
return x.columns;
}
return [];
} catch (error) {
} catch (error: unknown) {
console.log('🚀 ~ error:', error);
return [];
}
};
Expand All @@ -194,11 +193,12 @@ export const showTableIndexes = async ({
const x = await get(
`${ApiUrl.databases}/${database_name}/${ApiUrl.tables}/${table_name}/${ApiUrl.indexes}`
);
if (x.error_code === 0) {
if (isResponseListExist(x, 'indexes')) {
return x.indexes;
}
return [];
} catch (error) {
} catch (error: unknown) {
console.log('🚀 ~ error:', error);
return [];
}
};
Expand All @@ -214,11 +214,12 @@ export const showTableSegments = async ({
const x = await get(
`${ApiUrl.databases}/${database_name}/${ApiUrl.tables}/${table_name}/${ApiUrl.segments}`
);
if (x.error_code === 0) {
if (isResponseListExist(x, 'segments')) {
return x?.segments ?? [];
}
return [];
} catch (error) {
} catch (error: unknown) {
console.log('🚀 ~ error:', error);
return [];
}
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ const TableMap = {
[Leaf.Segments]: TableSegments
};

const Empty = () => {
return <div>empty</div>;
};

export default async function DatabasePage({
searchParams: { tab },
params: { tableId, databaseId }
}: DatabaseRouteParams) {
const DatabaseTable: React.FunctionComponent<DatabaseRouteParams['params']> =
TableMap[tab];
TableMap[tab] ?? Empty;

return (
<div>
Expand Down
14 changes: 7 additions & 7 deletions gui/app/(dashboard)/database/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useHandleClickTreeName = () => {
}
}
},
[]
[router]
);

return { handleClickTreeName };
Expand All @@ -55,7 +55,7 @@ export const useBuildTreeData = () => {
try {
setLoading(true);
const ret = await listDatabase();
if (ret.databases.length > 0) {
if (ret.databases?.length > 0) {
setData(
updateTreeData(
[
Expand Down Expand Up @@ -125,7 +125,7 @@ export const useBuildTreeData = () => {
}, [fetchDatabases]);

const onLoadData = async ({ element }: { element: INode }) => {
if (element.children.length > 0) {
if (element?.children?.length > 0) {
return;
}

Expand Down Expand Up @@ -157,7 +157,7 @@ export const useBuildTreeData = () => {
};

const wrappedOnLoadData = async (props: ITreeViewOnLoadDataProps) => {
const nodeHasNoChildData = props.element.children.length === 0;
const nodeHasNoChildData = props.element.children?.length === 0;
const nodeHasAlreadyBeenLoaded = nodesAlreadyLoaded.find(
(e) => e.id === props.element.id
);
Expand Down Expand Up @@ -196,7 +196,7 @@ export const useFetchTableColumns = ({
});

setTableColumns(data);
}, []);
}, [databaseId, tableId]);

useEffect(() => {
fetchTableColumns();
Expand All @@ -218,7 +218,7 @@ export const useFetchTableIndexes = ({
});

setTableIndexes(data);
}, []);
}, [databaseId, tableId]);

useEffect(() => {
fetchTableIndexes();
Expand All @@ -240,7 +240,7 @@ export const useFetchTableSegments = ({
});

setTableSegments(data);
}, []);
}, [databaseId, tableId]);

useEffect(() => {
fetchTableSegments();
Expand Down
2 changes: 1 addition & 1 deletion gui/app/(dashboard)/database/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function DatabaseLayout({
children: React.ReactNode;
}) {
return (
<div className="flex divide-x h-full">
<div className="flex divide-x h-[calc(100vh-32px)]">
<section className="w-1/4">
<AsyncTree></AsyncTree>
</section>
Expand Down
23 changes: 12 additions & 11 deletions gui/app/(dashboard)/database/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function AsyncTree() {
const branchNode = (isExpanded: boolean, element: INode) => {
return isExpanded &&
!element.metadata?.isEmpty &&
element.children.length === 0 ? (
element.children?.length === 0 ? (
<>
<span
role="alert"
Expand All @@ -76,19 +76,20 @@ function AsyncTree() {
};
return (
<div
{...getNodeProps({ onClick: handleExpand })}
{...getNodeProps({
onClick: isBranch
? handleExpand
: handleClickTreeName({
level,
name: element.name,
parent: element.parent,
data
})
})}
style={{ marginLeft: 40 * (level - 1) }}
>
{isBranch && branchNode(isExpanded, element)}
<div
className="flex items-center ml-1"
onClick={handleClickTreeName({
level,
name: element.name,
parent: element.parent,
data
})}
>
<div className="flex items-center ml-1">
{renderIcon(level, element.name)}
<span className="name">{element.name}</span>
</div>
Expand Down
37 changes: 2 additions & 35 deletions gui/app/(dashboard)/databases/page.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
import { Card, CardHeader, CardTitle } from '@/components/ui/card';
import AddIcon from '/public/add.svg';

import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue
} from '@radix-ui/react-select';
import { listDatabase } from '../actions';
import { DatabaseCard } from '../database-card';
import { DatabaseCreatingDialog } from '../database-creating-dialog';

interface IDatabaseSelectProps {
placeholder?: string;
options: Array<{ label: string; value: string }>;
}

export function DatabaseSelect({ placeholder, options }: IDatabaseSelectProps) {
return (
<Select>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder={placeholder} />
</SelectTrigger>
<SelectContent>
{options.map(({ value, label }) => (
<SelectItem value={value} key={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
);
}

export default async function HomePage({
searchParams
}: {
export default async function HomePage({}: {
searchParams: { q: string; offset: string };
}) {
const ret = await listDatabase();
const search = searchParams.q ?? '';
const offset = searchParams.offset ?? 0;

return (
<div className="grid grid-cols-4 gap-4">
{ret.databases.map((x: string, idx: number) => (
{ret?.databases?.map((x: string, idx: number) => (
<DatabaseCard key={idx} data={x}></DatabaseCard>
))}
<Card className="w-full max-w-sm">
Expand Down
Loading

0 comments on commit dc364e5

Please sign in to comment.