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