1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

chore: Move actions inside projects (#6191)

## About the changes
Action should be relative to a project (in general).
This commit is contained in:
Gastón Fournier 2024-02-12 09:26:05 +01:00 committed by GitHub
parent ccd2fee4ee
commit 6d26c79fa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 19 deletions

View File

@ -99,6 +99,8 @@ export const useIncomingWebhooksForm = (incomingWebhook?: IIncomingWebhook) => {
return false;
}
// TODO call backend to check if token name is unique
clearError(ErrorField.TOKEN_NAME);
return true;
};

View File

@ -3,6 +3,7 @@ import { IActionSet } from 'interfaces/action';
import { useEffect, useState } from 'react';
import { UIAction } from './ActionItem';
import { v4 as uuidv4 } from 'uuid';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
export enum ErrorField {
NAME = 'name',
@ -27,7 +28,8 @@ const DEFAULT_PROJECT_ACTIONS_FORM_ERRORS = {
export type ProjectActionsFormErrors = Record<ErrorField, string | undefined>;
export const useProjectActionsForm = (action?: IActionSet) => {
const { actions: actionSets } = useActions();
const projectId = useRequiredPathParam('projectId');
const { actions: actionSets } = useActions(projectId);
const [enabled, setEnabled] = useState(false);
const [name, setName] = useState('');

View File

@ -44,8 +44,8 @@ export const ProjectActionsModal = ({
setOpen,
}: IProjectActionsModalProps) => {
const projectId = useRequiredPathParam('projectId');
const { refetch } = useActions();
const { addActionSet, updateActionSet, loading } = useActionsApi();
const { refetch } = useActions(projectId);
const { addActionSet, updateActionSet, loading } = useActionsApi(projectId);
const { setToastData, setToastApiError } = useToast();
const { uiConfig } = useUiConfig();
@ -103,7 +103,9 @@ export const ProjectActionsModal = ({
const formatApiCode = () => `curl --location --request ${
editing ? 'PUT' : 'POST'
} '${uiConfig.unleashUrl}/api/admin/actions${editing ? `/${action.id}` : ''}' \\
} '${uiConfig.unleashUrl}/api/admin/projects/${projectId}/actions${
editing ? `/${action.id}` : ''
}' \\
--header 'Authorization: INSERT_API_KEY' \\
--header 'Content-Type: application/json' \\
--data-raw '${JSON.stringify(payload, undefined, 2)}'`;

View File

@ -22,6 +22,7 @@ import { ProjectActionsModal } from './ProjectActionsModal/ProjectActionsModal';
import { ProjectActionsDeleteDialog } from './ProjectActionsDeleteDialog';
import { useServiceAccounts } from 'hooks/api/getters/useServiceAccounts/useServiceAccounts';
import { useIncomingWebhooks } from 'hooks/api/getters/useIncomingWebhooks/useIncomingWebhooks';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
interface IProjectActionsTableProps {
modalOpen: boolean;
@ -40,8 +41,9 @@ export const ProjectActionsTable = ({
}: IProjectActionsTableProps) => {
const { setToastData, setToastApiError } = useToast();
const { actions, refetch } = useActions();
const { toggleActionSet, removeActionSet } = useActionsApi();
const projectId = useRequiredPathParam('projectId');
const { actions, refetch } = useActions(projectId);
const { toggleActionSet, removeActionSet } = useActionsApi(projectId);
const { incomingWebhooks } = useIncomingWebhooks();
const { serviceAccounts } = useServiceAccounts();

View File

@ -1,8 +1,6 @@
import { IAction, IActionSet } from 'interfaces/action';
import useAPI from '../useApi/useApi';
const ENDPOINT = 'api/admin/actions';
export type ActionPayload = Omit<
IAction,
'id' | 'createdAt' | 'createdByUserId'
@ -15,15 +13,16 @@ export type ActionSetPayload = Omit<
actions: ActionPayload[];
};
export const useActionsApi = () => {
export const useActionsApi = (project: string) => {
const { loading, makeRequest, createRequest, errors } = useAPI({
propagateErrors: true,
});
const endpoint = `api/admin/projects/${project}/actions`;
const addActionSet = async (actionSet: ActionSetPayload) => {
const requestId = 'addActionSet';
const req = createRequest(
ENDPOINT,
endpoint,
{
method: 'POST',
body: JSON.stringify(actionSet),
@ -41,7 +40,7 @@ export const useActionsApi = () => {
) => {
const requestId = 'updateActionSet';
const req = createRequest(
`${ENDPOINT}/${actionSetId}`,
`${endpoint}/${actionSetId}`,
{
method: 'PUT',
body: JSON.stringify(actionSet),
@ -55,7 +54,7 @@ export const useActionsApi = () => {
const enableActionSet = async (actionSetId: number) => {
const requestId = 'enableActionSet';
const req = createRequest(
`${ENDPOINT}/${actionSetId}/on`,
`${endpoint}/${actionSetId}/on`,
{
method: 'POST',
},
@ -68,7 +67,7 @@ export const useActionsApi = () => {
const disableActionSet = async (actionSetId: number) => {
const requestId = 'disableActionSet';
const req = createRequest(
`${ENDPOINT}/${actionSetId}/off`,
`${endpoint}/${actionSetId}/off`,
{
method: 'POST',
},
@ -89,7 +88,7 @@ export const useActionsApi = () => {
const removeActionSet = async (actionSetId: number) => {
const requestId = 'removeActionSet';
const req = createRequest(
`${ENDPOINT}/${actionSetId}`,
`${endpoint}/${actionSetId}`,
{ method: 'DELETE' },
requestId,
);

View File

@ -6,16 +6,16 @@ import useUiConfig from '../useUiConfig/useUiConfig';
import { IActionSet } from 'interfaces/action';
import { useUiFlag } from 'hooks/useUiFlag';
const ENDPOINT = 'api/admin/actions';
export const useActions = () => {
export const useActions = (project: string) => {
const { isEnterprise } = useUiConfig();
const actionsEnabled = useUiFlag('automatedActions');
const { data, error, mutate } = useConditionalSWR(
const { data, error, mutate } = useConditionalSWR<{
actions: IActionSet[];
}>(
isEnterprise() && actionsEnabled,
{ actions: [] },
formatApiPath(ENDPOINT),
formatApiPath(`api/admin/projects/${project}/actions`),
fetcher,
);