Skip to content
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

feat(pci-load-balancer): add edit pool member name modal #13617

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const renderComponent = (props: ManagerButtonProps) => {
return render(<ManagerButton {...props} />);
};

const mockedHook =
useAuthorizationIam as unknown as jest.Mock<IamAuthorizationResponse>;
const mockedHook = (useAuthorizationIam as unknown) as jest.Mock<
IamAuthorizationResponse
>;

describe('ManagerButton tests', () => {
afterEach(() => {
Expand All @@ -27,7 +28,8 @@ describe('ManagerButton tests', () => {
isFetched: true,
});
renderComponent({
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
urn:
'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: [
'manager-react-components:apiovh:manager-react-components/attach-action',
],
Expand All @@ -43,7 +45,8 @@ describe('ManagerButton tests', () => {
isFetched: true,
});
renderComponent({
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
urn:
'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: [
'manager-react-components:apiovh:manager-react-components/attach',
],
Expand All @@ -64,7 +67,8 @@ describe('ManagerButton tests', () => {
isFetched: true,
});
renderComponent({
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
urn:
'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: [
'manager-react-components:apiovh:manager-react-components/attach-action',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jest.mock('../../hooks/iam');
const renderComponent = (props: ManagerTextProps) => {
return render(<ManagerText {...props} />);
};
const mockedHook =
useAuthorizationIam as unknown as jest.Mock<IamAuthorizationResponse>;
const mockedHook = (useAuthorizationIam as unknown) as jest.Mock<
IamAuthorizationResponse
>;

describe('ManagerText tests', () => {
afterEach(() => {
Expand All @@ -26,7 +27,8 @@ describe('ManagerText tests', () => {
isFetched: true,
});
renderComponent({
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
urn:
'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: [
'manager-react-components:apiovh:manager-react-components/get-display',
],
Expand All @@ -43,7 +45,8 @@ describe('ManagerText tests', () => {
isFetched: true,
});
renderComponent({
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
urn:
'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: [
'manager-react-components:apiovh:manager-react-components/get-display',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { useAuthorizationIam } from '../../../hooks/iam';

jest.mock('../../../hooks/iam');

const mockedHook =
useAuthorizationIam as unknown as jest.Mock<IamAuthorizationResponse>;
const mockedHook = (useAuthorizationIam as unknown) as jest.Mock<
IamAuthorizationResponse
>;

describe('Headers component', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ const actionItems: ActionMenuProps = {
const setupSpecTest = async (customProps?: Partial<ActionMenuProps>) =>
waitFor(() => render(<ActionMenu {...actionItems} {...customProps} />));

const mockedHook =
useAuthorizationIam as unknown as jest.Mock<IamAuthorizationResponse>;
const mockedHook = (useAuthorizationIam as unknown) as jest.Mock<
IamAuthorizationResponse
>;

describe('ActionMenu', () => {
it('renders menu actions correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Manuell hinzufügen",
"octavia_load_balancer_pools_detail_members_create_description": "Fügen Sie ein Mitglied manuell hinzu, wenn es nicht in der Tabelle der verfügbaren Instanzen aufgeführt ist.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Abbrechen",
"octavia_load_balancer_pools_detail_members_create_confirm": "Hinzufügen",
"octavia_load_balancer_pools_detail_members_create_name_label": "Name (optional)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "IP-Adresse",
"octavia_load_balancer_pools_detail_members_create_port_label": "Port"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Add Manually",
"octavia_load_balancer_pools_detail_members_create_description": "Manually add a member if it is not found in the available instances table.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Cancel",
"octavia_load_balancer_pools_detail_members_create_confirm": "Add",
"octavia_load_balancer_pools_detail_members_create_name_label": "Surname (optional)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "IP address",
"octavia_load_balancer_pools_detail_members_create_port_label": "Port"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Añadir manualmente",
"octavia_load_balancer_pools_detail_members_create_description": "Añadir un miembro manualmente si no aparece en la tabla de instancias disponibles.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Cancelar",
"octavia_load_balancer_pools_detail_members_create_confirm": "Añadir",
"octavia_load_balancer_pools_detail_members_create_name_label": "Nombre (opcional)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "Dirección IP",
"octavia_load_balancer_pools_detail_members_create_port_label": "Puerto"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Ajouter Manuellement",
"octavia_load_balancer_pools_detail_members_create_description": "Ajouter un membre manuellement s'il est introuvable dans le tableau des instances disponibles.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Annuler",
"octavia_load_balancer_pools_detail_members_create_confirm": "Ajouter",
"octavia_load_balancer_pools_detail_members_create_name_label": "Nom (optionnel)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "Adresse IP",
"octavia_load_balancer_pools_detail_members_create_port_label": "Port"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Ajouter Manuellement",
"octavia_load_balancer_pools_detail_members_create_description": "Ajouter un membre manuellement s'il est introuvable dans le tableau des instances disponibles.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Annuler",
"octavia_load_balancer_pools_detail_members_create_confirm": "Ajouter",
"octavia_load_balancer_pools_detail_members_create_name_label": "Nom (optionnel)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "Adresse IP",
"octavia_load_balancer_pools_detail_members_create_port_label": "Port"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Aggiungi manualmente",
"octavia_load_balancer_pools_detail_members_create_description": "Aggiungi un membro manualmente se non riesci a trovarlo nella tabella delle istanze disponibili.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Annullare",
"octavia_load_balancer_pools_detail_members_create_confirm": "Aggiungi",
"octavia_load_balancer_pools_detail_members_create_name_label": "Nome (facoltativo)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "Indirizzo IP",
"octavia_load_balancer_pools_detail_members_create_port_label": "Porta"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Dodaj ręcznie",
"octavia_load_balancer_pools_detail_members_create_description": "Jeśli użytkownika nie ma w tabeli dostępnych instancji, dodaj go ręcznie.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Anuluj",
"octavia_load_balancer_pools_detail_members_create_confirm": "Dodaj",
"octavia_load_balancer_pools_detail_members_create_name_label": "Nazwa (opcjonalnie)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "Adres IP",
"octavia_load_balancer_pools_detail_members_create_port_label": "Port"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"octavia_load_balancer_pools_detail_members_create_title": "Adicionar Manualmente",
"octavia_load_balancer_pools_detail_members_create_description": "Adicionar um membro manualmente, se não for possível encontrá-lo na tabela das instâncias disponíveis.",
"octavia_load_balancer_pools_detail_members_create_cancel": "Anular",
"octavia_load_balancer_pools_detail_members_create_confirm": "Adicionar",
"octavia_load_balancer_pools_detail_members_create_name_label": "Sobrenome (facultativo)",
"octavia_load_balancer_pools_detail_members_create_address_ip_label": "Endereço IP",
"octavia_load_balancer_pools_detail_members_create_port_label": "Porta"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Den Namen Ihres Mitglieds ändern",
"octavia_load_balancer_pools_members_edit_name_label": "Name",
"octavia_load_balancer_pools_members_edit_name_cancel": "Abbrechen",
"octavia_load_balancer_pools_members_edit_name_confirm": "Ändern"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Change your member’s name",
"octavia_load_balancer_pools_members_edit_name_label": "Name",
"octavia_load_balancer_pools_members_edit_name_cancel": "Cancel",
"octavia_load_balancer_pools_members_edit_name_confirm": "Edit"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Cambiar el nombre de su miembro",
"octavia_load_balancer_pools_members_edit_name_label": "Nombre",
"octavia_load_balancer_pools_members_edit_name_cancel": "Cancelar",
"octavia_load_balancer_pools_members_edit_name_confirm": "Editar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Modifier le nom de votre membre",
"octavia_load_balancer_pools_members_edit_name_label": "Nom",
"octavia_load_balancer_pools_members_edit_name_cancel": "Annuler",
"octavia_load_balancer_pools_members_edit_name_confirm": "Modifier"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Modifier le nom de votre membre",
"octavia_load_balancer_pools_members_edit_name_label": "Nom",
"octavia_load_balancer_pools_members_edit_name_cancel": "Annuler",
"octavia_load_balancer_pools_members_edit_name_confirm": "Modifier"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Modifica il nome del membro",
"octavia_load_balancer_pools_members_edit_name_label": "Nome",
"octavia_load_balancer_pools_members_edit_name_cancel": "Annullare",
"octavia_load_balancer_pools_members_edit_name_confirm": "Modificare"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Zmień nazwę użytkownika",
"octavia_load_balancer_pools_members_edit_name_label": "Nazwa",
"octavia_load_balancer_pools_members_edit_name_cancel": "Anuluj",
"octavia_load_balancer_pools_members_edit_name_confirm": "Zmień"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_members_edit_name_title": "Alterar o nome do seu membro",
"octavia_load_balancer_pools_members_edit_name_label": "Nome",
"octavia_load_balancer_pools_members_edit_name_cancel": "Anular",
"octavia_load_balancer_pools_members_edit_name_confirm": "Alterar"
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,34 @@ export const getPoolMember = async (
);
return data;
};

export const updatePoolMemberName = async (
projectId: string,
region: string,
poolId: string,
memberId: string,
name: string,
) => {
const { data } = await v6.put(
`/cloud/project/${projectId}/region/${region}/loadbalancing/pool/${poolId}/member/${memberId}`,
{
name,
},
);
return data;
};

export const createPoolMembers = async (
projectId: string,
region: string,
poolId: string,
members: TPoolMember[],
) => {
const { data } = await v6.post(
`/cloud/project/${projectId}/region/${region}/loadbalancing/pool/${poolId}/member`,
{
members,
},
);
return data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { useMutation, useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';
import {
TPoolMember,
createPoolMembers,
deletePoolMember,
getPoolMember,
getPoolMembers,
updatePoolMemberName,
} from '@/api/data/pool-member';
import { paginateResults, sortResults } from '@/helpers';
import queryClient from '@/queryClient';
Expand Down Expand Up @@ -102,3 +104,71 @@ export const useGetPoolMember = (
queryKey: ['poolMembers', projectId, poolId, region, memberId],
queryFn: () => getPoolMember(projectId, region, poolId, memberId),
});

type UpdatePoolMemberProps = {
projectId: string;
poolId: string;
memberId: string;
region: string;
name: string;
onError: (cause: Error) => void;
onSuccess: () => void;
};

export const useUpdatePoolMember = ({
projectId,
poolId,
memberId,
region,
name,
onError,
onSuccess,
}: UpdatePoolMemberProps) => {
const mutation = useMutation({
mutationFn: async () =>
updatePoolMemberName(projectId, region, poolId, memberId, name),
onError,
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['poolMembers', projectId],
});
onSuccess();
},
});
return {
updatePoolMemberName: () => mutation.mutate(),
...mutation,
};
};

type CreatePoolMembersProps = {
projectId: string;
poolId: string;
region: string;
onError: (cause: Error) => void;
onSuccess: () => void;
};

export const useCreatePoolMembers = ({
projectId,
poolId,
region,
onError,
onSuccess,
}: CreatePoolMembersProps) => {
const mutation = useMutation({
mutationFn: async (members: TPoolMember[]) =>
createPoolMembers(projectId, region, poolId, members),
onError,
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['poolMembers', projectId],
});
onSuccess();
},
});
return {
createPoolMembers: (members: TPoolMember[]) => mutation.mutate(members),
...mutation,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function ActionsComponent({
const items = [
{
id: 0,
href: useHref(`../${memberId}/edit`),
href: useHref(`./${memberId}/edit`),
label: t('octavia_load_balancer_pools_detail_members_edit'),
},
{
Expand Down
4 changes: 4 additions & 0 deletions packages/manager/apps/pci-load-balancer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,7 @@ export const VALUE_REGEX_BY_TYPE = {
};

export const KEY_REGEX = "^[a-zA-Z0-9!#$%&'*+-.^_`|~]+$";

export const REGEX = {
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
};
Loading
Loading