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

feat: move blocks between categories #265

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

IkbelTalebHssan
Copy link
Collaborator

@IkbelTalebHssan IkbelTalebHssan commented Oct 23, 2024

Motivation

This PR introduces functionality to move one or multiple selected blocks between different categories. This enhancement allows for smoother transitions of grouped blocks across flows, improving workflow organization and flexibility in flow management.

Fixes # (issue)

Type of change:

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@yassinedorbozgithub
Copy link
Contributor

yassinedorbozgithub commented Oct 31, 2024

Hi,i think that there is a possibility to split flows cross categories.
In specific case, we will a have a working flow that is not fully visible in the visual editor.

Proposed solutions :

  1. Move block(s) and delete nextBlock(s) if necessary
  2. Copy block(s) and delete moved blocks nextBlock(s)

NB: Needs to support the case when we act on two or more linked blocks

@IkbelTalebHssan IkbelTalebHssan force-pushed the 256-request-move-blocks-between-categories branch from f8edf63 to 310d9e4 Compare October 31, 2024 16:09
@IkbelTalebHssan
Copy link
Collaborator Author

Hi,i think that there is a possibility to split flows cross categories. In specific case, we will a have a working flow that is not fully visible in the visual editor.

Proposed solutions :

  1. Move block(s) and delete nextBlock(s) if necessary
  2. Copy block(s) and delete moved blocks nextBlock(s)

NB: Needs to support the case when we act on two or more linked blocks

Thanks for your feedback 🙏 I worked on the first approch ✔️ 🙏

Copy link
Contributor

@marrouchi marrouchi left a comment

Choose a reason for hiding this comment

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

1 comment left 👏

frontend/src/components/visual-editor/v2/Diagrams.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@marrouchi marrouchi left a comment

Choose a reason for hiding this comment

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

Awesome work @IkbelTalebHssan @yassinedorbozgithub Left some comments.

api/src/chat/repositories/block.repository.ts Show resolved Hide resolved
api/src/chat/repositories/block.repository.ts Outdated Show resolved Hide resolved
api/src/utils/generics/base-repository.ts Show resolved Hide resolved
frontend/src/services/api.class.ts Outdated Show resolved Hide resolved
api/src/utils/generics/base-repository.ts Show resolved Hide resolved
api/src/chat/repositories/block.repository.ts Outdated Show resolved Hide resolved
api/src/chat/repositories/block.repository.ts Show resolved Hide resolved
@medchedli
Copy link

medchedli commented Nov 19, 2024

Testing various scenarios for moving blocks between flows. Everything worked fine 👏. I have one suggestion regarding the move button start icon: Using the hand Swipe icon may give users the impression that they can use a drag-n-drop gesture to move blocks between flows. I recommend replacing the icon with the MoveUpIcon.

image

Copy link

@medchedli medchedli left a comment

Choose a reason for hiding this comment

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

I ran the functional test again, and everything is working well.

Comment on lines +137 to +138
if (criteria._id?.$in && updates?.$set?.category) {
const ids: string[] = criteria._id?.$in || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (criteria._id?.$in && updates?.$set?.category) {
const ids: string[] = criteria._id?.$in || [];
if (updates?.$set?.category) {
const blocks = await this.find(criteria);
const ids = blocks.map(({id}) => id);

// Step 2: Find other blocks
const otherBlocks = await this.model.find({
_id: { $nin: objIds },
category: { $ne: objCategory },
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
category: { $ne: objCategory },
category: { $ne: categoryId },

// Step 1: Map IDs and Category
const { objIds, objCategory } = this.mapIdsAndCategory(ids, category);

// Step 2: Find other blocks
Copy link
Contributor

Choose a reason for hiding this comment

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

const objIds = ids.map((id) => ObjectId(id))

const objCategory = new mongoose.Types.ObjectId(category);
return { objIds, objCategory };
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment function

): Promise<void> {
for (const id of ids) {
const oldState = await this.model.findOne({
_id: new mongoose.Types.ObjectId(id),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_id: new mongoose.Types.ObjectId(id),
_id: id,

: null;

await this.model.updateOne(
{ _id: new mongoose.Types.ObjectId(id) },
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{ _id: new mongoose.Types.ObjectId(id) },
id,

}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment ...

): Promise<void> {
for (const block of otherBlocks) {
if (
objIds.some((id) => id.toString() === block.attachedBlock?.toString())
Copy link
Contributor

Choose a reason for hiding this comment

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

objIds.includes(block.attachedBlock)

!objIds.some((id) => id.toString() === nextBlock.toString()),
);

if (updatedNextBlocks.length !== block.nextBlocks.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (updatedNextBlocks.length !== block.nextBlocks.length) {
if (updatedNextBlocks.length > 0) {

if (updatedNextBlocks.length !== block.nextBlocks.length) {
await this.model.updateOne(
{ _id: block.id },
{ nextBlocks: updatedNextBlocks },
Copy link
Contributor

Choose a reason for hiding this comment

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

$pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 [REQUEST] - Move Blocks Between Categories
5 participants