Skip to content

Commit

Permalink
feat(pci-load-balancer): add create member modal
Browse files Browse the repository at this point in the history
ref: DTCORE-2660
Signed-off-by: Yoann Fievez <[email protected]>
  • Loading branch information
kqesar committed Oct 18, 2024
1 parent 36c3d93 commit 345cbcf
Show file tree
Hide file tree
Showing 17 changed files with 339 additions and 13 deletions.
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
Expand Up @@ -65,3 +65,18 @@ export const updatePoolMemberName = async (
);
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,6 +4,7 @@ import { useMutation, useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';
import {
TPoolMember,
createPoolMembers,
deletePoolMember,
getPoolMember,
getPoolMembers,
Expand Down Expand Up @@ -139,3 +140,35 @@ export const useUpdatePoolMember = ({
...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,
};
};
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

0 comments on commit 345cbcf

Please sign in to comment.