From 828189d5d2cda9e7d628d2db3c9e33cd4ae57110 Mon Sep 17 00:00:00 2001 From: Klaudija Ljevar Date: Tue, 14 Nov 2023 08:32:27 +0100 Subject: [PATCH] Project and locale switcher changes (#3293) * chore: removing the counters from locale and project switchers * chore: setting up the width of the selectors * chore: remove the unneccessary class * chore: adding changeset * chore: move the logic to the private components * Update the changeset Co-authored-by: Nicola Molinari * chore: code improvements --------- Co-authored-by: Nicola Molinari --- .changeset/six-needles-kiss.md | 5 ++ .../locale-switcher/locale-switcher.tsx | 56 ++++++++--------- .../project-switcher/project-switcher.tsx | 60 ++++++++----------- 3 files changed, 53 insertions(+), 68 deletions(-) create mode 100644 .changeset/six-needles-kiss.md diff --git a/.changeset/six-needles-kiss.md b/.changeset/six-needles-kiss.md new file mode 100644 index 0000000000..7fa990d2d0 --- /dev/null +++ b/.changeset/six-needles-kiss.md @@ -0,0 +1,5 @@ +--- +'@commercetools-frontend/application-shell': patch +--- + +Removing the counters from locale and project switcher in the app bar. diff --git a/packages/application-shell/src/components/locale-switcher/locale-switcher.tsx b/packages/application-shell/src/components/locale-switcher/locale-switcher.tsx index fb337302d3..ab34124562 100644 --- a/packages/application-shell/src/components/locale-switcher/locale-switcher.tsx +++ b/packages/application-shell/src/components/locale-switcher/locale-switcher.tsx @@ -1,16 +1,18 @@ import { useCallback } from 'react'; import { css } from '@emotion/react'; import { FormattedMessage } from 'react-intl'; -import type { SingleValueProps, ValueContainerProps } from 'react-select'; +import type { + SingleValueProps, + ValueContainerProps, + MenuListProps, +} from 'react-select'; +import { components } from 'react-select'; import AccessibleHidden from '@commercetools-uikit/accessible-hidden'; import { designTokens } from '@commercetools-uikit/design-system'; import { WorldIcon } from '@commercetools-uikit/icons'; import SelectInput from '@commercetools-uikit/select-input'; import messages from './messages'; -type CustomSingleValueProps = SingleValueProps & { - localeCount: number; -}; type Props = { projectDataLocale: string; setProjectDataLocale: (locale: string) => void; @@ -19,7 +21,7 @@ type Props = { const LOCALE_SWITCHER_LABEL_ID = 'locale-switcher-label'; -export const SingleValue = (props: CustomSingleValueProps) => { +export const SingleValue = (props: SingleValueProps) => { return (
{ > {props.children} - - {props.localeCount} -
); }; @@ -66,6 +53,19 @@ const PatchedValueContainer = (props: ValueContainerProps) => ( ); PatchedValueContainer.displayName = 'PatchedValueContainer'; +const CustomMenuList = (props: MenuListProps) => { + return ( +
+ {props.children} +
+ ); +}; + const LocaleSwitcher = (props: Props) => { const { setProjectDataLocale } = props; const handleSelection = useCallback( @@ -75,12 +75,7 @@ const LocaleSwitcher = (props: Props) => { [setProjectDataLocale] ); return ( -
+
@@ -96,17 +91,14 @@ const LocaleSwitcher = (props: Props) => { value: locale, }))} components={{ - SingleValue: (valueProps: SingleValueProps) => ( - - ), + SingleValue, ValueContainer: PatchedValueContainer, + MenuList: CustomMenuList, }} isClearable={false} backspaceRemovesValue={false} isSearchable={false} + horizontalConstraint={'auto'} />
); diff --git a/packages/application-shell/src/components/project-switcher/project-switcher.tsx b/packages/application-shell/src/components/project-switcher/project-switcher.tsx index 7b4b1ce7e1..bf4efd5c98 100644 --- a/packages/application-shell/src/components/project-switcher/project-switcher.tsx +++ b/packages/application-shell/src/components/project-switcher/project-switcher.tsx @@ -1,7 +1,12 @@ import { css } from '@emotion/react'; import memoize from 'memoize-one'; import { FormattedMessage, useIntl } from 'react-intl'; -import type { OptionProps, ValueContainerProps } from 'react-select'; +import type { + OptionProps, + ValueContainerProps, + MenuListProps, +} from 'react-select'; +import { components } from 'react-select'; import { useMcQuery, oidcStorage, @@ -30,16 +35,10 @@ type Props = { type OptionType = Pick & { label: string; }; -type CustomValueContainerProps = ValueContainerProps & { - projectCount: number; -}; const PROJECT_SWITCHER_LABEL_ID = 'project-switcher-label'; -export const ProjectSwitcherValueContainer = ({ - projectCount, - ...restProps -}: CustomValueContainerProps) => { +export const ValueContainer = ({ ...restProps }: ValueContainerProps) => { return (
- - {projectCount} -
); }; @@ -148,6 +132,19 @@ const mapProjectsToOptions = memoize((projects) => })) ); +const CustomMenuList = (props: MenuListProps) => { + return ( +
+ {props.children} +
+ ); +}; + const redirectTo = (targetUrl: string) => location.replace(targetUrl); const ProjectSwitcher = (props: Props) => { @@ -165,11 +162,7 @@ const ProjectSwitcher = (props: Props) => { if (loading) return null; return ( -
+
@@ -201,19 +194,14 @@ const ProjectSwitcher = (props: Props) => { }} components={{ Option: ProjectSwitcherOption, - ValueContainer: (valueContainerProps) => ( - - ), + ValueContainer, + MenuList: CustomMenuList, }} isClearable={false} backspaceRemovesValue={false} placeholder={intl.formatMessage(messages.searchPlaceholder)} noOptionsMessage={() => intl.formatMessage(messages.noResults)} + horizontalConstraint={'auto'} />
);