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:
parent
ccd2fee4ee
commit
6d26c79fa7
@ -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;
|
||||||
};
|
};
|
||||||
|
@ -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('');
|
||||||
|
@ -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)}'`;
|
||||||
|
@ -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();
|
||||||
|
@ -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,
|
||||||
);
|
);
|
||||||
|
@ -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,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user