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

MARKET-1466 Cascade Select #184

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

Conversation

StasivPavlo
Copy link
Contributor

image
image
image

components/bl-cascadeSelect-component/README.md Outdated Show resolved Hide resolved
components/bl-cascadeSelect-component/src/index.js Outdated Show resolved Hide resolved
components/bl-cascadeSelect-component/src/index.js Outdated Show resolved Hide resolved
components/bl-cascadeSelect-component/src/subcomponent.js Outdated Show resolved Hide resolved
components/bl-cascadeSelect-component/src/subcomponent.js Outdated Show resolved Hide resolved
components/bl-cascadeSelect-component/src/index.js Outdated Show resolved Hide resolved
components/bl-cascadeSelect-component/src/helpers.js Outdated Show resolved Hide resolved

| Action | Inputs | Return |
|---------------|--------|--------------------------|
| Get Select in | | Object: of a select item |
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about add an actions same as for default select?
Set Options
Get Options
Set Value
Get Value

Copy link
Member

Choose a reason for hiding this comment

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

please describe these actions here in the doc

return validItem;
});

levelOfNesting--;
Copy link
Member

Choose a reason for hiding this comment

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

could you please explain the logic around ++/-- levelOfNesting

if it needs to calculate nesting depth would not it be better to pass a new level into the prepare function?

 const prepare = (children, depth) => {
if (item.children) {
        validItem = {
          ...validItem,
          children: prepare(item.children, depth + 1),
        };

        parentItems.push({ code: item.code, isOpen: false, depth });
      } else {
        items.push(validItem);
      }
 }

 const preparedCascade = prepare(cascade);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand, with this implementation, we will not be able to get the last depth value when this recursion ends. It's needed to get max depth

Copy link
Member

Choose a reason for hiding this comment

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

why do you need to know about the max depth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get sorted and separated array of parentItems by levelOfNesting in the getNestedItems function

const { display, classList, style, cascade, placeholder } = component;
const { onClickItem } = eventHandlers;

const [itemsCascade, setItemsCascade] = useState();
Copy link
Member

Choose a reason for hiding this comment

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

what's the difference between them?

  • itemsCascade
  • parentItems
  • items

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • itemsCascade is a validated object which comes from property cascade
  • parentItems is the array of arrays of parent items(items which have children) separated by levelOfNesting
  • items is the array of items which we can select(which haven't children)

Copy link
Member

Choose a reason for hiding this comment

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

I still do not understand why we need 3 lists instead of a single one itemsCascade
we can validate/transform the source list into a list that suits all needs, the target list can have any structure we need and items can have all necessary information about clickable/nestingLevel/etc

Copy link
Contributor Author

@StasivPavlo StasivPavlo Oct 2, 2023

Choose a reason for hiding this comment

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

because it's easy to find items in an array, instead of an array of objects that have in turn, have their own array of objects

Copy link
Collaborator

Choose a reason for hiding this comment

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

parent reference should solve that problem

let isCircular = false;
let cycleLocation;

function detect(obj, key) {
Copy link
Member

Choose a reason for hiding this comment

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

detectCircular ?

component.getCascade = () => itemsCascade;
component.setCascade = (cascade) => validate(cascade, setItemsCascade, setParentItems, setItems);

useEffect(() => component.el = cascadeSelectRef.current, []);
Copy link
Member

Choose a reason for hiding this comment

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

use elRef

}

return (
<div ref={ cascadeSelectRef } className={ cn('bl-cascadeSelect-component', ...classList) } style={ style }>
Copy link
Member

Choose a reason for hiding this comment

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

cn('bl-cascadeSelect-component', classList)

export const findParentItem = (parentItems, item) => {
const { levelOfNesting, code } = item;

return parentItems[levelOfNesting].find(item => item.code === code);
Copy link
Member

Choose a reason for hiding this comment

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

to avoid reverse find you can build you data structure with the following way:

list = [
  {
    id: parent1,
    label: I am parent item,
    children: [
      { 
        id:child1,
        label: I am child 1,
        parent: $refToTheParent1Object 
      }
   
   ]
  }
]

where $refToTheParent1Object is list[0].children[0].parent = list[0]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it a cyclic object? Isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. Is it problem?

for (let i = 0; i < currentParentItems[levelOfNesting].length; i++) {
const { code: parentItemCode, isOpen } = currentParentItems[levelOfNesting][i];

currentParentItems[levelOfNesting][i].isOpen = parentItemCode === code ? !isOpen : false;
Copy link
Member

Choose a reason for hiding this comment

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

in order to avoid modifying the entire state each time I can propose the following approach:

  1. having a data structure of the list as described here https://github.com/Backendless/ui-builder-library/pull/184/files#r1095517200 you can build a specific path for each item, for ex: parent1.child1

  2. in the view you can determine if the leaf/branch must be open by comparing selectedItem.path.startsWith(theViewItem.path)


| Property | Type | Default Value | Logic | Data Binding | UI Setting | Description |
|-------------------|---------|---------------------|-----------------------------|--------------|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Cascade | JSON | | Cascade Logic | YES | YES | Allows determinate an array of select items to display as the available options. Watch [Codeless Examples](#Examples). Signature of polygon: `[{name, code, ?children}]` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

name -> label


| Property | Type | Default Value | Logic | Data Binding | UI Setting | Description |
|-------------------|---------|---------------------|-----------------------------|--------------|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Cascade | JSON | | Cascade Logic | YES | YES | Allows determinate an array of select items to display as the available options. Watch [Codeless Examples](#Examples). Signature of polygon: `[{name, code, ?children}]` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

code -> value

export const findParentItem = (parentItems, item) => {
const { levelOfNesting, code } = item;

return parentItems[levelOfNesting].find(item => item.code === code);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. Is it problem?

const { display, classList, style, cascade, placeholder } = component;
const { onClickItem } = eventHandlers;

const [itemsCascade, setItemsCascade] = useState();
Copy link
Collaborator

Choose a reason for hiding this comment

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

parent reference should solve that problem

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.

4 participants