import React, { useState } from "react"; import styled from "styled-components"; import { Position } from "@blueprintjs/core"; import { DebouncedFunc } from "lodash"; import { Button, IconSize, Menu, MenuItem, MenuItemProps, Icon, SearchVariant, } from "design-system-old"; import { HeaderWrapper } from "pages/Settings/components"; import { HelpPopoverStyle, StyledSearchInput, SettingsHeader, } from "components/utils/helperComponents"; import { ARE_YOU_SURE, createMessage } from "@appsmith/constants/messages"; import { useMediaQuery } from "react-responsive"; import { TooltipComponent } from "design-system-old"; type PageHeaderProps = { buttonText?: string; searchPlaceholder: string; onButtonClick?: () => void; onSearch?: DebouncedFunc<(search: string) => void>; pageMenuItems: MenuItemProps[]; title?: string; showMoreOptions?: boolean; showSearchNButton?: boolean; }; const Container = styled.div<{ isMobile?: boolean }>` display: flex; justify-content: space-between; align-items: center; gap: 24px; flex-wrap: ${(props) => (props.isMobile ? "wrap" : "nowrap")}; h2 { text-transform: unset; } .actions-icon { color: var(--appsmith-color-black-400); &:hover { color: var(--appsmith-color-black-700); } } `; const StyledButton = styled(Button)` flex: 1 0 auto; min-width: 88px; `; const SearchWrapper = styled.div` width: 100%; `; const ActionsWrapper = styled.div` display: flex; align-items: center; width: 100%; .menu-actions-icon { margin-left: 12px; } `; export function SettingsPageHeader(props: PageHeaderProps) { const [showConfirmationText, setShowConfirmationText] = useState(false); const [showOptions, setShowOptions] = useState(false); const { buttonText, onSearch, pageMenuItems, searchPlaceholder, showMoreOptions, showSearchNButton = true, title, } = props; const handleSearch = (search: string) => { onSearch?.(search.toLocaleUpperCase()); }; const onOptionSelect = ( e: React.MouseEvent, menuItem: MenuItemProps, ) => { if (menuItem.label === "delete") { setShowOptions(true); setShowConfirmationText(true); showConfirmationText && menuItem?.onSelect?.(e, "delete"); } else if (menuItem.label === "rename") { setShowOptions(false); } else { setShowConfirmationText(false); setShowOptions(false); menuItem?.onSelect?.(e, "other"); } }; const isMobile: boolean = useMediaQuery({ maxWidth: 767 }); return ( {title} {onSearch && showSearchNButton && ( )} {/* */} {buttonText && showSearchNButton && ( )} {showMoreOptions && ( setShowOptions(false)} onClosing={() => { setShowConfirmationText(false); setShowOptions(false); }} onOpening={() => setShowOptions(true)} position={Position.BOTTOM_RIGHT} target={ setShowOptions(!showOptions)} size={IconSize.XXL} /> } > {pageMenuItems && pageMenuItems.map((menuItem) => ( ) => { onOptionSelect(e, menuItem); }} text={ showConfirmationText && menuItem.label === "delete" ? createMessage(ARE_YOU_SURE) : menuItem.text } {...(showConfirmationText && menuItem.label === "delete" ? { type: "warning" } : {})} /> ))} )} ); }