Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

[WIP] fix(DataMapper): Show a confirmation dialog when DataMapper step is t… #102

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

igarashitm
Copy link
Collaborator

@igarashitm igarashitm commented Oct 9, 2024

…o be deleted, with also offering an option to delete associated mapping file (XSLT)

Fixes: KaotoIO/kaoto#1749

Here's what I could come up with. Let's start from here.
Screenshot from 2024-10-09 16-30-42

@igarashitm igarashitm requested a review from lordrip October 9, 2024 21:18
callback: (vizNode, modalAnswer) => {
metadataApi && onDeleteDataMapper(metadataApi, vizNode, modalAnswer);
},
modalCustomization: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding modal customization for the DataMapper step

export interface IRegisteredInteractionAddon {
type: IInteractionAddonType;
activationFn: (vizNode: IVisualizationNode) => boolean;
callback: (vizNode: IVisualizationNode) => void;
callback: (vizNode: IVisualizationNode, modalAnswer: number | undefined) => void;
modalCustomization?: IModalCustomization;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added modal customization option inside the IRegisteredInteractionAddon. For the DataMapper step specifically it is tightly coupled. The each callback execution needs to receive modalAnswer to determine if XSLT file is to be removed or not.

DataMapperMetadataService.deleteMetadata(api, metadataId);
// TODO DataMapperMetadataService.deleteXsltFile(api, metadataId);
if (modalAnswer === ACTION_INDEX_DELETE_STEP_AND_FILE) {
await DataMapperMetadataService.deleteXsltFile(api, metadataId);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's exactly the one removing associated XSLT file for the target DataMapper step.


let modalAnswer: number | undefined = 1;
if (props.loadActionConfirmationModal || modalCustoms.length > 0) {
const additionalModalText = modalCustoms.length > 0 ? modalCustoms[0].additionalText : undefined;
Copy link
Collaborator Author

@igarashitm igarashitm Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM the first found modal customization is used, but I wonder if there's any possibility to get more options in the future - say, if there's a sql step which has an external sql file, then we want to support removing the external sql file as well if user wants... but there's a DataMapper step right next to the sql step, and both are under when, and the user is deleting the when. How the modal should look like?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is possible to go that route if we want to, it will probably require checking what steps are involved first and then preparing the appropriate modal for that.

const modalCustoms = findModalCustomizationRecursively(props.vizNode, (vn) =>
getRegisteredInteractionAddons(IInteractionAddonType.ON_DELETE, vn),
);
let modalAnswer: number | undefined = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the reasons we should have used named indexes 😢 , it's not easy to reason about why 1.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, but I see later on in the code:

import { ACTION_INDEX_DELETE_STEP_AND_FILE, ACTION_INDEX_DELETE_STEP_ONLY, MetadataContext } from '../../providers';

can we use those? the benefit would be that when we refactor this functionality to use named indexes, it will be easier to know what's what.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will do - we can use the string key in a same way

getAddons: (vizNode: IVisualizationNode) => IRegisteredInteractionAddon[],
) => {
const modalCustomizations: IModalCustomization[] = [];
// going breadth-first while addon processes depth-first... do we want?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand the question, what do you mean? to pick between one or the other? If that's the case, I think yes, but I don't have any preference at the moment, feel free to pick the one that you consider the best.

Copy link
Collaborator Author

@igarashitm igarashitm Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM there's no effect, this makes a difference once multiple modal customizations are introduced, on whether the sibling customization should come first or the deeper children should come first.
cf. #102 (comment)

Copy link
Collaborator

@lordrip lordrip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igarashitm feel free to move forward with this PR, if you want, I can give you a hand with the changes around the confirmation modal

@lordrip
Copy link
Collaborator

lordrip commented Oct 11, 2024

The modal looks "interesting" with the cancel button trying to escape from the modal
image

@igarashitm
Copy link
Collaborator Author

igarashitm commented Oct 11, 2024

I'll fix to use string key for the button actions and modal button layout upstream first, put this PR on hold for a moment

@igarashitm
Copy link
Collaborator Author

@igarashitm
Copy link
Collaborator Author

Merged upstream fix and verified 3 options works as expected
Screenshot from 2024-10-14 13-25-08

@igarashitm igarashitm merged commit 7f20716 into kaoto-archive:main Oct 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants