Skip to content

Commit

Permalink
feat(pci-load-balancer): add edit page policy
Browse files Browse the repository at this point in the history
ref: DTCORE-2641
Signed-off-by: Yoann Fievez <[email protected]>
  • Loading branch information
kqesar committed Oct 9, 2024
1 parent a158b5d commit d2dbe0e
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 290 deletions.
20 changes: 20 additions & 0 deletions packages/manager/apps/pci-load-balancer/src/api/data/l7Policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,23 @@ export const createPolicy = async (
);
return data;
};

export const updatePolicy = async (
projectId: string,
region: string,
policy: TL7Policy,
) => {
const { data } = await v6.put(
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policy.id}`,
{
name: policy.name,
position: policy.position,
action: policy.action,
redirectHttpCode: policy.redirectHttpCode,
redirectPoolId: policy.redirectPoolId,
redirectPrefix: policy.redirectPrefix,
redirectUrl: policy.redirectUrl,
},
);
return data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getL7Policies,
getPolicy,
TL7Policy,
updatePolicy,
} from '@/api/data/l7Policies';
import { paginateResults, sortResults } from '@/helpers';
import { ACTION_LABELS, ACTIONS } from '@/constants';
Expand Down Expand Up @@ -112,7 +113,7 @@ export const useDeletePolicy = ({
onError,
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['l7Policies'],
queryKey: ['l7Policies', projectId],
});
onSuccess();
},
Expand All @@ -127,31 +128,60 @@ type CreatePolicyProps = {
projectId: string;
listenerId: string;
region: string;
policy: TL7Policy;
onError: (cause: Error) => void;
onSuccess: (newPolicy: TL7Policy) => void;
};

export const useCreatePolicy = ({
projectId,
listenerId,
policy,
region,
onError,
onSuccess,
}: CreatePolicyProps) => {
const mutation = useMutation<TL7Policy>({
mutationFn: async () => createPolicy(projectId, region, listenerId, policy),
const mutation = useMutation({
mutationFn: async (policy: TL7Policy) =>
createPolicy(projectId, region, listenerId, policy),
onError,
onSuccess: async (newPolicy) => {
await queryClient.invalidateQueries({
queryKey: ['l7Policies'],
queryKey: ['l7Policies', projectId],
});
onSuccess(newPolicy);
},
});
return {
createPolicy: () => mutation.mutate(),
createPolicy: (policy: TL7Policy) => mutation.mutate(policy),
...mutation,
};
};

type UpdatePolicyProps = {
projectId: string;
region: string;
onError: (cause: Error) => void;
onSuccess: (policy: TL7Policy) => void;
};

export const useUpdatePolicy = ({
projectId,
region,
onError,
onSuccess,
}: UpdatePolicyProps) => {
const mutation = useMutation({
mutationFn: async (policy: TL7Policy) =>
updatePolicy(projectId, region, policy),
onError,
onSuccess: async (policy: TL7Policy) => {
await queryClient.invalidateQueries({
queryKey: ['l7Policies', projectId],
});
onSuccess(policy);
},
});
return {
updatePolicy: (policy: TL7Policy) => mutation.mutate(policy),
...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: '',
href: useHref(`../${l7PoliciesId}/edit`),
label: t('octavia_load_balancer_list_l7_policies_actions_edit'),
},
{
Expand Down
Loading

0 comments on commit d2dbe0e

Please sign in to comment.