Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEN-1613]: delete destination #1672

Merged
merged 17 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f97a5a1
Merge pull request #4 from odigos-io/new-ui
BenElferink Oct 27, 2024
afa1268
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 27, 2024
536f32f
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
fa352be
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
a4f03d8
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
b3fa682
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
f0a397f
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
2c13a75
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
3ab5c0c
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
977c57b
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 30, 2024
d95b6fe
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 30, 2024
cde9bdd
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 31, 2024
7ca44f7
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 31, 2024
29d2e0d
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
39500a9
feat: delete destination
BenElferink Nov 3, 2024
5be5c7d
fix: types for CRUD hooks
BenElferink Nov 3, 2024
fcf6349
Merge branch 'new-ui' of https://github.com/odigos-io/odigos into gen…
BenElferink Nov 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DeleteEntityModal } from '@/components';
import { ActionDrawer, type ActionDrawerHandle } from '../../actions';
import { DestinationDrawer, type DestinationDrawerHandle } from '../../destinations';
import { RuleDrawer, RuleDrawerHandle } from '../../instrumentation-rules/rule-drawer-container';
import { useActionCRUD, useActualSources, useInstrumentationRuleCRUD, useUpdateDestination } from '@/hooks';
import { useActionCRUD, useActualSources, useDestinationCRUD, useInstrumentationRuleCRUD } from '@/hooks';
import { getMainContainerLanguageLogo, WORKLOAD_PROGRAMMING_LANGUAGES } from '@/utils/constants/programming-languages';
import {
WorkloadId,
Expand Down Expand Up @@ -40,7 +40,7 @@ const OverviewDrawer = () => {
const [title, setTitle] = useState('');

const { updateAction, deleteAction } = useActionCRUD();
const { updateExistingDestination } = useUpdateDestination();
const { updateDestination, deleteDestination } = useDestinationCRUD();
const { updateActualSource, deleteSourcesForNamespace } = useActualSources();
const { updateInstrumentationRule, deleteInstrumentationRule } = useInstrumentationRuleCRUD();

Expand Down Expand Up @@ -175,7 +175,7 @@ const OverviewDrawer = () => {
};

try {
await updateExistingDestination(id as string, payload);
await updateDestination(id as string, payload);
} catch (error) {
console.error('Error updating destination:', error);
}
Expand Down Expand Up @@ -217,7 +217,9 @@ const OverviewDrawer = () => {
}

if (type === OVERVIEW_ENTITY_TYPES.DESTINATION) {
alert('TODO !');
const { id } = item as ActualDestination;

await deleteDestination(id);
}

handleClose();
Expand Down Expand Up @@ -256,7 +258,7 @@ const OverviewDrawer = () => {
isModalOpen={isDeleteModalOpen}
handleDelete={handleDelete}
handleCloseModal={handleCloseDeleteModal}
description='Are you sure you want to delete this source?'
description='Are you sure you want to delete this?'
/>
</>
) : null;
Expand Down
29 changes: 6 additions & 23 deletions frontend/webapp/graphql/mutations/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,12 @@ export const UPDATE_DESTINATION = gql`
mutation UpdateDestination($id: ID!, $destination: DestinationInput!) {
updateDestination(id: $id, destination: $destination) {
id
name
exportedSignals {
traces
metrics
logs
}
fields
destinationType {
type
displayName
imageUrl
supportedSignals {
traces {
supported
}
metrics {
supported
}
logs {
supported
}
}
}
}
}
`;

export const DELETE_DESTINATION = gql`
mutation DeleteDestination($id: ID!) {
deleteDestination(id: $id)
}
`;
6 changes: 3 additions & 3 deletions frontend/webapp/hooks/actions/useActionCRUD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export const useActionCRUD = (params?: UseActionCrudParams) => {
params?.onSuccess?.();
};

const [createAction, cState] = useMutation(CREATE_ACTION, {
const [createAction, cState] = useMutation<{ createAction: { id: string } }>(CREATE_ACTION, {
onError: (error) => handleError('Create Action', error.message),
onCompleted: () => handleComplete('Create Action', 'successfully created'),
});
const [updateAction, uState] = useMutation(UPDATE_ACTION, {
const [updateAction, uState] = useMutation<{ updateAction: { id: string } }>(UPDATE_ACTION, {
onError: (error) => handleError('Update Action', error.message),
onCompleted: () => handleComplete('Update Action', 'successfully updated'),
});
const [deleteAction, dState] = useMutation(DELETE_ACTION, {
const [deleteAction, dState] = useMutation<{ deleteAction: boolean }>(DELETE_ACTION, {
onError: (error) => handleError('Delete Action', error.message),
onCompleted: () => handleComplete('Delete Action', 'successfully deleted'),
});
Expand Down
3 changes: 1 addition & 2 deletions frontend/webapp/hooks/destinations/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export * from './useDestinations';
export * from './useTestConnection';
export * from './useConnectDestinationForm';
export * from './useCreateDestination';
export * from './usePotentialDestinations';
export * from './useActualDestinations';
export * from './useUpdateDestination';
export * from './useDestinationCRUD';
export * from './useDestinationFormData';
export * from './useEditDestinationFormHandlers';
export * from './useDestinationTypes';
21 changes: 0 additions & 21 deletions frontend/webapp/hooks/destinations/useCreateDestination.ts

This file was deleted.

53 changes: 53 additions & 0 deletions frontend/webapp/hooks/destinations/useDestinationCRUD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useDrawerStore } from '@/store';
import { useNotify } from '../useNotify';
import { useMutation } from '@apollo/client';
import type { DestinationInput } from '@/types';
import { useComputePlatform } from '../compute-platform';
import { CREATE_DESTINATION, DELETE_DESTINATION, UPDATE_DESTINATION } from '@/graphql/mutations';

interface Params {
onSuccess?: () => void;
onError?: () => void;
}

export const useDestinationCRUD = (params?: Params) => {
const { setSelectedItem: setDrawerItem } = useDrawerStore((store) => store);
const { refetch } = useComputePlatform();
const notify = useNotify();

const notifyUser = (title: string, message: string, type: 'error' | 'success') => {
notify({ title, message, type, target: 'notification', crdType: 'notification' });
};

const handleError = (title: string, message: string) => {
notifyUser(title, message, 'error');
params?.onError?.();
};

const handleComplete = (title: string, message: string) => {
notifyUser(title, message, 'success');
setDrawerItem(null);
refetch();
params?.onSuccess?.();
};

const [createDestination, cState] = useMutation<{ createNewDestination: { id: string } }>(CREATE_DESTINATION, {
onError: (error) => handleError('Create Destination', error.message),
onCompleted: () => handleComplete('Create Destination', 'successfully created'),
});
const [updateDestination, uState] = useMutation<{ updateDestination: { id: string } }>(UPDATE_DESTINATION, {
onError: (error) => handleError('Update Destination', error.message),
onCompleted: () => handleComplete('Update Destination', 'successfully updated'),
});
const [deleteDestination, dState] = useMutation<{ deleteDestination: boolean }>(DELETE_DESTINATION, {
onError: (error) => handleError('Delete Destination', error.message),
onCompleted: () => handleComplete('Delete Destination', 'successfully deleted'),
});

return {
loading: cState.loading || uState.loading || dState.loading,
createDestination: (destination: DestinationInput) => createDestination({ variables: { destination } }),
updateDestination: (id: string, destination: DestinationInput) => updateDestination({ variables: { id, destination } }),
deleteDestination: (id: string) => deleteDestination({ variables: { id } }),
};
};
32 changes: 0 additions & 32 deletions frontend/webapp/hooks/destinations/useUpdateDestination.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export const useInstrumentationRuleCRUD = (params?: Params) => {
params?.onSuccess?.();
};

const [createInstrumentationRule, cState] = useMutation(CREATE_INSTRUMENTATION_RULE, {
const [createInstrumentationRule, cState] = useMutation<{ createInstrumentationRule: { ruleId: string } }>(CREATE_INSTRUMENTATION_RULE, {
onError: (error) => handleError('Create Rule', error.message),
onCompleted: () => handleComplete('Create Rule', 'successfully created'),
});
const [updateInstrumentationRule, uState] = useMutation(UPDATE_INSTRUMENTATION_RULE, {
const [updateInstrumentationRule, uState] = useMutation<{ updateInstrumentationRule: { ruleId: string } }>(UPDATE_INSTRUMENTATION_RULE, {
onError: (error) => handleError('Update Rule', error.message),
onCompleted: () => handleComplete('Update Rule', 'successfully updated'),
});
const [deleteInstrumentationRule, dState] = useMutation(DELETE_INSTRUMENTATION_RULE, {
const [deleteInstrumentationRule, dState] = useMutation<{ deleteInstrumentationRule: boolean }>(DELETE_INSTRUMENTATION_RULE, {
onError: (error) => handleError('Delete Rule', error.message),
onCompleted: () => handleComplete('Delete Rule', 'successfully deleted'),
});
Expand Down
26 changes: 8 additions & 18 deletions frontend/webapp/hooks/setup/useConnectEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ import { useAppStore } from '@/store';
import { DestinationInput } from '@/types';
import { useActualSources } from '../sources';
import { useState, useCallback } from 'react';
import { useCreateDestination } from '../destinations';
import { useDestinationCRUD } from '../destinations';

type ConnectEnvResult = {
success: boolean;
destinationId?: string;
};

export const useConnectEnv = () => {
const { createNewDestination } = useCreateDestination();
const { createSourcesForNamespace, persistNamespaceItems } =
useActualSources();
const { createDestination } = useDestinationCRUD();
const { createSourcesForNamespace, persistNamespaceItems } = useActualSources();

const [result, setResult] = useState<ConnectEnvResult | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

const sourcesList = useAppStore((state) => state.sources);
const resetSources = useAppStore((state) => state.resetSources);
const namespaceFutureSelectAppsList = useAppStore(
(state) => state.namespaceFutureSelectAppsList
);
const namespaceFutureSelectAppsList = useAppStore((state) => state.namespaceFutureSelectAppsList);

const connectEnv = useCallback(
async (destination: DestinationInput, callback?: () => void) => {
Expand All @@ -32,9 +29,7 @@ export const useConnectEnv = () => {

try {
// Persist namespaces based on namespaceFutureSelectAppsList
const namespaceItems = Object.entries(
namespaceFutureSelectAppsList
).map(([namespaceName, futureSelected]) => ({
const namespaceItems = Object.entries(namespaceFutureSelectAppsList).map(([namespaceName, futureSelected]) => ({
name: namespaceName,
futureSelected,
}));
Expand All @@ -54,7 +49,8 @@ export const useConnectEnv = () => {
resetSources();

// Create destination
const destinationId = await createNewDestination(destination);
const { data } = await createDestination(destination);
const destinationId = data?.createNewDestination.id;

if (!destinationId) {
throw new Error('Error creating destination.');
Expand All @@ -73,13 +69,7 @@ export const useConnectEnv = () => {
setLoading(false);
}
},
[
sourcesList,
createNewDestination,
persistNamespaceItems,
createSourcesForNamespace,
namespaceFutureSelectAppsList,
]
[sourcesList, createDestination, persistNamespaceItems, createSourcesForNamespace, namespaceFutureSelectAppsList]
);

return {
Expand Down
Loading