1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

refactor(edge/groups): migrate view to react [EE-2219] (#11758)
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled

This commit is contained in:
Chaim Lev-Ari 2024-06-02 15:43:37 +03:00 committed by GitHub
parent b7cde35c3d
commit 9c70a43ac3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 579 additions and 386 deletions

View file

@ -0,0 +1,10 @@
import { useRouter } from '@uirouter/react';
import { useEffect } from 'react';
export function Redirect({ to, params = {} }: { to: string; params?: object }) {
const router = useRouter();
useEffect(() => {
router.stateService.go(to, params);
}, [params, router.stateService, to]);
return null;
}

View file

@ -6,6 +6,7 @@ import { useCreateTagMutation, useTags } from '@/portainer/tags/queries';
import { Creatable, Select } from '@@/form-components/ReactSelect';
import { FormControl } from '@@/form-components/FormControl';
import { Link } from '@@/Link';
import { ArrayError } from '@@/form-components/InputList/InputList';
import { TagButton } from '../TagButton';
@ -13,6 +14,7 @@ interface Props {
value: TagId[];
allowCreate?: boolean;
onChange(value: TagId[]): void;
errors?: ArrayError<TagId[]>;
}
interface Option {
@ -20,7 +22,12 @@ interface Option {
label: string;
}
export function TagSelector({ value, allowCreate = false, onChange }: Props) {
export function TagSelector({
value,
allowCreate = false,
onChange,
errors,
}: Props) {
// change the struct because react-select has a bug with Creatable (https://github.com/JedWatson/react-select/issues/3417#issuecomment-461868989)
const tagsQuery = useTags({
select: (tags) => tags?.map((opt) => ({ label: opt.Name, value: opt.ID })),
@ -62,19 +69,29 @@ export function TagSelector({ value, allowCreate = false, onChange }: Props) {
<>
{value.length > 0 && (
<FormControl label="Selected tags">
{selectedTags.map((tag) => (
<TagButton
key={tag.value}
title="Remove tag"
value={tag.value}
label={tag.label}
onRemove={() => handleRemove(tag.value)}
/>
))}
<div data-cy="selected-tags">
{selectedTags.map((tag) => (
<TagButton
key={tag.value}
title="Remove tag"
value={tag.value}
label={tag.label}
onRemove={() => handleRemove(tag.value)}
/>
))}
</div>
</FormControl>
)}
<FormControl label="Tags" inputId="tags-selector">
<FormControl
label="Tags"
inputId="tags-selector"
errors={
typeof errors === 'string'
? errors
: errors?.map((e) => e?.toString())
}
>
<SelectComponent
inputId="tags-selector"
value={[] as { label: string; value: number }[]}

View file

@ -11,6 +11,7 @@ interface Props extends AutomationTestingProps {
loadingText: string;
isLoading: boolean;
isValid: boolean;
errors?: unknown;
}
export function FormActions({
@ -19,6 +20,7 @@ export function FormActions({
isLoading,
children,
isValid,
errors,
'data-cy': dataCy,
}: PropsWithChildren<Props>) {
return (
@ -35,6 +37,13 @@ export function FormActions({
>
{submitLabel}
</LoadingButton>
{!isValid && (
<div className="hidden" data-cy="errors">
{JSON.stringify(errors)}
</div>
)}
{children}
</div>
</div>