This is an automated email from the ASF dual-hosted git repository. young pushed a commit to branch young/feat/service-list-add in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
commit bf8e6e876dc2ca73ba96378e29d4de65c805643c Author: Skye Young <[email protected]> AuthorDate: Mon May 5 23:04:50 2025 +0800 feat: stream route list page --- .devcontainer/apisix_conf.yml | 6 ++ .devcontainer/devcontainer.json | 10 +++ src/apis/stream_routes.ts | 45 +++++++++++++ src/config/constant.ts | 1 + src/config/navRoutes.ts | 4 ++ src/locales/en/common.json | 15 +++++ src/routeTree.gen.ts | 26 ++++++++ src/routes/stream_routes/index.tsx | 127 +++++++++++++++++++++++++++++++++++++ src/types/schema/apisix/type.ts | 7 ++ 9 files changed, 241 insertions(+) diff --git a/.devcontainer/apisix_conf.yml b/.devcontainer/apisix_conf.yml index 1220d8fb2..94532cf57 100644 --- a/.devcontainer/apisix_conf.yml +++ b/.devcontainer/apisix_conf.yml @@ -18,6 +18,12 @@ apisix: node_listen: 9080 # APISIX listening port enable_ipv6: false + proxy_mode: http&stream + stream_proxy: + tcp: + - 9100 + udp: + - 9200 deployment: admin: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c3e38ed14..ead684d11 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,6 +11,8 @@ "forwardPorts": [ 9080, 9180, + 9100, + 9200, 5173, 5174, 4173 @@ -27,6 +29,14 @@ "9180": { "label": "APISIX Admin API Port", "onAutoForward": "notify" + }, + "9100": { + "label": "APISIX Stream Proxy TCP Port", + "onAutoForward": "silent" + }, + "9200": { + "label": "APISIX Stream Proxy UDP Port", + "onAutoForward": "silent" } }, "customizations": { diff --git a/src/apis/stream_routes.ts b/src/apis/stream_routes.ts new file mode 100644 index 000000000..85516ec07 --- /dev/null +++ b/src/apis/stream_routes.ts @@ -0,0 +1,45 @@ +import { API_STREAM_ROUTES } from '@/config/constant'; +import { req } from '@/config/req'; +import type { APISIXType } from '@/types/schema/apisix'; +import type { PageSearchType } from '@/types/schema/pageSearch'; +import { queryOptions } from '@tanstack/react-query'; + +export const getStreamRouteListQueryOptions = (props: PageSearchType) => { + const { page, pageSize } = props; + return queryOptions({ + queryKey: ['stream_routes', page, pageSize], + queryFn: () => + req + .get<unknown, APISIXType['RespStreamRouteList']>(API_STREAM_ROUTES, { + params: { page, page_size: pageSize }, + }) + .then((v) => v.data), + }); +}; + +export const getStreamRouteQueryOptions = (id: string) => + queryOptions({ + queryKey: ['stream_route', id], + queryFn: () => + req + .get<unknown, APISIXType['RespStreamRouteDetail']>( + `${API_STREAM_ROUTES}/${id}` + ) + .then((v) => v.data), + }); + +export const putStreamRouteReq = (data: APISIXType['StreamRoute']) => { + const { id, ...rest } = data; + return req.put< + APISIXType['StreamRoute'], + APISIXType['RespStreamRouteDetail'] + >(`${API_STREAM_ROUTES}/${id}`, rest); +}; + +export const postStreamRouteReq = ( + data: Omit<APISIXType['StreamRoute'], 'id'> +) => + req.post<unknown, APISIXType['RespStreamRouteDetail']>( + API_STREAM_ROUTES, + data + ); diff --git a/src/config/constant.ts b/src/config/constant.ts index 1b8fb885a..b48150c15 100644 --- a/src/config/constant.ts +++ b/src/config/constant.ts @@ -4,6 +4,7 @@ export const LOCAL_STORAGE_ADMIN_KEY = 'apisix-admin-key'; export const API_PREFIX = '/apisix/admin'; export const API_ROUTES = '/routes'; +export const API_STREAM_ROUTES = '/stream_routes'; export const API_UPSTREAMS = '/upstreams'; export const API_PROTOS = '/protos'; export const API_GLOBAL_RULES = '/global_rules'; diff --git a/src/config/navRoutes.ts b/src/config/navRoutes.ts index 960f86e32..43e8f3df1 100644 --- a/src/config/navRoutes.ts +++ b/src/config/navRoutes.ts @@ -14,6 +14,10 @@ export const navRoutes: NavRoute[] = [ to: '/routes', label: 'routes', }, + { + to: '/stream_routes', + label: 'streamRoutes', + }, { to: '/upstreams', label: 'upstreams', diff --git a/src/locales/en/common.json b/src/locales/en/common.json index fa01f8828..014ecd5e8 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -193,6 +193,7 @@ "pluginMetadata": "Plugin Metadata", "protos": "Protos", "routes": "Routes", + "streamRoutes": "Stream Routes", "secrets": "Secrets", "services": "Services", "ssls": "SSLs", @@ -258,6 +259,20 @@ "adminKey": "Admin Key", "title": "Setting" }, + "streamRoutes": { + "add": { + "submit": "Add Stream Route Successfully", + "title": "Add Stream Route" + }, + "detail": { + "title": "Stream Route Detail" + }, + "edit": { + "success": "Edit Stream Route Successfully", + "title": "Edit Stream Route" + }, + "title": "Stream Routes" + }, "upstreams": { "add": { "success": "Add Upstream Successfully", diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 7d0341a6e..03498a25e 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -13,6 +13,7 @@ import { Route as rootRoute } from './routes/__root' import { Route as IndexImport } from './routes/index' import { Route as UpstreamsIndexImport } from './routes/upstreams/index' +import { Route as StreamroutesIndexImport } from './routes/stream_routes/index' import { Route as SslsIndexImport } from './routes/ssls/index' import { Route as ServicesIndexImport } from './routes/services/index' import { Route as SecretsIndexImport } from './routes/secrets/index' @@ -44,6 +45,12 @@ const UpstreamsIndexRoute = UpstreamsIndexImport.update({ getParentRoute: () => rootRoute, } as any) +const StreamroutesIndexRoute = StreamroutesIndexImport.update({ + id: '/stream_routes/', + path: '/stream_routes/', + getParentRoute: () => rootRoute, +} as any) + const SslsIndexRoute = SslsIndexImport.update({ id: '/ssls/', path: '/ssls/', @@ -235,6 +242,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof SslsIndexImport parentRoute: typeof rootRoute } + '/stream_routes/': { + id: '/stream_routes/' + path: '/stream_routes' + fullPath: '/stream_routes' + preLoaderRoute: typeof StreamroutesIndexImport + parentRoute: typeof rootRoute + } '/upstreams/': { id: '/upstreams/' path: '/upstreams' @@ -289,6 +303,7 @@ export interface FileRoutesByFullPath { '/secrets': typeof SecretsIndexRoute '/services': typeof ServicesIndexRoute '/ssls': typeof SslsIndexRoute + '/stream_routes': typeof StreamroutesIndexRoute '/upstreams': typeof UpstreamsIndexRoute '/global_rules/detail/$id': typeof GlobalrulesDetailIdRoute '/protos/detail/$id': typeof ProtosDetailIdRoute @@ -310,6 +325,7 @@ export interface FileRoutesByTo { '/secrets': typeof SecretsIndexRoute '/services': typeof ServicesIndexRoute '/ssls': typeof SslsIndexRoute + '/stream_routes': typeof StreamroutesIndexRoute '/upstreams': typeof UpstreamsIndexRoute '/global_rules/detail/$id': typeof GlobalrulesDetailIdRoute '/protos/detail/$id': typeof ProtosDetailIdRoute @@ -332,6 +348,7 @@ export interface FileRoutesById { '/secrets/': typeof SecretsIndexRoute '/services/': typeof ServicesIndexRoute '/ssls/': typeof SslsIndexRoute + '/stream_routes/': typeof StreamroutesIndexRoute '/upstreams/': typeof UpstreamsIndexRoute '/global_rules/detail/$id': typeof GlobalrulesDetailIdRoute '/protos/detail/$id': typeof ProtosDetailIdRoute @@ -355,6 +372,7 @@ export interface FileRouteTypes { | '/secrets' | '/services' | '/ssls' + | '/stream_routes' | '/upstreams' | '/global_rules/detail/$id' | '/protos/detail/$id' @@ -375,6 +393,7 @@ export interface FileRouteTypes { | '/secrets' | '/services' | '/ssls' + | '/stream_routes' | '/upstreams' | '/global_rules/detail/$id' | '/protos/detail/$id' @@ -395,6 +414,7 @@ export interface FileRouteTypes { | '/secrets/' | '/services/' | '/ssls/' + | '/stream_routes/' | '/upstreams/' | '/global_rules/detail/$id' | '/protos/detail/$id' @@ -417,6 +437,7 @@ export interface RootRouteChildren { SecretsIndexRoute: typeof SecretsIndexRoute ServicesIndexRoute: typeof ServicesIndexRoute SslsIndexRoute: typeof SslsIndexRoute + StreamroutesIndexRoute: typeof StreamroutesIndexRoute UpstreamsIndexRoute: typeof UpstreamsIndexRoute GlobalrulesDetailIdRoute: typeof GlobalrulesDetailIdRoute ProtosDetailIdRoute: typeof ProtosDetailIdRoute @@ -438,6 +459,7 @@ const rootRouteChildren: RootRouteChildren = { SecretsIndexRoute: SecretsIndexRoute, ServicesIndexRoute: ServicesIndexRoute, SslsIndexRoute: SslsIndexRoute, + StreamroutesIndexRoute: StreamroutesIndexRoute, UpstreamsIndexRoute: UpstreamsIndexRoute, GlobalrulesDetailIdRoute: GlobalrulesDetailIdRoute, ProtosDetailIdRoute: ProtosDetailIdRoute, @@ -468,6 +490,7 @@ export const routeTree = rootRoute "/secrets/", "/services/", "/ssls/", + "/stream_routes/", "/upstreams/", "/global_rules/detail/$id", "/protos/detail/$id", @@ -514,6 +537,9 @@ export const routeTree = rootRoute "/ssls/": { "filePath": "ssls/index.tsx" }, + "/stream_routes/": { + "filePath": "stream_routes/index.tsx" + }, "/upstreams/": { "filePath": "upstreams/index.tsx" }, diff --git a/src/routes/stream_routes/index.tsx b/src/routes/stream_routes/index.tsx new file mode 100644 index 000000000..6682a5fda --- /dev/null +++ b/src/routes/stream_routes/index.tsx @@ -0,0 +1,127 @@ +import { queryClient } from '@/config/global'; +import { useSuspenseQuery } from '@tanstack/react-query'; +import { createFileRoute } from '@tanstack/react-router'; +import { useTranslation } from 'react-i18next'; +import type { APISIXType } from '@/types/schema/apisix'; +import { ProTable } from '@ant-design/pro-components'; +import type { ProColumns } from '@ant-design/pro-components'; +import { useEffect, useMemo } from 'react'; +import { ToDetailPageBtn, ToAddPageBtn } from '@/components/page/ToAddPageBtn'; +import { pageSearchSchema } from '@/types/schema/pageSearch'; +import { getStreamRouteListQueryOptions } from '@/apis/stream_routes'; +import { usePagination } from '@/utils/usePagination'; +import { AntdConfigProvider } from '@/config/antdConfigProvider'; +import PageHeader from '@/components/page/PageHeader'; + +const StreamRouteList = () => { + const { pagination, handlePageChange, updateTotal } = usePagination({ + queryKey: 'stream_routes', + }); + + const query = useSuspenseQuery(getStreamRouteListQueryOptions(pagination)); + const { data, isLoading } = query; + const { t } = useTranslation(); + + useEffect(() => { + if (data?.total) { + updateTotal(data.total); + } + }, [data?.total, updateTotal]); + + const columns = useMemo< + ProColumns<APISIXType['RespStreamRouteItem']>[] + >(() => { + return [ + { + dataIndex: ['value', 'id'], + title: 'ID', + key: 'id', + valueType: 'text', + }, + { + dataIndex: ['value', 'name'], + title: t('form.basic.name'), + key: 'name', + valueType: 'text', + }, + { + dataIndex: ['value', 'desc'], + title: t('form.basic.desc'), + key: 'desc', + valueType: 'text', + }, + { + title: t('actions'), + valueType: 'option', + key: 'option', + width: 120, + render: (_, record) => [ + <ToDetailPageBtn + key="detail" + to="/routes/detail/$id" + id={record.value.id} + />, + ], + }, + ]; + }, [t]); + + return ( + <AntdConfigProvider> + <ProTable + columns={columns} + dataSource={data.list} + rowKey="id" + loading={isLoading} + search={false} + options={false} + pagination={{ + current: pagination.page, + pageSize: pagination.pageSize, + total: pagination.total, + showSizeChanger: true, + onChange: handlePageChange, + }} + cardProps={{ bodyStyle: { padding: 0 } }} + toolbar={{ + menu: { + type: 'inline', + items: [ + { + key: 'add', + label: ( + <ToAddPageBtn + key="add" + label={t('streamRoutes.add.title')} + to="/routes/add" + /> + ), + }, + ], + }, + }} + /> + </AntdConfigProvider> + ); +}; + +function StreamRouteComponent() { + const { t } = useTranslation(); + + return ( + <> + <PageHeader title={t('streamRoutes.title')} /> + <AntdConfigProvider> + <StreamRouteList /> + </AntdConfigProvider> + </> + ); +} + +export const Route = createFileRoute('/stream_routes/')({ + component: StreamRouteComponent, + validateSearch: pageSearchSchema, + loaderDeps: ({ search }) => search, + loader: ({ deps }) => + queryClient.ensureQueryData(getStreamRouteListQueryOptions(deps)), +}); diff --git a/src/types/schema/apisix/type.ts b/src/types/schema/apisix/type.ts index 90e77fbcc..d85fc71dd 100644 --- a/src/types/schema/apisix/type.ts +++ b/src/types/schema/apisix/type.ts @@ -21,6 +21,13 @@ export type APISIXType = RawAPISIXType & { RespRouteList: AxiosResponse<APISIXListResponse<APISIXType['Route']>>; RespRouteItem: APISIXType['RespRouteList']['data']['list'][number]; RespRouteDetail: AxiosResponse<APISIXDetailResponse<APISIXType['Route']>>; + RespStreamRouteList: AxiosResponse< + APISIXListResponse<APISIXType['StreamRoute']> + >; + RespStreamRouteItem: APISIXType['RespRouteList']['data']['list'][number]; + RespStreamRouteDetail: AxiosResponse< + APISIXDetailResponse<APISIXType['StreamRoute']> + >; RespUpstreamList: AxiosResponse<APISIXListResponse<APISIXType['Upstream']>>; RespUpstreamItem: APISIXType['RespUpstreamList']['data']['list'][number]; RespUpstreamDetail: AxiosResponse<
