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-1601]: refetch after create/update destination #1668

Merged
merged 15 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 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
16b9a41
fix: refetch after create destination
BenElferink Nov 3, 2024
08fb05d
fix: refetch after update destination
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 @@ -9,19 +9,8 @@ import { GET_DESTINATION_TYPE_DETAILS } from '@/graphql';
import { Body, Container, SideMenuWrapper } from '../styled';
import { Divider, SectionTitle } from '@/reuseable-components';
import { ConnectionNotification } from './connection-notification';
import {
useConnectDestinationForm,
useConnectEnv,
useDestinationFormData,
useEditDestinationFormHandlers,
} from '@/hooks';
import {
StepProps,
DestinationInput,
DestinationTypeItem,
DestinationDetailsResponse,
ConfiguredDestination,
} from '@/types';
import { useComputePlatform, useConnectDestinationForm, useConnectEnv, useDestinationFormData, useEditDestinationFormHandlers } from '@/hooks';
import { StepProps, DestinationInput, DestinationTypeItem, DestinationDetailsResponse, ConfiguredDestination } from '@/types';

const SIDE_MENU_DATA: StepProps[] = [
{
Expand All @@ -42,38 +31,24 @@ interface ConnectDestinationModalBodyProps {
onFormValidChange: (isValid: boolean) => void;
}

export function ConnectDestinationModalBody({
destination,
onSubmitRef,
onFormValidChange,
}: ConnectDestinationModalBodyProps) {
export function ConnectDestinationModalBody({ destination, onSubmitRef, onFormValidChange }: ConnectDestinationModalBodyProps) {
const [destinationName, setDestinationName] = useState<string>('');
const [showConnectionError, setShowConnectionError] = useState(false);

const {
dynamicFields,
exportedSignals,
setDynamicFields,
setExportedSignals,
} = useDestinationFormData();
const { dynamicFields, exportedSignals, setDynamicFields, setExportedSignals } = useDestinationFormData();

const { connectEnv } = useConnectEnv();
const { refetch } = useComputePlatform();
const { buildFormDynamicFields } = useConnectDestinationForm();

const { handleDynamicFieldChange, handleSignalChange } =
useEditDestinationFormHandlers(setExportedSignals, setDynamicFields);
const { handleDynamicFieldChange, handleSignalChange } = useEditDestinationFormHandlers(setExportedSignals, setDynamicFields);

const addConfiguredDestination = useAppStore(
({ addConfiguredDestination }) => addConfiguredDestination
);
const addConfiguredDestination = useAppStore(({ addConfiguredDestination }) => addConfiguredDestination);

const { data } = useQuery<DestinationDetailsResponse>(
GET_DESTINATION_TYPE_DETAILS,
{
variables: { type: destination?.type },
skip: !destination,
}
);
const { data } = useQuery<DestinationDetailsResponse>(GET_DESTINATION_TYPE_DETAILS, {
variables: { type: destination?.type },
skip: !destination,
});

useLayoutEffect(() => {
if (!destination) return;
Expand Down Expand Up @@ -109,9 +84,7 @@ export function ConnectDestinationModalBody({
}, [dynamicFields, destinationName, exportedSignals]);

useEffect(() => {
const isFormValid = dynamicFields.every((field) =>
field.required ? field.value : true
);
const isFormValid = dynamicFields.every((field) => (field.required ? field.value : true));
onFormValidChange(isFormValid);
}, [dynamicFields]);

Expand All @@ -131,9 +104,7 @@ export function ConnectDestinationModalBody({
handleDynamicFieldChange(name, value);
}
function processFieldValue(field) {
return field.componentType === INPUT_TYPES.DROPDOWN
? field.value.value
: field.value;
return field.componentType === INPUT_TYPES.DROPDOWN ? field.value.value : field.value;
}

function processFormFields() {
Expand Down Expand Up @@ -185,17 +156,16 @@ export function ConnectDestinationModalBody({

try {
// Await connection and store the configured destination if successful
await connectEnv(body, storeConfiguredDestination);
// await connectEnv(body, storeConfiguredDestination);
await connectEnv(body, refetch);
} catch (error) {
console.error('Failed to submit destination configuration:', error);
// Handle error (e.g., show notification or alert)
}
}

if (!destination) return null;

const actionButton = useMemo(() => {
if (destination.testConnectionSupported) {
if (!!destination?.testConnectionSupported) {
return (
<TestConnection
onError={() => {
Expand All @@ -212,13 +182,9 @@ export function ConnectDestinationModalBody({
);
}
return null;
}, [
destination,
destinationName,
exportedSignals,
processFormFields,
onFormValidChange,
]);
}, [destination, destinationName, exportedSignals, processFormFields, onFormValidChange]);

if (!destination) return null;

return (
<Container>
Expand All @@ -227,16 +193,9 @@ export function ConnectDestinationModalBody({
</SideMenuWrapper>

<Body>
<SectionTitle
title="Create connection"
description="Connect selected destination with Odigos."
actionButton={actionButton}
/>
<ConnectionNotification
showConnectionError={showConnectionError}
destination={destination}
/>
<Divider margin="24px 0" />
<SectionTitle title='Create connection' description='Connect selected destination with Odigos.' actionButton={actionButton} />
<ConnectionNotification showConnectionError={showConnectionError} destination={destination} />
<Divider margin='24px 0' />
<FormContainer
monitors={monitors}
dynamicFields={dynamicFields}
Expand Down
17 changes: 8 additions & 9 deletions frontend/webapp/hooks/destinations/useUpdateDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import { UPDATE_DESTINATION } from '@/graphql';
import { useDrawerStore } from '@/store';
import { DestinationInput } from '@/types';
import { useMutation } from '@apollo/client';
import { useComputePlatform } from '../compute-platform';

export function useUpdateDestination() {
const [updateDestinationMutation] = useMutation(UPDATE_DESTINATION);

const setDrawerItem = useDrawerStore(
({ setSelectedItem }) => setSelectedItem
);
const setDrawerItem = useDrawerStore(({ setSelectedItem }) => setSelectedItem);
const { refetch } = useComputePlatform();

async function updateExistingDestination(
id: string,
destination: DestinationInput
) {
async function updateExistingDestination(id: string, destination: DestinationInput) {
try {
const { data } = await updateDestinationMutation({
variables: { id, destination },
});
setDrawerItem({ id, item: data?.updateDestination, type: 'destination' });
console.log({ data });

setDrawerItem(null);
refetch();

return data?.updateDestination?.id;
} catch (error) {
console.error('Error updating destination:', error);
Expand Down
Loading