import React, { useState } from "react"; import styled from "styled-components"; import type { DebouncedFunc } from "lodash"; import { Button, Menu, MenuItem, MenuContent, MenuTrigger, SearchInput, Tooltip, } from "design-system"; import { HeaderWrapper } from "pages/Settings/components"; import { SettingsHeader } from "components/utils/helperComponents"; import { ARE_YOU_SURE, createMessage } from "@appsmith/constants/messages"; import { useMediaQuery } from "react-responsive"; type PageHeaderProps = { buttonText?: string; searchPlaceholder: string; onButtonClick?: () => void; onSearch?: DebouncedFunc<(search: string) => void>; pageMenuItems: any[]; 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")}; min-height: 36px; `; const SearchWrapper = styled.div` width: 100%; `; const ActionsWrapper = styled.div` display: flex; align-items: center; width: 100%; .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: any, ) => { 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 && ( { if (showOptions) { setShowOptions(open); showConfirmationText && setShowConfirmationText(false); } }} open={showOptions} > )} ); }