Skip to content

Commit

Permalink
[misc cleanup] Remove manual conditions in favor of `callWithItemIfFu…
Browse files Browse the repository at this point in the history
…nction` util
  • Loading branch information
cee-chen committed Apr 9, 2024
1 parent 9eef965 commit c3bd4c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
10 changes: 3 additions & 7 deletions src/components/basic_table/collapsed_item_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import React, {
ReactElement,
} from 'react';

import { isString } from '../../services/predicate';
import { EuiContextMenuItem, EuiContextMenuPanel } from '../context_menu';
import { EuiPopover } from '../popover';
import { EuiButtonIcon } from '../button';
Expand Down Expand Up @@ -69,12 +68,9 @@ export const CollapsedItemActions = <T extends {}>({
</EuiContextMenuItem>
);
} else {
const buttonIcon = action.icon;
let icon;
if (buttonIcon) {
icon = isString(buttonIcon) ? buttonIcon : buttonIcon(item);
}

const icon = action.icon
? callWithItemIfFunction(item)(action.icon)
: undefined;
const buttonContent = callWithItemIfFunction(item)(action.name);
const toolTipContent = callWithItemIfFunction(item)(action.description);
const href = callWithItemIfFunction(item)(action.href);
Expand Down
21 changes: 7 additions & 14 deletions src/components/basic_table/default_item_action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import React, { ReactElement, ReactNode, MouseEvent, useCallback } from 'react';

import { isString } from '../../services/predicate';
import {
EuiButtonEmpty,
EuiButtonIcon,
Expand Down Expand Up @@ -51,26 +50,20 @@ export const DefaultItemAction = <T extends object>({
[action.onClick, item]
);

const buttonColor = action.color;
let color: EuiButtonIconProps['color'] = 'primary';
if (buttonColor) {
color = isString(buttonColor) ? buttonColor : buttonColor(item);
}

const buttonIcon = action.icon;
let icon;
if (buttonIcon) {
icon = isString(buttonIcon) ? buttonIcon : buttonIcon(item);
}

let button;
const color: EuiButtonIconProps['color'] = action.color
? callWithItemIfFunction(item)(action.color)
: 'primary';
const icon = action.icon
? callWithItemIfFunction(item)(action.icon)
: undefined;
const actionContent = callWithItemIfFunction(item)(action.name);
const tooltipContent = callWithItemIfFunction(item)(action.description);
const href = callWithItemIfFunction(item)(action.href);
const dataTestSubj = callWithItemIfFunction(item)(action['data-test-subj']);

const ariaLabelId = useGeneratedHtmlId();
let ariaLabelledBy: ReactNode;
let button;

if (action.type === 'icon') {
if (!icon) {
Expand Down

0 comments on commit c3bd4c1

Please sign in to comment.