Skip to content

Commit

Permalink
chore: Add feature metrics for mainAction and checkbox items in butto…
Browse files Browse the repository at this point in the history
…n dropdown (#2438)
  • Loading branch information
timogasda authored Jul 3, 2024
1 parent dba9901 commit fcd9ab1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/button-dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import { ButtonDropdownProps } from './interfaces';
import InternalButtonDropdown from './internal';
import { hasCheckboxItems } from './utils/utils';
import { getBaseProps } from '../internal/base-component';
import { applyDisplayName } from '../internal/utils/apply-display-name';
import useBaseComponent from '../internal/hooks/use-base-component';
Expand Down Expand Up @@ -30,6 +31,10 @@ const ButtonDropdown = React.forwardRef(
) => {
const baseComponentProps = useBaseComponent('ButtonDropdown', {
props: { expandToViewport, expandableGroups, variant },
metadata: {
mainAction: !!mainAction,
checkboxItems: hasCheckboxItems(items),
},
});
const baseProps = getBaseProps(props);
return (
Expand Down
2 changes: 1 addition & 1 deletion src/button-dropdown/utils/create-items-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function createItemsTree(items: ButtonDropdownProps.Items): Items
};
}

function traverseItems(
export function traverseItems(
items: ButtonDropdownProps.Items,
act: (item: ButtonDropdownProps.ItemOrGroup, index: TreeIndex) => void,
parentIndex: TreeIndex = []
Expand Down
11 changes: 11 additions & 0 deletions src/button-dropdown/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { ButtonDropdownProps, LinkItem } from '../interfaces';
import { traverseItems } from './create-items-tree';

export const isItemGroup = (item: ButtonDropdownProps.ItemOrGroup): item is ButtonDropdownProps.ItemGroup =>
item && (item as ButtonDropdownProps.ItemGroup).items !== undefined;
Expand Down Expand Up @@ -36,3 +37,13 @@ export function indexEquals(left: number[], right: number[]) {

return true;
}

export function hasCheckboxItems(items: ButtonDropdownProps.Items) {
let hasCheckboxItems = false;
traverseItems(items, item => {
if (item.itemType === 'checkbox') {
hasCheckboxItems = true;
}
});
return hasCheckboxItems;
}

0 comments on commit fcd9ab1

Please sign in to comment.