-
Notifications
You must be signed in to change notification settings - Fork 567
feat: route list, add page #3008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
71f0891
88ce0c3
ce1350d
c0b3b42
5a6892b
fe0335b
f89a91f
68d2a2d
52b44b3
b45f814
38c35af
d848b3d
44a33aa
8d9a67e
71c7e09
b5524ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { RoutePostType } from '@/components/form-slice/FormPartRoute/schema'; | ||
import { API_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 getRouteListQueryOptions = (props: PageSearchType) => { | ||
const { page, pageSize } = props; | ||
return queryOptions({ | ||
queryKey: ['routes', page, pageSize], | ||
queryFn: () => | ||
req | ||
.get<unknown, APISIXType['RespRouteList']>(API_ROUTES, { | ||
params: { page, page_size: pageSize }, | ||
}) | ||
.then((v) => v.data), | ||
}); | ||
}; | ||
|
||
export const postRouteReq = (data: RoutePostType) => | ||
req.post<unknown, APISIXType['RespRouteDetail']>(API_ROUTES, data); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { useFormContext } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { FormItemNumberInput } from '@/components/form/NumberInput'; | ||
import { FormItemSwitch } from '@/components/form/Switch'; | ||
import { FormItemTagsInput } from '@/components/form/TagInput'; | ||
import { FormItemTextarea } from '@/components/form/Textarea'; | ||
import { FormItemTextInput } from '@/components/form/TextInput'; | ||
import { NamePrefixProvider } from '@/utils/useNamePrefix'; | ||
import { FormItemPlugins } from '../FormItemPlugins'; | ||
import { FormPartBasic } from '../FormPartBasic'; | ||
import { FormPartUpstream, FormSectionTimeout } from '../FormPartUpstream'; | ||
import { FormSection } from '../FormSection'; | ||
import { Divider, InputWrapper } from '@mantine/core'; | ||
import type { RoutePostType } from './schema'; | ||
import { FormItemSelect } from '@/components/form/Select'; | ||
import { APISIX } from '@/types/schema/apisix'; | ||
import { zGetDefault } from '@/utils/zod'; | ||
|
||
const FormPartBasicWithPriority = () => { | ||
const { t } = useTranslation(); | ||
const { control } = useFormContext<RoutePostType>(); | ||
return ( | ||
<FormPartBasic> | ||
<FormItemNumberInput | ||
control={control} | ||
name="priority" | ||
label={t('form.route.priority')} | ||
juzhiyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultValue={zGetDefault(APISIX.Route).priority!} | ||
/> | ||
<FormItemSelect | ||
control={control} | ||
name="status" | ||
label={t('form.route.status')} | ||
data={APISIX.RouteStatus.options.map((v) => v.value.toString())} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After all pages are completed... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After all, it's strictly aligned with the API now. |
||
defaultValue={APISIX.RouteStatus.options[1].value.toString()} | ||
from={String} | ||
to={Number} | ||
/> | ||
</FormPartBasic> | ||
); | ||
}; | ||
|
||
const FormSectionMatchRules = () => { | ||
const { t } = useTranslation(); | ||
const { control } = useFormContext<RoutePostType>(); | ||
return ( | ||
<FormSection legend={t('form.route.matchRules')}> | ||
<FormItemTagsInput | ||
control={control} | ||
name="methods" | ||
label={t('form.route.methods')} | ||
data={APISIX.HttpMethod.options.map((v) => v.value)} | ||
searchValue="" | ||
/> | ||
<InputWrapper label={t('form.route.enableWebsocket')}> | ||
<FormItemSwitch control={control} name="enable_websocket" /> | ||
</InputWrapper> | ||
<FormItemTextInput | ||
control={control} | ||
name="uri" | ||
label={t('form.route.uri')} | ||
/> | ||
<FormItemTagsInput | ||
control={control} | ||
name="uris" | ||
label={t('form.route.uris')} | ||
/> | ||
<FormItemTextInput | ||
control={control} | ||
name="host" | ||
label={t('form.route.host')} | ||
/> | ||
<FormItemTagsInput | ||
control={control} | ||
name="hosts" | ||
label={t('form.route.hosts')} | ||
/> | ||
<FormItemTextInput | ||
control={control} | ||
name="remote_addr" | ||
label={t('form.route.remoteAddr')} | ||
/> | ||
<FormItemTagsInput | ||
control={control} | ||
name="remote_addrs" | ||
label={t('form.route.remoteAddrs')} | ||
/> | ||
<FormItemTagsInput | ||
control={control} | ||
name="vars" | ||
label={t('form.route.vars')} | ||
/> | ||
<FormItemTextarea | ||
control={control} | ||
name="filter_func" | ||
label={t('form.route.filterFunc')} | ||
/> | ||
</FormSection> | ||
); | ||
}; | ||
|
||
const FormSectionUpstream = () => { | ||
const { t } = useTranslation(); | ||
const { control } = useFormContext<RoutePostType>(); | ||
return ( | ||
<FormSection legend={t('form.upstream.title')}> | ||
<FormSection legend={t('form.upstream.upstreamId')}> | ||
<FormItemTextInput control={control} name="upstream_id" /> | ||
</FormSection> | ||
<Divider my="xs" label={t('or')} /> | ||
<NamePrefixProvider value="upstream"> | ||
<FormPartUpstream /> | ||
</NamePrefixProvider> | ||
</FormSection> | ||
); | ||
}; | ||
|
||
const FormSectionPlugins = () => { | ||
const { t } = useTranslation(); | ||
const { control } = useFormContext<RoutePostType>(); | ||
return ( | ||
<FormSection legend={t('form.plugins.label')}> | ||
<FormItemTextInput | ||
control={control} | ||
name="plugin_config_id" | ||
label={t('form.plugins.configId')} | ||
/> | ||
<Divider my="xs" label={t('or')} /> | ||
<FormItemPlugins name="plugins" /> | ||
</FormSection> | ||
); | ||
}; | ||
|
||
const FormSectionService = () => { | ||
const { t } = useTranslation(); | ||
const { control } = useFormContext<RoutePostType>(); | ||
return ( | ||
<FormSection legend={t('form.route.service')}> | ||
<FormItemTextInput | ||
control={control} | ||
name="service_id" | ||
label={t('form.upstream.serviceId')} | ||
/> | ||
</FormSection> | ||
); | ||
}; | ||
|
||
export const FormPartRoute = () => { | ||
return ( | ||
<> | ||
<FormPartBasicWithPriority /> | ||
<FormSectionMatchRules /> | ||
<FormSectionService /> | ||
<FormSectionTimeout /> | ||
<FormSectionUpstream /> | ||
<FormSectionPlugins /> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { APISIX } from '@/types/schema/apisix'; | ||
import type { z } from 'zod'; | ||
|
||
export const RoutePostSchema = APISIX.Route.omit({ | ||
id: true, | ||
create_time: true, | ||
update_time: true, | ||
}); | ||
|
||
export type RoutePostType = z.infer<typeof RoutePostSchema>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried it. I can only make it work by inputting
,
or by blurring it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enter should be able to work 🤔