1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-09 01:17:06 +02: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; return false;
} }
// TODO call backend to check if token name is unique
clearError(ErrorField.TOKEN_NAME); clearError(ErrorField.TOKEN_NAME);
return true; return true;
}; };

View File

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

View File

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

View File

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

View File

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

View File

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