fix(wizard): update nodeport placeholder [r8s-62] (#12255)

pull/12259/head
Ali 2024-09-25 11:36:50 +12:00 committed by GitHub
parent b8b46ec129
commit db616bc8a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 12 deletions

View File

@ -1,20 +1,28 @@
import { useState } from 'react';
import { Environment } from '@/react/portainer/environments/types'; import { Environment } from '@/react/portainer/environments/types';
import { AgentForm } from '../shared/AgentForm'; import { AgentForm } from '../shared/AgentForm';
import { DeploymentScripts } from './DeploymentScripts'; import { deployments, DeploymentScripts } from './DeploymentScripts';
interface Props { interface Props {
onCreate(environment: Environment): void; onCreate(environment: Environment): void;
} }
export function AgentPanel({ onCreate }: Props) { export function AgentPanel({ onCreate }: Props) {
const [deployType, setDeployType] = useState(deployments[0].id);
const defaultPort = deployType === 'k8sNodePort' ? '30778' : '9001';
return ( return (
<> <>
<DeploymentScripts /> <DeploymentScripts
deployType={deployType}
setDeployType={setDeployType}
/>
<div className="mt-5"> <div className="mt-5">
<AgentForm onCreate={onCreate} /> {' '}
<AgentForm onCreate={onCreate} envDefaultPort={defaultPort} />
</div> </div>
</> </>
); );

View File

@ -1,4 +1,3 @@
import { useState } from 'react';
import { Info } from 'lucide-react'; import { Info } from 'lucide-react';
import { getAgentShortVersion } from '@/portainer/views/endpoints/helpers'; import { getAgentShortVersion } from '@/portainer/views/endpoints/helpers';
@ -11,7 +10,7 @@ import { NavTabs } from '@@/NavTabs';
import { Icon } from '@@/Icon'; import { Icon } from '@@/Icon';
import { NavContainer } from '@@/NavTabs/NavContainer'; import { NavContainer } from '@@/NavTabs/NavContainer';
const deployments = [ export const deployments = [
{ {
id: 'k8sLoadBalancer', id: 'k8sLoadBalancer',
label: 'Kubernetes via load balancer', label: 'Kubernetes via load balancer',
@ -26,9 +25,13 @@ const deployments = [
}, },
]; ];
export function DeploymentScripts() { export function DeploymentScripts({
const [deployType, setDeployType] = useState(deployments[0].id); deployType,
setDeployType,
}: {
deployType: string;
setDeployType: (id: string) => void;
}) {
const agentDetailsQuery = useAgentDetails(); const agentDetailsQuery = useAgentDetails();
if (!agentDetailsQuery) { if (!agentDetailsQuery) {

View File

@ -17,6 +17,7 @@ import { useValidation } from './AgentForm.validation';
interface Props { interface Props {
onCreate(environment: Environment): void; onCreate(environment: Environment): void;
envDefaultPort?: string;
} }
const initialValues: CreateAgentEnvironmentValues = { const initialValues: CreateAgentEnvironmentValues = {
@ -28,7 +29,7 @@ const initialValues: CreateAgentEnvironmentValues = {
}, },
}; };
export function AgentForm({ onCreate }: Props) { export function AgentForm({ onCreate, envDefaultPort }: Props) {
const [formKey, clearForm] = useReducer((state) => state + 1, 0); const [formKey, clearForm] = useReducer((state) => state + 1, 0);
const mutation = useCreateAgentEnvironmentMutation(); const mutation = useCreateAgentEnvironmentMutation();
@ -45,7 +46,7 @@ export function AgentForm({ onCreate }: Props) {
{({ isValid, dirty }) => ( {({ isValid, dirty }) => (
<Form> <Form>
<NameField /> <NameField />
<EnvironmentUrlField /> <EnvironmentUrlField placeholderPort={envDefaultPort} />
<MoreSettingsSection /> <MoreSettingsSection />

View File

@ -3,7 +3,11 @@ import { Field, useField } from 'formik';
import { FormControl } from '@@/form-components/FormControl'; import { FormControl } from '@@/form-components/FormControl';
import { Input } from '@@/form-components/Input'; import { Input } from '@@/form-components/Input';
export function EnvironmentUrlField() { export function EnvironmentUrlField({
placeholderPort = '9001',
}: {
placeholderPort?: string;
}) {
const [, meta] = useField('environmentUrl'); const [, meta] = useField('environmentUrl');
return ( return (
@ -18,7 +22,7 @@ export function EnvironmentUrlField() {
id="environment-url-field" id="environment-url-field"
name="environmentUrl" name="environmentUrl"
as={Input} as={Input}
placeholder="e.g. 10.0.0.10:9001 or tasks.portainer_agent:9001" placeholder={`e.g. 10.0.0.10:${placeholderPort} or tasks.portainer_agent:${placeholderPort}`}
data-cy="endpointCreate-endpointUrlAgentInput" data-cy="endpointCreate-endpointUrlAgentInput"
/> />
</FormControl> </FormControl>