diff --git a/docker-compose.yml b/docker-compose.yml index e9b36d0405a25..2e5b423854249 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,8 @@ services: - "./:/workspace" - "./public:/usr/share/grafana/public" - "./conf/grafana.local-dev.ini:/usr/share/grafana/conf/defaults.ini" + # pmm + # - "../pmm:/root/go/src/github.com/percona/pmm" ports: - 80:8080 - 443:8443 diff --git a/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/ExternalServiceConnectionDetails/ExternalServiceConnectionDetails.tsx b/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/ExternalServiceConnectionDetails/ExternalServiceConnectionDetails.tsx index 59a8703512e3d..b80ce5548b2d2 100644 --- a/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/ExternalServiceConnectionDetails/ExternalServiceConnectionDetails.tsx +++ b/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/ExternalServiceConnectionDetails/ExternalServiceConnectionDetails.tsx @@ -1,7 +1,6 @@ import React, { FC, useCallback, useEffect, useMemo } from 'react'; import { useStyles2 } from '@grafana/ui'; -import { NodesAgents } from 'app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents'; import { PasswordInputField } from 'app/percona/shared/components/Form/PasswordInput'; import { RadioButtonGroupField } from 'app/percona/shared/components/Form/RadioButtonGroup'; import { TextInputField } from 'app/percona/shared/components/Form/TextInput'; @@ -97,7 +96,6 @@ export const ExternalServiceConnectionDetails: FC = ({ form }) => />
-
= ({ form, r />
-
{ render(
( +

{values.node?.value}

{values.pmm_agent_id?.value}

@@ -134,4 +138,44 @@ describe('Nodes Agents:: ', () => { expect.anything() ); }); + + it("shouldn't change address on node change if already filled out", async () => { + jest + .spyOn(InventoryService, 'getNodes') + .mockReturnValue(Promise.resolve({ nodes: nodesMockMultipleAgentsNoPMMServer })); + + setup(); + await waitFor(() => { + expect(fetchNodesActionActionSpy).toHaveBeenCalled(); + }); + + const form = screen.getByTestId('node-agents-form'); + + const address = screen.getByTestId('address-field'); + fireEvent.change(address, { target: { value: 'some-address' } }); + + const nodesSelect = screen.getByLabelText('Nodes'); + await waitFor(() => + selectEvent.select(nodesSelect, [nodesMockMultipleAgentsNoPMMServer[0].node_name], { + container: document.body, + }) + ); + + const agentsSelect = screen.getByLabelText('Agents'); + await waitFor(() => + selectEvent.select(agentsSelect, nodesMockMultipleAgentsNoPMMServer[0].agents[0].agent_id, { + container: document.body, + }) + ); + + fireEvent.submit(form); + + expect(submitMock).toHaveBeenCalledWith( + expect.objectContaining({ + address: 'some-address', + }), + expect.anything(), + expect.anything() + ); + }); }); diff --git a/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents.tsx b/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents.tsx index 59a8dc550de77..e63447f677744 100644 --- a/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents.tsx +++ b/public/app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents.tsx @@ -39,10 +39,12 @@ export const NodesAgents: FC = ({ form }) => { }, []); const changeAgentValue = (value: AgentsOption) => { - if (value.label !== PMM_SERVER_NODE_AGENT_ID) { - form?.change('address', 'localhost'); - } else { - form?.change('address', ''); + if (!form?.getState().values?.address) { + if (value.label !== PMM_SERVER_NODE_AGENT_ID) { + form?.change('address', 'localhost'); + } else { + form?.change('address', ''); + } } }; @@ -57,13 +59,9 @@ export const NodesAgents: FC = ({ form }) => { } if (selectedAgent) { form?.change('pmm_agent_id', selectedAgent); - - if (selectedAgent.value !== PMM_SERVER_NODE_AGENT_ID) { - form?.change('address', 'localhost'); - } + changeAgentValue(selectedAgent); } else { form?.change('pmm_agent_id', undefined); - form?.change('address', ''); } }; diff --git a/public/app/percona/shared/core/reducers/nodes/nodes.utils.ts b/public/app/percona/shared/core/reducers/nodes/nodes.utils.ts index 19817dfd11a8b..43d728add1e49 100644 --- a/public/app/percona/shared/core/reducers/nodes/nodes.utils.ts +++ b/public/app/percona/shared/core/reducers/nodes/nodes.utils.ts @@ -56,14 +56,16 @@ export const nodeFromDbMapper = (nodeFromDb: NodeDB[]): Node[] => { }; export const nodesOptionsMapper = (nodeFromDb: NodeDB[]): NodesOption[] => - nodeFromDb.map((node) => { - const agents = (node.agents || []) - .filter((agent) => agent.agent_type === AgentType.pmmAgent) - .map((agent) => ({ value: agent.agent_id, label: agent.agent_id, key: agent.agent_type })); + nodeFromDb + .map((node) => { + const agents = (node.agents || []) + .filter((agent) => agent.agent_type === AgentType.pmmAgent) + .map((agent) => ({ value: agent.agent_id, label: agent.agent_id, key: agent.agent_type })); - return { - value: node.node_id, - label: node.node_name, - agents: agents, - }; - }); + return { + value: node.node_id, + label: node.node_name, + agents: agents, + }; + }) + .filter((node) => node.agents.length > 0);