import React, { useState } from 'react'; import PropTypes from 'prop-types'; import i18next from 'i18next'; import { takeRight } from 'lodash'; import { ThemeProvider } from 'styled-components'; import { getTheme } from '../../../utils/theme'; import { OptionsContainer, ActionsContainer, ActionsInLineContainer, OtherActionsContainer, } from '../../styledComponents'; import { Props } from './interfaces'; import { SeparateAction } from '../../interfaces'; import Dropdown from '../Dropdown'; import Button from '../../../Button/index'; import SearchBar from '../../../SearchBar'; import Download from '../../../images/icon-download.svg'; function renderDropdownActions( actions: SeparateAction[], label: string ): JSX.Element { if (!actions || !actions.length) { return <>; } return ; } function renderInlineActions( actions: SeparateAction[], renderButton: Function, maxActionsInLine: number ): JSX.Element { if (!actions || !actions.length) { return <>; } if (actions.length > maxActionsInLine) { return ( {actions .slice(0, maxActionsInLine) .map(({ actionLabel, handleAction, render }) => (
{renderButton(render, actionLabel, handleAction)}
))} {actions.length > maxActionsInLine && renderDropdownActions( takeRight(actions, actions.length - maxActionsInLine), `${i18next.t('COMPONENT_LIST_VIEW_DROPDOWN_OTHER_ACTIONS')} (${ actions.length - maxActionsInLine })` )}
); } return ( {actions.map(({ actionLabel, handleAction, render }) => (
{renderButton(render, actionLabel, handleAction)}
))}
); } function renderOtherActions( // eslint-disable-next-line @typescript-eslint/no-explicit-any theme: any, actions: SeparateAction[], renderButton: Function, minActionsInActionsDropdown: number ): JSX.Element { if (!actions || !actions.length) { return <>; } const { actionLabel, handleAction, render } = actions[0]; return ( <> {actions.length >= minActionsInActionsDropdown ? ( ) : ( renderButton(render, actionLabel, handleAction) )} ); } function renderFixedActions( actions: SeparateAction[], renderButton: Function ): JSX.Element { if (!actions || !actions.length) { return <>; } return ( {actions.map(({ actionLabel, handleAction, render }) => (
{renderButton(render, actionLabel, handleAction)}
))}
); } function renderActions( // eslint-disable-next-line @typescript-eslint/no-explicit-any theme: any, actions: SeparateAction[], shouldDisplayAction: Function, maxActionsInLine: number, minActionsInActionsDropdown: number, exportFunction?: Function ): JSX.Element { const renderButton = (render, actionLabel, handleAction) => { if (render) { return render(actionLabel, handleAction) as string; } return (