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-1621]: add cancel modal & breakdown overview-drawer files #1682

Merged
merged 25 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 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
5647431
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
8d22beb
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
e53746d
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
45f06d1
feat: warn before canceling
BenElferink Nov 3, 2024
646a930
perf: break overview-drawer to smaller files
BenElferink Nov 3, 2024
9d2082a
fix: warning modal double-overlay
BenElferink Nov 3, 2024
1f4a6d7
perf: move modals as well
BenElferink Nov 3, 2024
4392ff1
fix: clean imports for wanring modals
BenElferink Nov 3, 2024
222bc11
fix: key down - add "active" indicator
BenElferink Nov 3, 2024
019a50f
feat: key down with special keys
BenElferink Nov 3, 2024
346e9e5
fix(): keydown event dependencies
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
31 changes: 31 additions & 0 deletions frontend/webapp/components/modals/cancel-warning/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { WarningModal } from '@/reuseable-components';

interface Props {
isOpen: boolean;
name?: string;
onApprove: () => void;
onDeny: () => void;
}

const CancelWarning: React.FC<Props> = ({ isOpen, name, onApprove, onDeny }) => {
return (
<WarningModal
isOpen={isOpen}
noOverlay
title={`Cancel${name ? ` ${name}` : ''}`}
description='Are you sure you want to cancel?'
approveButton={{
text: 'Cancel',
variant: 'warning',
onClick: onApprove,
}}
denyButton={{
text: 'Go Back',
onClick: onDeny,
}}
/>
);
};

export { CancelWarning };
73 changes: 0 additions & 73 deletions frontend/webapp/components/modals/delete-entity-modal/index.tsx

This file was deleted.

31 changes: 31 additions & 0 deletions frontend/webapp/components/modals/delete-warning/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { WarningModal } from '@/reuseable-components';

interface Props {
isOpen: boolean;
name?: string;
onApprove: () => void;
onDeny: () => void;
}

const DeleteWarning: React.FC<Props> = ({ isOpen, name, onApprove, onDeny }) => {
return (
<WarningModal
isOpen={isOpen}
noOverlay
title={`Delete${name ? ` ${name}` : ''}`}
description='Are you sure you want to delete this?'
approveButton={{
text: 'Delete',
variant: 'danger',
onClick: onApprove,
}}
denyButton={{
text: 'Cancel',
onClick: onDeny,
}}
/>
);
};

export { DeleteWarning };
2 changes: 2 additions & 0 deletions frontend/webapp/components/modals/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './cancel-warning';
export * from './delete-warning';
1 change: 0 additions & 1 deletion frontend/webapp/components/modals/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function CreateConnectionForm({
filterSupportedMonitors();
}, [destination]);

useKeyDown('Enter', handleKeyPress);
useKeyDown({ key: 'Enter', active: true }, handleKeyPress);

function handleKeyPress(e: any) {
if (!isCreateButtonDisabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import React, { forwardRef, useImperativeHandle, useMemo } from 'react';
import React, { useMemo, useState } from 'react';
import styled from 'styled-components';
import { getActionIcon } from '@/utils';
import { useDrawerStore } from '@/store';
import { CardDetails } from '@/components';
import { useActionFormData, useNotify } from '@/hooks';
import type { ActionDataParsed } from '@/types';
import { ChooseActionBody } from '../choose-action-body';
import type { ActionDataParsed, ActionInput } from '@/types';
import OverviewDrawer from '../../overview/overview-drawer';
import buildCardFromActionSpec from './build-card-from-action-spec';
import { useActionCRUD, useActionFormData, useNotify } from '@/hooks';
import { ACTION_OPTIONS } from '../choose-action-modal/action-options';

export type ActionDrawerHandle = {
getCurrentData: () => ActionInput | null;
};

interface Props {
isEditing: boolean;
}
interface Props {}

const ActionDrawer = forwardRef<ActionDrawerHandle, Props>(({ isEditing }, ref) => {
const ActionDrawer: React.FC<Props> = () => {
const notify = useNotify();
const selectedItem = useDrawerStore(({ selectedItem }) => selectedItem);
const [isEditing, setIsEditing] = useState(false);

const { formData, handleFormChange, resetFormData, validateForm, loadFormWithDrawerItem } = useActionFormData();
const { updateAction, deleteAction } = useActionCRUD();

const cardData = useMemo(() => {
if (!selectedItem) return [];
Expand Down Expand Up @@ -48,33 +47,65 @@ const ActionDrawer = forwardRef<ActionDrawerHandle, Props>(({ isEditing }, ref)
return found;
}, [selectedItem, isEditing]);

useImperativeHandle(ref, () => ({
getCurrentData: () => {
if (validateForm()) {
return formData;
} else {
notify({
message: 'Required fields are missing!',
title: 'Update Action Error',
type: 'error',
target: 'notification',
crdType: 'notification',
});
return null;
}
},
}));

return isEditing && thisAction ? (
<FormContainer>
<ChooseActionBody isUpdate action={thisAction} formData={formData} handleFormChange={handleFormChange} />
</FormContainer>
) : (
<CardDetails data={cardData} />
);
});
if (!selectedItem?.item) return null;
const { id, item } = selectedItem;

ActionDrawer.displayName = 'ActionDrawer';
const handleEdit = (bool?: boolean) => {
if (typeof bool === 'boolean') {
setIsEditing(bool);
} else {
setIsEditing(true);
}
};

const handleCancel = () => {
resetFormData();
setIsEditing(false);
};

const handleDelete = async () => {
await deleteAction(id as string, (item as ActionDataParsed).type);
};

const handleSave = async (newTitle: string) => {
if (!validateForm()) {
notify({
message: 'Required fields are missing!',
title: 'Update Action Error',
type: 'error',
target: 'notification',
crdType: 'notification',
});
} else {
const payload = {
...formData,
name: newTitle,
};

await updateAction(id as string, payload);
}
};

return (
<OverviewDrawer
title={(item as ActionDataParsed).spec.actionName}
imageUri={getActionIcon((item as ActionDataParsed).type)}
isEdit={isEditing}
clickEdit={handleEdit}
clickSave={handleSave}
clickDelete={handleDelete}
clickCancel={handleCancel}
>
{isEditing && thisAction ? (
<FormContainer>
<ChooseActionBody isUpdate action={thisAction} formData={formData} handleFormChange={handleFormChange} />
</FormContainer>
) : (
<CardDetails data={cardData} />
)}
</OverviewDrawer>
);
};

export { ActionDrawer };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { ACTION_OPTIONS, type ActionOption } from './action-options';
import { AutocompleteInput, Modal, NavigationButtons, Divider, FadeLoader, SectionTitle, ModalContent, Center } from '@/reuseable-components';

interface AddActionModalProps {
isModalOpen: boolean;
handleCloseModal: () => void;
isOpen: boolean;
onClose: () => void;
}

export const AddActionModal: React.FC<AddActionModalProps> = ({ isModalOpen, handleCloseModal }) => {
export const AddActionModal: React.FC<AddActionModalProps> = ({ isOpen, onClose }) => {
const { formData, handleFormChange, resetFormData, validateForm } = useActionFormData();
const { createAction, loading } = useActionCRUD({ onSuccess: handleClose });
const [selectedItem, setSelectedItem] = useState<ActionOption | undefined>(undefined);
Expand All @@ -23,7 +23,7 @@ export const AddActionModal: React.FC<AddActionModalProps> = ({ isModalOpen, han
function handleClose() {
resetFormData();
setSelectedItem(undefined);
handleCloseModal();
onClose();
}

const handleSelect = (item?: ActionOption) => {
Expand All @@ -34,7 +34,7 @@ export const AddActionModal: React.FC<AddActionModalProps> = ({ isModalOpen, han

return (
<Modal
isOpen={isModalOpen}
isOpen={isOpen}
onClose={handleClose}
header={{ title: 'Add Action' }}
actionComponent={
Expand Down
Loading
Loading