saleor-dashboard/src/components/ButtonWithDropdown/ButtonWithDropdown.tsx

58 lines
1.3 KiB
TypeScript
Raw Normal View History

import {
Box,
Button,
ChervonDownIcon,
Dropdown,
List,
Text,
} from "@saleor/macaw-ui/next";
import React from "react";
interface ButtonWithDropdownProps {
onClick: () => void;
options: Array<{ label: string; testId: string; onSelect: () => void }>;
testId?: string;
🏛️ Implement new column picker (#3514) * (wip) basic column picker implementation * (wip) fix stories error * (wip) fix custom column cells & sorting * (wip) Group attributes query values in props * (wip) Add docs * (wip) fix story error * Implement new column picker in order list * Fix search input padding * Fix empty settings crash * Fix empty settings crash * Portalize popover * Preselect category when there is only one * Remove legacy code * Move product column adapters to proper directory * Improve file structure * Rename custom columns to dynamic columns * Improve strings * (wip) Implement pagination logic * Beautify pagination * Update macaw-ui * Add unit test for useColumns * Improve naming * Code review style fixes * Update docs * Remove empty column * Remove unexpected padding from attribute columns * Add min height to prevent jumping * Fix typo in column picker files * CSS fixes to popover content * Implement auto-scroll to new column * Improve docs * Improve type in useColumns reducer * Extract dynamic columns from NewColumnPicker as a smaller component * Disable movement of empty column * Fix circular loader * Do not persist expanded state when closing picker * Fix dynamic columns with long names line break * Prevent user from disabling all static columns * Simplify dynamic column reducer into flatMap * Optimistic UIbasic implementation * Make available attributes query lazy * Fix displaying arrow next to sorted column * Add explainatory comment * Fix product list stories * Fix dynamic columns and query handling for empty lists * Remove jump on first attribute selection * Remove jump on first attribute selection * Fix search * Add debounce to search * CR - base state change on previous in popover * Extract search into separate component * Rename useDynamicColumnSettings to useColumnPickerSettings * Use difference from lodash * Improve static column rendering * Improve order list * Fix stories error * Improve search for edge cases * Extract messages * Calculate more complex dynamic column adapter parameters in separate functions * Fix url pointing to CardMenu substitute * Extract nodes to separate component * Move files, remove New prefix * Extract to static columns * Refactor utility functions * Render column picker categories only when provided in props * Replace switch with if statements * Refactor to hooks * Remove comments with legacy stacing * Add spaces for better readibility * Tighten types * Add space * Add extra comments to useColumns optimistic update logic * Fix paddings * Add arbitrary min/max height for handling various resolutions * Add full-width hover & click effect on candidate columns labels * Handle long attribute names * Make column picker popover a modal * Bump macaw-ui * Fix macaw-ui type mismatch * Update types * Add data-test-id * Fix closing picker with trigger button * Replace list settings deep merging with shallow merging * Fix list settings deep merging behaviour for arrays * Replace conditional data-test-id- with close-search * Rename targetArray to columnsToCheck * Rename filterColumns to filterSelectedColumns * Rename gridAttributes query objects to more descriptive * Add explainatory comment to customizer function in useListSettings * Update strictness * Fix rendering dynamic columns
2023-06-26 09:36:01 +00:00
disabled?: boolean;
}
export const ButtonWithDropdown: React.FC<ButtonWithDropdownProps> = ({
onClick,
options,
children,
testId,
🏛️ Implement new column picker (#3514) * (wip) basic column picker implementation * (wip) fix stories error * (wip) fix custom column cells & sorting * (wip) Group attributes query values in props * (wip) Add docs * (wip) fix story error * Implement new column picker in order list * Fix search input padding * Fix empty settings crash * Fix empty settings crash * Portalize popover * Preselect category when there is only one * Remove legacy code * Move product column adapters to proper directory * Improve file structure * Rename custom columns to dynamic columns * Improve strings * (wip) Implement pagination logic * Beautify pagination * Update macaw-ui * Add unit test for useColumns * Improve naming * Code review style fixes * Update docs * Remove empty column * Remove unexpected padding from attribute columns * Add min height to prevent jumping * Fix typo in column picker files * CSS fixes to popover content * Implement auto-scroll to new column * Improve docs * Improve type in useColumns reducer * Extract dynamic columns from NewColumnPicker as a smaller component * Disable movement of empty column * Fix circular loader * Do not persist expanded state when closing picker * Fix dynamic columns with long names line break * Prevent user from disabling all static columns * Simplify dynamic column reducer into flatMap * Optimistic UIbasic implementation * Make available attributes query lazy * Fix displaying arrow next to sorted column * Add explainatory comment * Fix product list stories * Fix dynamic columns and query handling for empty lists * Remove jump on first attribute selection * Remove jump on first attribute selection * Fix search * Add debounce to search * CR - base state change on previous in popover * Extract search into separate component * Rename useDynamicColumnSettings to useColumnPickerSettings * Use difference from lodash * Improve static column rendering * Improve order list * Fix stories error * Improve search for edge cases * Extract messages * Calculate more complex dynamic column adapter parameters in separate functions * Fix url pointing to CardMenu substitute * Extract nodes to separate component * Move files, remove New prefix * Extract to static columns * Refactor utility functions * Render column picker categories only when provided in props * Replace switch with if statements * Refactor to hooks * Remove comments with legacy stacing * Add spaces for better readibility * Tighten types * Add space * Add extra comments to useColumns optimistic update logic * Fix paddings * Add arbitrary min/max height for handling various resolutions * Add full-width hover & click effect on candidate columns labels * Handle long attribute names * Make column picker popover a modal * Bump macaw-ui * Fix macaw-ui type mismatch * Update types * Add data-test-id * Fix closing picker with trigger button * Replace list settings deep merging with shallow merging * Fix list settings deep merging behaviour for arrays * Replace conditional data-test-id- with close-search * Rename targetArray to columnsToCheck * Rename filterColumns to filterSelectedColumns * Rename gridAttributes query objects to more descriptive * Add explainatory comment to customizer function in useListSettings * Update strictness * Fix rendering dynamic columns
2023-06-26 09:36:01 +00:00
disabled = false,
}) => (
<Dropdown>
<Dropdown.Trigger>
🏛️ Implement new column picker (#3514) * (wip) basic column picker implementation * (wip) fix stories error * (wip) fix custom column cells & sorting * (wip) Group attributes query values in props * (wip) Add docs * (wip) fix story error * Implement new column picker in order list * Fix search input padding * Fix empty settings crash * Fix empty settings crash * Portalize popover * Preselect category when there is only one * Remove legacy code * Move product column adapters to proper directory * Improve file structure * Rename custom columns to dynamic columns * Improve strings * (wip) Implement pagination logic * Beautify pagination * Update macaw-ui * Add unit test for useColumns * Improve naming * Code review style fixes * Update docs * Remove empty column * Remove unexpected padding from attribute columns * Add min height to prevent jumping * Fix typo in column picker files * CSS fixes to popover content * Implement auto-scroll to new column * Improve docs * Improve type in useColumns reducer * Extract dynamic columns from NewColumnPicker as a smaller component * Disable movement of empty column * Fix circular loader * Do not persist expanded state when closing picker * Fix dynamic columns with long names line break * Prevent user from disabling all static columns * Simplify dynamic column reducer into flatMap * Optimistic UIbasic implementation * Make available attributes query lazy * Fix displaying arrow next to sorted column * Add explainatory comment * Fix product list stories * Fix dynamic columns and query handling for empty lists * Remove jump on first attribute selection * Remove jump on first attribute selection * Fix search * Add debounce to search * CR - base state change on previous in popover * Extract search into separate component * Rename useDynamicColumnSettings to useColumnPickerSettings * Use difference from lodash * Improve static column rendering * Improve order list * Fix stories error * Improve search for edge cases * Extract messages * Calculate more complex dynamic column adapter parameters in separate functions * Fix url pointing to CardMenu substitute * Extract nodes to separate component * Move files, remove New prefix * Extract to static columns * Refactor utility functions * Render column picker categories only when provided in props * Replace switch with if statements * Refactor to hooks * Remove comments with legacy stacing * Add spaces for better readibility * Tighten types * Add space * Add extra comments to useColumns optimistic update logic * Fix paddings * Add arbitrary min/max height for handling various resolutions * Add full-width hover & click effect on candidate columns labels * Handle long attribute names * Make column picker popover a modal * Bump macaw-ui * Fix macaw-ui type mismatch * Update types * Add data-test-id * Fix closing picker with trigger button * Replace list settings deep merging with shallow merging * Fix list settings deep merging behaviour for arrays * Replace conditional data-test-id- with close-search * Rename targetArray to columnsToCheck * Rename filterColumns to filterSelectedColumns * Rename gridAttributes query objects to more descriptive * Add explainatory comment to customizer function in useListSettings * Update strictness * Fix rendering dynamic columns
2023-06-26 09:36:01 +00:00
<Button data-test-id={testId} onClick={onClick} disabled={disabled}>
{children}
<ChervonDownIcon />
</Button>
</Dropdown.Trigger>
<Dropdown.Content align="end">
<Box>
<List
padding={2}
borderRadius={4}
boxShadow="overlay"
backgroundColor="surfaceNeutralPlain"
>
{options.map((item, idx) => (
<Dropdown.Item key={`dropdown-item-${idx}`}>
<List.Item
borderRadius={4}
paddingX={1.5}
paddingY={2}
onClick={item.onSelect}
data-test-id={item.testId}
>
<Text>{item.label}</Text>
</List.Item>
</Dropdown.Item>
))}
</List>
</Box>
</Dropdown.Content>
</Dropdown>
);