Sha256: 1d132bd2931d8fdc8331c35fdbe60cc14aaba3dabe4f0ac42bf574f5c8812df5

Contents?: true

Size: 1.19 KB

Versions: 68

Compression:

Stored size: 1.19 KB

Contents

export const findItemById = (
  items: { [key: string]: any }[],
  id: string
): any => {
  for (const item of items) {
    if (item.id === id) {
      return item;
    }
    if (item.children) {
      const found = findItemById(item.children, id);
      if (found) {
        return found;
      }
    }
  }
  return null;
};

export const checkIt = (
  foundItem: { [key: string]: any },
  selectedItems: any[],
  setSelectedItems: Function
) => {
  if (!foundItem) {
    return;
  }

  foundItem.checked = true;
  foundItem.expanded = true;
  selectedItems.push(foundItem);

  if (foundItem.children) {
    foundItem.children.map((x: any) => {
      checkIt(x, selectedItems, setSelectedItems);
    });
  }

  setSelectedItems([...selectedItems]);
};

export const unCheckIt = (
  foundItem: { [key: string]: any },
  selectedItems: any,
  setSelectedItems: any
) => {
  if (!foundItem) {
    return;
  }

  foundItem.checked = false;
  const newSelectedItems = selectedItems.filter(
    (item: any) => item.id !== foundItem.id
  );
  if (foundItem.children) {
    foundItem.children.map((x: any) => {
      unCheckIt(x, selectedItems, setSelectedItems);
    });
  }
  setSelectedItems([...newSelectedItems]);
};

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
playbook_ui-12.19.0.pre.alpha.PLAY699zindexresponsive650 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.19.0.pre.alpha.movemarkdown639 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.19.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown638 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.19.0.pre.alpha.movemarkdown637 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY785typeaheadts632 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.19.0 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown629 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown628 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown626 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown617 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY735mobileheadersfix616 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY747carddarktokens610 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY785typeaheadts608 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0.pre.alpha.PLAY785typeaheadts607 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.18.0 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.17.1 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.17.0.pre.alpha.lightboxcurrentPhotoIndex582 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.17.0 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.16.0.pre.alpha.tooltippositionprop566 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts
playbook_ui-12.16.0.pre.alpha.PLAY693tooltipwrongbg558 app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts