saleor-dashboard/src/components/SingleAutocompleteSelectField/SingleAutocompleteSelectFieldContent.tsx

350 lines
9.5 KiB
TypeScript
Raw Normal View History

// @ts-strict-ignore
import chevronDown from "@assets/images/ChevronDown.svg";
import useElementScroll, {
isScrolledToBottom,
} from "@dashboard/hooks/useElementScroll";
import { FetchMoreProps } from "@dashboard/types";
import {
CircularProgress,
MenuItem,
Paper,
Typography,
} from "@material-ui/core";
import Add from "@material-ui/icons/Add";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import { makeStyles } from "@saleor/macaw-ui";
import clsx from "clsx";
2019-10-14 11:57:08 +00:00
import { GetItemPropsOptions } from "downshift";
import React, { ReactElement } from "react";
2019-10-15 10:33:14 +00:00
import SVG from "react-inlinesvg";
2019-10-14 11:57:08 +00:00
import { FormattedMessage } from "react-intl";
import Hr from "../Hr";
const menuItemHeight = 46;
const maxMenuItems = 5;
2019-10-14 14:17:03 +00:00
const offset = 24;
2019-10-14 11:57:08 +00:00
export type ChoiceValue = string;
export interface SingleAutocompleteChoiceType<
V extends ChoiceValue = ChoiceValue,
L = string,
> {
label: L;
value: V;
2019-10-14 11:57:08 +00:00
}
2020-02-10 16:07:17 +00:00
export interface SingleAutocompleteActionType {
label: string;
onClick: () => void;
}
2019-10-14 14:17:03 +00:00
export interface SingleAutocompleteSelectFieldContentProps
extends Partial<FetchMoreProps> {
2020-03-18 17:24:55 +00:00
add?: SingleAutocompleteActionType;
choices: Array<SingleAutocompleteChoiceType<string, string | JSX.Element>>;
2019-10-14 11:57:08 +00:00
displayCustomValue: boolean;
emptyOption: boolean;
getItemProps: (options: GetItemPropsOptions<string>) => any;
2019-10-14 11:57:08 +00:00
highlightedIndex: number;
inputValue: string;
isCustomValueSelected: boolean;
selectedItem: any;
Bump macaw to 0.3 (#1807) * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 12:34:20 +00:00
style?: React.CSSProperties;
2019-10-14 11:57:08 +00:00
}
const useStyles = makeStyles(
2019-10-28 16:16:49 +00:00
theme => ({
2020-02-10 16:07:17 +00:00
add: {
background: theme.palette.background.default,
border: `1px solid ${theme.palette.divider}`,
borderRadius: "100%",
height: 24,
marginRight: theme.spacing(),
width: 24,
2020-02-10 16:07:17 +00:00
},
2019-10-15 10:33:14 +00:00
arrowContainer: {
position: "relative",
2019-10-15 10:33:14 +00:00
},
arrowInnerContainer: {
alignItems: "center",
2019-10-28 16:16:49 +00:00
background:
theme.palette.type === "light"
? theme.palette.grey[50]
: theme.palette.grey[900],
2019-10-15 10:33:14 +00:00
bottom: 0,
color: theme.palette.grey[500],
2019-10-15 10:33:14 +00:00
display: "flex",
height: 30,
justifyContent: "center",
opacity: 1,
position: "absolute",
transition: theme.transitions.duration.short + "ms",
width: "100%",
2019-10-15 10:33:14 +00:00
},
2019-10-14 11:57:08 +00:00
content: {
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
maxHeight: `calc(${menuItemHeight * maxMenuItems}px + ${theme.spacing(
2,
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
)})`,
2019-10-14 11:57:08 +00:00
overflow: "scroll",
padding: 8,
2019-10-14 11:57:08 +00:00
},
2019-10-15 10:33:14 +00:00
hide: {
2019-12-02 15:48:19 +00:00
opacity: 0,
zIndex: -1,
2019-10-15 10:33:14 +00:00
},
2019-10-14 11:57:08 +00:00
hr: {
margin: theme.spacing(1, 0),
2019-10-14 11:57:08 +00:00
},
menuItem: {
height: "auto",
whiteSpace: "normal",
'&[aria-selected="true"]': {
backgroundColor: theme.palette.background.default,
},
2019-10-14 11:57:08 +00:00
},
2019-10-14 14:17:03 +00:00
progress: {},
progressContainer: {
display: "flex",
Bump macaw to 0.3 (#1807) * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 12:34:20 +00:00
justifyContent: "center",
padding: theme.spacing(1, 0),
2019-10-14 14:17:03 +00:00
},
2019-10-14 11:57:08 +00:00
root: {
2019-10-15 10:33:14 +00:00
borderBottomLeftRadius: 8,
borderBottomRightRadius: 8,
Bump macaw to 0.3 (#1807) * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 12:34:20 +00:00
margin: theme.spacing(1, 0),
2019-10-15 10:33:14 +00:00
overflow: "hidden",
zIndex: 22,
},
2019-10-14 11:57:08 +00:00
}),
{
name: "SingleAutocompleteSelectFieldContent",
},
2019-10-14 11:57:08 +00:00
);
function getChoiceIndex(
index: number,
emptyValue: boolean,
customValue: boolean,
add: boolean,
2019-10-14 11:57:08 +00:00
) {
let choiceIndex = index;
if (emptyValue) {
choiceIndex += 1;
}
if (customValue || add) {
2019-10-14 11:57:08 +00:00
choiceIndex += 2;
}
return choiceIndex;
}
2020-09-24 10:54:43 +00:00
const sliceSize = 20;
const SingleAutocompleteSelectFieldContent: React.FC<
SingleAutocompleteSelectFieldContentProps
> = props => {
2019-10-14 11:57:08 +00:00
const {
2020-02-10 16:07:17 +00:00
add,
2019-10-14 11:57:08 +00:00
choices,
displayCustomValue,
emptyOption,
getItemProps,
2019-10-14 14:17:03 +00:00
hasMore,
loading,
2019-10-14 11:57:08 +00:00
inputValue,
isCustomValueSelected,
2019-10-14 14:17:03 +00:00
selectedItem,
Bump macaw to 0.3 (#1807) * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 12:34:20 +00:00
onFetchMore,
style,
2019-10-14 11:57:08 +00:00
} = props;
2020-02-10 16:07:17 +00:00
if (!!add && !!displayCustomValue) {
throw new Error("Add and custom value cannot be displayed simultaneously");
}
2019-10-14 11:57:08 +00:00
const classes = useStyles(props);
const anchor = React.useRef<HTMLDivElement>();
const scrollPosition = useElementScroll(anchor);
2019-10-14 14:17:03 +00:00
const [calledForMore, setCalledForMore] = React.useState(false);
const [slice, setSlice] = React.useState(onFetchMore ? 10000 : sliceSize);
const [initialized, setInitialized] = React.useState(false);
2019-10-14 11:57:08 +00:00
2019-10-15 12:12:38 +00:00
const scrolledToBottom = isScrolledToBottom(anchor, scrollPosition, offset);
2019-10-14 11:57:08 +00:00
2019-10-14 14:17:03 +00:00
React.useEffect(() => {
🦄 Simple taxes (#2072) * Tax configuration - implement channels view (#2048) * Add channels view * Fix channels view import * Remove legacy stories references * Fix link in configuration * Update snapshots * Remove sample checkboxes props * Disable hover in country exceptions * Update snapshots * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Extract messages * Add ListItemLink component * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change codegen to build from custom schema * Build types * Update fragments * Add fixtures * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Update snapshots * Remove any from TaxSettings * Fix todos * Change relative marginLeft to before pseudoelement * Extract styles to seperate files * Change folder structure * Extract redirect logic to custom hook * Update snapshots * Fix comment * Add early return in channels view * Tax configuration - implement countries view (#2053) * Add channels view * Remove sample checkboxes props * Disable hover in country exceptions * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Remove any from TaxSettings * Add countries list view * Add TaxCountryMenu component * Add CountryList page * Change channels menu rows height * Change countries menu rows height * Add TaxInput component * Add tax classes rates to countries page * Fix search input padding * Add minmax to TaxInput * Add searching through tax class rates * Extract messages * Add better handlers * Add fullWidth to TaxInput * Specify type for TaxInputs * Remove spinboxes on firefox * Remove custom spinboxes * Remove maxHeight from menu rows * Post-rebase fix * Change setter to formchagne * Add TaxConfiguration fragment * Add isDefault field to taxClass * Add fixtures * Shape data * Replace useEffect with useTaxUrlRedirect * Fix country names in menu * Add country page story * Add early return in countries view * Unify loading states between channels and countries pages * Handle special chars and case insensitiveness in local search * Replace navigate function with ListItemLink * Move styles to seperate file * Move styles to seperate file * Migrate to strict null checks * Remove unnecessary optional chaining * Change overflow scroll to Y only * Add useMemo on finding selected country * Add useMemo on local search * Translate labels in page tabs * Change url from /taxes/classes to /taxes/tax-classes * Remove capitalization from strings * Extract messages * Bump macaw to 0.6.2 * Update snapshots * Add spinboxes explanation comment * Handle empty state * Add tax classes view (#2093) * Add TaxClass fragment * Build types * Add tax classes to fixtures * Add tax classes view * wip Add tax classes page * Add tax classes menu * Add TaxRate fragment * Extract logic * Handle loading state & add story * Extract messages * Update snapshots * Change schema building from schema back to introspection * Update schema * Update fragments * Build types * Update fixtures * Reshape data * Move styles to seperate file * Use getById * Add explicit undefined * Comment out unfinished modal stories * Update snapshots * Taxes - add API calls in channels view (#2106) * Build types * Add TaxRate fragment * Update snapshots * Add taxConfigurationList query * Add taxCountriesList query * Add TaxClassesList query * Rename TaxConfigurationsList query * Handle empty state * Fix types post-rebase * Add form to TaxChannelsPage * wip Add dialog for handling country exceptions * wip Fix dialog url * wip Add update exceptions handlers * Add dialog story * Fix type errors * Add mutation support * Fix types in story * Add transition state to submit button * Add notifier * Extract messages * Remove unused import * Add backlink in savebar * Update snapshots * Fix link in navigation * Update snapshots * Remove message from tax config error fragment * Add hook description * Use useStateFromProps * Remove error handling * Improve url & path function names * Use theme.spacing in TaxCountryDialog styles * Remove redundant key modification * Revert "Use useStateFromProps" This reverts commit d3c68b04701cf935e917d7baa3ed1361ca3446d5. * Move initial map to parent & add open dependency to countries state * Use useModalDialogOpen * Fix state update * Remove scrolls & add ellipsis in side menu * Center checkboxes * Update snapshots * Add fake div for list alignment * Trigger deployment * Close modal on submit * Remove divider on last ListItem * Align add country button * Wrap grid child in div to avoid card stretching * Update snapshots * Trigger changes in add/delete exceptions * Trigger change on expcetion checkboxes * Add trailing commas * Connect countries view to API (#2178) * Add empty states * Update countries view urls * Remove unused import * Add country modal to countries view * Update schema * Implement country view mutations & error fragments * Implement tax class update mutation * Add sidebar temporary state for new configs * Remove unused imports * Wrap in form * Add savebar & fix search * Update schema * Add form wrapper * Fix types * Extract messages * Bump macaw * Update snapshots * Fix comma dangles * Update snapshots * Notify about mutation success * Add logic for mixing current and new rates * Workaround for sending null rates * Fix filling form with correct data after submitting * Handle deleting configuration * Fix selected banner * Remove leftover comment * Add handler for country configuration delete * Trigger deployment * Clean up useEffects causing infinite render loops * Sort countries from api by name * Fix card bottom padding * Remove bottom divider & fix padding * Remove scroll wrapper in side menu * Update snapshots * Remove scroll wrapper from tax classes menu * Update snapshots * Refresh form to initial onSubmit * Revert "Refresh form to initial onSubmit" This reverts commit 42414237d35086da63f4aa088c8072411429b1d8. * Allow only 3 decimal characters in tax inputs * Update snapshots * Update schema * Update types * Change logic from default tax class to null class * Fix sorting * Send empty country rates as nulls in mutation * Extract messages * Update lockfile * Update schema * Drop default tax classes * Update snapshots * Post-rebase fixes * Connect tax classes view to API (#2334) * Add mutations * Handle empty state * Wrap page in form * Update stories * Build types * Handle tax class delete * Handle update tax class * Update stories * Handle tax class change name * Add mutation state to savebar * Handle creating new tax classes * Extract messages * Specify type * Update stories * Sort rates * Fix skeleton rendering * Remove placeholders * Fix skeleton rendering on country list * Update snapshots * Change initial pagination to 100 * Disallow creating multiple new tax classes * Disallow creating multiple country configurations * Fix messages * Autofocus on new tax class name * Add country name to header * Temporarily comment out broken code in tax channels * Update snapshots * Update snapshots post-rebase * Add tax strategies & assigning tax classes (#2369) * Update fragments * Add optional merging in useForm * Handle tax strategies * Update snapshots * Update fixtures * Extract messages * Remove unused shop query fields * Fix breaking bug when fetchMore is used in non-searchable SingleAutocompleteSelectFields * Migrate product types to tax classes * Add tax classes to shipping methods * Use encapsulated logic in product types * Fix product type stories * Fix shipping fixtures * Fix product type type mismatch * Fix shipping stories * Fix product type fixtures * Fix mismatching types * Extract messages * Update snapshots * Update snapshots * Fix comment * Drop deprecated graphql fields * Replace tax types with tax classes in product create view * Replace tax types with tax classes in product update view * Fix tests, stories, fixtures * Extract messages * Update snapshots * Move status messages to commonStatusMessages * Handle empty array case in tax class change handler * Reuse messages * Simple taxes bugfixes (#2395) * Fix tax channels menu - dense layout * Change view names to fit convention * Fix per country exceptions in tax channels view * Fix skeleton rendering on tax countries card title * Filter out existing countries from modal * Update snapshots * Fix deleting country configuration * Disallow negative values in tax inputs * Handle empty tax classes view * Allow empty options in shipping & product types views tax class assignment field * Modify undefined rates in tax classes view * Update macaw-ui * Fix UI on channels view * Fix UI on countries view * Fix UI on countries view * Align tax class rate label to the right * Updaste snapshots * Extract messages * Fix adding rates on new tax class * Fix key errors * Update schema * Build types * Allow empty rates in taxClassUpdate mutation * Extract tax channels change country function as a handler * Deprecate useStateFromProps * Change useStateFromProps to useStateUpdate * Fix dividers * Delete delete icon on new tax classes * Update snapshots * Update lockfile * Update macaw to 0.6.6 * Update snapshots * Specify type of input in country change handler * Extract autofocus logic to custom hook * Replace alternative with switch statement * Extract country exclusion logic from JSX * Update lockfile * Update lockfile * Trigger deployment * Fix invisible select markers * Fix linter issue * Fix crashing product details page * Fix e2e error * Update snapshots * Allow view taxes with any staff permissions (#2510) * Update after rebase Co-authored-by: Dawid <tarasiukdawid@gmail.com>
2022-11-17 12:48:50 +00:00
if (!calledForMore && onFetchMore && scrolledToBottom && hasMore) {
2019-10-14 14:17:03 +00:00
onFetchMore();
setCalledForMore(true);
} else if (scrolledToBottom && !onFetchMore) {
2020-09-24 10:54:43 +00:00
setSlice(slice => slice + sliceSize);
2019-10-14 14:17:03 +00:00
}
}, [scrolledToBottom]);
2020-09-24 10:54:43 +00:00
React.useEffect(() => {
if (!onFetchMore) {
setSlice(sliceSize);
}
}, [choices?.length]);
React.useEffect(() => {
if (anchor.current?.scrollTo && !initialized) {
2020-10-12 10:45:07 +00:00
anchor.current.scrollTo({
top: 0,
2020-10-12 10:45:07 +00:00
});
setInitialized(true);
2020-10-12 10:45:07 +00:00
}
}, [initialized]);
2020-09-24 10:54:43 +00:00
React.useEffect(() => {
setInitialized(false);
}, [inputValue]);
2019-10-14 14:17:03 +00:00
React.useEffect(() => {
if (calledForMore && !loading) {
setCalledForMore(false);
}
}, [loading]);
2020-10-12 10:45:07 +00:00
const emptyOptionProps = getItemProps({
item: "",
2020-10-12 10:45:07 +00:00
});
const choicesToDisplay = choices.slice(0, slice);
2019-10-14 11:57:08 +00:00
return (
New datagrid view for product variant management (#2162) * New datagrid view for product variant management (#2040) * Split simple and product with variants updates * Simplify code * Change selectedVariantsIds to availableVariants selectedVariantsIds suggested that these variants *were just* selected * Add datagrid component Add datagrid component Add actions column Add column picker Add ts-ignore comment Remove unused import Fix after rebase Add story Fix column picking Fix column dragging Add column resizing Extract components to own files Apply styles from class Improve data storage Extract state to hook Expose handlers Fix styles Fix header overflow Add select all option Add cell types Fix types Add number type cell Add min to stocks Fix types Generate columns from shop data Add number type editor Fix tests Update src/components/Datagrid/Datagrid.tsx Co-authored-by: Jonatan Witoszek <jonatanwitoszek@gmail.com> Reconstruct data after column toggling Minor fixes Add missing id Remove unused import Fix container width Keep changes in state Drop onChange usage Use glide datagrid * Add column picker * Memoize callbacks * Add right toolbar * Make toolbar as prop * Clean up code * Fix styling * Lint files * Save variant data in datagrid (#2161) * Allow rows to be deleted * Add row adding * Clean up code * Improve mutations * Add stock saving * Add sku and attribute saving * Display notification after all mutations * Fix types * Save channels in datagrid (#2197) * wip * Merge simple and variantable handlers * Move channel setting to form * Link availability card to form * Extract listing management to hook * Update only touched channels * Improve channel listing managemend * Display channel data in datagrid * Save variant channels * Save changes in channel listings * Group columns * Fix types * Display touched fields * Return errors from hook * Display errors in cells * Improve naming * Improve naming * Use reliable called/loading state * Update src/components/Datagrid/cells.ts Co-authored-by: Michał Droń <dron.official@yahoo.com> * Apply fixes from review Co-authored-by: Michał Droń <dron.official@yahoo.com> * Fix type error * Trigger CI * Trigger CI * Save added and deleted variants (#2237) * Save new variants * Update channel data * Remove bulk variant delete dialog * Do not fetch products from api after save * Extract types * Reset errors after api response * Display error when creating variants * Fix variant reordering * Remove commented code * Fix imports * Edit attributes in datagrid (#2305) * Add basic dropdown cell * Fix clickaway * Add choice customization * Add callback to fetch choices * Add attriute value search * wip * Pass getSuggestions cb using props * Fix row adding * Fix choice creation * Add styles to datagrid (#2315) * Improve cell styling * Prevent navigation when scrolling horizontally * Fix text editor styles * Remove unused variable * Update whole row after editing cell * Translate column names * Improve empty message * Highlight newly created rows * Add name editing * Add disabled context menu to added rows * Add column groups * Translate column groups names * Save edited name * Fix missing column id error * Add card to datagrid * Improve shadow on scroll * Improve fonts * Fix toolbar placement * Update api type definitions * Fix copypasting from excel * Fix editor font weight * Improve dark theme * Improve cell coloring * Drop styling from story * Add docs to datagrid (#2339) * Add docs * Add summary * Datagrid fix bugs (#2341) * Pass refetch to form to avoid double calls * Add missing prop * Remove paddings (#2352) * remove paddings * remove paddings * remove paddings * remove vertical scroll * update tests * styles, currency * Fix variants tests in datagrid (#2365) * refactor variant test after adding datagrid * adding assertion to check if datagrid table is visible * adding check for datagrid * fix flaky tests in variants * fix flaky tests in variants * small changes * amedments * update styles * refactoring, handle prices * update snapshots * messages * snap * scrolling handle, css for safari * snap, random mock * update overflow * history back hook * fix cross-price changing, scroll optimization * trigger ci * channel checking when adding new variant Co-authored-by: Michał Droń <dron.official@yahoo.com> Co-authored-by: Patryk Andrzejewski <vox3r69@gmail.com> Co-authored-by: Ewa Czerniak <ewa.czerniak@saleor.io>
2022-10-18 09:10:15 +00:00
<Paper
// click-outside-ignore is used by glide-datagrid
className={clsx("click-outside-ignore", classes.root)}
New datagrid view for product variant management (#2162) * New datagrid view for product variant management (#2040) * Split simple and product with variants updates * Simplify code * Change selectedVariantsIds to availableVariants selectedVariantsIds suggested that these variants *were just* selected * Add datagrid component Add datagrid component Add actions column Add column picker Add ts-ignore comment Remove unused import Fix after rebase Add story Fix column picking Fix column dragging Add column resizing Extract components to own files Apply styles from class Improve data storage Extract state to hook Expose handlers Fix styles Fix header overflow Add select all option Add cell types Fix types Add number type cell Add min to stocks Fix types Generate columns from shop data Add number type editor Fix tests Update src/components/Datagrid/Datagrid.tsx Co-authored-by: Jonatan Witoszek <jonatanwitoszek@gmail.com> Reconstruct data after column toggling Minor fixes Add missing id Remove unused import Fix container width Keep changes in state Drop onChange usage Use glide datagrid * Add column picker * Memoize callbacks * Add right toolbar * Make toolbar as prop * Clean up code * Fix styling * Lint files * Save variant data in datagrid (#2161) * Allow rows to be deleted * Add row adding * Clean up code * Improve mutations * Add stock saving * Add sku and attribute saving * Display notification after all mutations * Fix types * Save channels in datagrid (#2197) * wip * Merge simple and variantable handlers * Move channel setting to form * Link availability card to form * Extract listing management to hook * Update only touched channels * Improve channel listing managemend * Display channel data in datagrid * Save variant channels * Save changes in channel listings * Group columns * Fix types * Display touched fields * Return errors from hook * Display errors in cells * Improve naming * Improve naming * Use reliable called/loading state * Update src/components/Datagrid/cells.ts Co-authored-by: Michał Droń <dron.official@yahoo.com> * Apply fixes from review Co-authored-by: Michał Droń <dron.official@yahoo.com> * Fix type error * Trigger CI * Trigger CI * Save added and deleted variants (#2237) * Save new variants * Update channel data * Remove bulk variant delete dialog * Do not fetch products from api after save * Extract types * Reset errors after api response * Display error when creating variants * Fix variant reordering * Remove commented code * Fix imports * Edit attributes in datagrid (#2305) * Add basic dropdown cell * Fix clickaway * Add choice customization * Add callback to fetch choices * Add attriute value search * wip * Pass getSuggestions cb using props * Fix row adding * Fix choice creation * Add styles to datagrid (#2315) * Improve cell styling * Prevent navigation when scrolling horizontally * Fix text editor styles * Remove unused variable * Update whole row after editing cell * Translate column names * Improve empty message * Highlight newly created rows * Add name editing * Add disabled context menu to added rows * Add column groups * Translate column groups names * Save edited name * Fix missing column id error * Add card to datagrid * Improve shadow on scroll * Improve fonts * Fix toolbar placement * Update api type definitions * Fix copypasting from excel * Fix editor font weight * Improve dark theme * Improve cell coloring * Drop styling from story * Add docs to datagrid (#2339) * Add docs * Add summary * Datagrid fix bugs (#2341) * Pass refetch to form to avoid double calls * Add missing prop * Remove paddings (#2352) * remove paddings * remove paddings * remove paddings * remove vertical scroll * update tests * styles, currency * Fix variants tests in datagrid (#2365) * refactor variant test after adding datagrid * adding assertion to check if datagrid table is visible * adding check for datagrid * fix flaky tests in variants * fix flaky tests in variants * small changes * amedments * update styles * refactoring, handle prices * update snapshots * messages * snap * scrolling handle, css for safari * snap, random mock * update overflow * history back hook * fix cross-price changing, scroll optimization * trigger ci * channel checking when adding new variant Co-authored-by: Michał Droń <dron.official@yahoo.com> Co-authored-by: Patryk Andrzejewski <vox3r69@gmail.com> Co-authored-by: Ewa Czerniak <ewa.czerniak@saleor.io>
2022-10-18 09:10:15 +00:00
elevation={8}
style={style}
>
<div
className={classes.content}
ref={anchor}
data-test-id="autocomplete-dropdown"
aria-label="autocomplete-dropdown"
>
2019-10-14 11:57:08 +00:00
{choices.length > 0 || displayCustomValue ? (
<>
{emptyOption && (
2019-10-14 11:57:08 +00:00
<MenuItem
className={classes.menuItem}
component="div"
data-test-id="single-autocomplete-select-option"
2020-10-12 10:45:07 +00:00
data-test-type="empty"
{...emptyOptionProps}
2019-10-14 11:57:08 +00:00
>
<Typography color="textSecondary">
<FormattedMessage id="450Fty" defaultMessage="None" />
2019-10-14 11:57:08 +00:00
</Typography>
</MenuItem>
)}
2020-02-10 16:07:17 +00:00
{add && (
<MenuItem
className={classes.menuItem}
component="div"
{...getItemProps({
item: inputValue,
2020-02-10 16:07:17 +00:00
})}
data-test-id="single-autocomplete-select-option-add"
2020-10-12 10:45:07 +00:00
data-test-type="add"
2020-02-10 16:07:17 +00:00
onClick={add.onClick}
>
<Add color="primary" className={classes.add} />
<Typography color="primary">{add.label}</Typography>
</MenuItem>
)}
2019-10-14 11:57:08 +00:00
{displayCustomValue && (
<MenuItem
className={classes.menuItem}
key={"customValue"}
selected={isCustomValueSelected}
component="div"
{...getItemProps({
item: inputValue,
2019-10-14 11:57:08 +00:00
})}
data-test-id="single-autocomplete-select-option"
2020-10-12 10:45:07 +00:00
data-test-type="custom"
2019-10-14 11:57:08 +00:00
>
<FormattedMessage
id="U2WgwW"
2019-10-14 11:57:08 +00:00
defaultMessage="Add new value: {value}"
description="add custom select input option"
values={{
value: inputValue,
2019-10-14 11:57:08 +00:00
}}
/>
</MenuItem>
)}
2020-02-10 16:07:17 +00:00
{choices.length > 0 && (!!add || displayCustomValue) && (
2019-10-14 11:57:08 +00:00
<Hr className={classes.hr} />
)}
{choicesToDisplay.map((suggestion, index) => {
2019-10-14 11:57:08 +00:00
const choiceIndex = getChoiceIndex(
index,
emptyOption,
displayCustomValue,
!!add,
2019-10-14 11:57:08 +00:00
);
const key = React.isValidElement(suggestion.label)
? `${index}${suggestion.value}${
(suggestion as unknown as ReactElement).props
}`
: JSON.stringify(suggestion);
2019-10-14 11:57:08 +00:00
return (
<MenuItem
className={classes.menuItem}
key={key}
2019-10-28 16:16:49 +00:00
selected={selectedItem === suggestion.value}
2019-10-14 11:57:08 +00:00
component="div"
{...getItemProps({
index: choiceIndex,
item: suggestion.value,
2019-10-14 11:57:08 +00:00
})}
data-test-id="single-autocomplete-select-option"
2020-10-12 10:45:07 +00:00
data-test-value={suggestion.value}
data-test-type="option"
2019-10-14 11:57:08 +00:00
>
{suggestion.label}
</MenuItem>
);
})}
2019-10-14 14:17:03 +00:00
{hasMore && (
<>
<Hr className={classes.hr} />
<div className={classes.progressContainer}>
<CircularProgress className={classes.progress} size={24} />
</div>
</>
)}
2019-10-14 11:57:08 +00:00
</>
) : (
<MenuItem
disabled={true}
component="div"
data-test-id="single-autocomplete-select-no-options"
2019-10-14 11:57:08 +00:00
>
<FormattedMessage id="hX5PAb" defaultMessage="No results found" />
2019-10-14 11:57:08 +00:00
</MenuItem>
)}
</div>
2019-11-29 12:19:18 +00:00
{choices.length > maxMenuItems && (
<div className={classes.arrowContainer}>
<div
className={clsx(classes.arrowInnerContainer, {
// Needs to be explicitly compared to false because
2019-11-29 12:19:18 +00:00
// scrolledToBottom can be either true, false or undefined
[classes.hide]: scrolledToBottom,
2019-11-29 12:19:18 +00:00
})}
>
<SVG src={chevronDown} />
</div>
2019-10-15 10:33:14 +00:00
</div>
2019-11-29 12:19:18 +00:00
)}
2019-10-14 11:57:08 +00:00
</Paper>
);
};
SingleAutocompleteSelectFieldContent.displayName =
"SingleAutocompleteSelectFieldContent";
export default SingleAutocompleteSelectFieldContent;