mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(app): app service form to react [EE-5415] (#8994)
This commit is contained in:
parent
2d05103fed
commit
69776b4863
26 changed files with 1224 additions and 538 deletions
|
@ -4,6 +4,7 @@ import { UISref, UISrefProps } from '@uirouter/react';
|
|||
interface Props {
|
||||
title?: string;
|
||||
target?: AnchorHTMLAttributes<HTMLAnchorElement>['target'];
|
||||
rel?: AnchorHTMLAttributes<HTMLAnchorElement>['rel'];
|
||||
}
|
||||
|
||||
export function Link({
|
||||
|
@ -16,7 +17,7 @@ export function Link({
|
|||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
<UISref className={className} {...props}>
|
||||
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
||||
<a title={title} target={props.target}>
|
||||
<a title={title} target={props.target} rel={props.rel}>
|
||||
{children}
|
||||
</a>
|
||||
</UISref>
|
||||
|
|
|
@ -18,6 +18,7 @@ interface Props<T> {
|
|||
size?: Size;
|
||||
disabled?: boolean;
|
||||
readOnly?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ButtonSelector<T extends string | number>({
|
||||
|
@ -27,9 +28,10 @@ export function ButtonSelector<T extends string | number>({
|
|||
options,
|
||||
disabled,
|
||||
readOnly,
|
||||
className,
|
||||
}: Props<T>) {
|
||||
return (
|
||||
<ButtonGroup size={size} className={styles.group}>
|
||||
<ButtonGroup size={size} className={clsx(styles.group, className)}>
|
||||
{options.map((option) => (
|
||||
<OptionItem
|
||||
key={option.value}
|
||||
|
|
|
@ -13,7 +13,7 @@ export function FormError({ children, className }: PropsWithChildren<Props>) {
|
|||
<p
|
||||
className={clsx(`text-muted small vertical-center help-block`, className)}
|
||||
>
|
||||
<Icon icon={AlertTriangle} className="icon-warning" />
|
||||
<Icon icon={AlertTriangle} className="icon-warning shrink-0" />
|
||||
<span className="text-warning">{children}</span>
|
||||
</p>
|
||||
);
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
import { ComponentType, PropsWithChildren } from 'react';
|
||||
import clsx from 'clsx';
|
||||
|
||||
import { useInputGroupContext } from './InputGroup';
|
||||
|
||||
type BaseProps<TProps> = {
|
||||
as?: ComponentType<TProps> | string;
|
||||
required?: boolean;
|
||||
};
|
||||
|
||||
export function InputGroupAddon<TProps>({
|
||||
children,
|
||||
as = 'span',
|
||||
required,
|
||||
...props
|
||||
}: PropsWithChildren<{ as?: ComponentType<TProps> | string } & TProps>) {
|
||||
}: PropsWithChildren<BaseProps<TProps> & TProps>) {
|
||||
useInputGroupContext();
|
||||
const Component = as as 'span';
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
<Component className="input-group-addon" {...props}>
|
||||
<Component
|
||||
className={clsx('input-group-addon', required && 'required')}
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
|
|
|
@ -3,7 +3,8 @@ import { SchemaOf } from 'yup';
|
|||
|
||||
export async function validateForm<T>(
|
||||
schemaBuilder: () => SchemaOf<T>,
|
||||
formValues: T
|
||||
formValues: T,
|
||||
validationContext?: object
|
||||
) {
|
||||
const validationSchema = schemaBuilder();
|
||||
|
||||
|
@ -11,6 +12,8 @@ export async function validateForm<T>(
|
|||
await validationSchema.validate(formValues, {
|
||||
strict: true,
|
||||
abortEarly: false,
|
||||
// workaround to access all parents for nested fields. See clusterIpFormValidation for a use case.
|
||||
context: { formValues, validationContext },
|
||||
});
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue