Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: settings form select menu #9179

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { addressSchema as addressFieldDefaultValueSchema } from '@/object-record/record-field/types/guards/isFieldAddressValue';
import { SettingsOptionCardContentSelect } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSelect';
import { useCountries } from '@/ui/input/components/internal/hooks/useCountries';
import { Select } from '@/ui/input/components/Select';
import { IconMap } from 'twenty-ui';
import { Select, SelectOption } from '@/ui/input/components/Select';
import { IconCircleOff, IconComponentProps, IconMap } from 'twenty-ui';
import { z } from 'zod';
import { applySimpleQuotesToString } from '~/utils/string/applySimpleQuotesToString';
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
Expand Down Expand Up @@ -33,13 +33,16 @@ export const SettingsDataModelFieldAddressForm = ({
const { control } = useFormContext<SettingsDataModelFieldTextFormValues>();
const countries = useCountries()
.sort((a, b) => a.countryName.localeCompare(b.countryName))
.map((country) => ({
label: country.countryName,
value: country.countryName,
.map<SelectOption<string>>(({ countryName, Flag }) => ({
label: countryName,
value: countryName,
Icon: (props: IconComponentProps) =>
Flag({ width: props.size, height: props.size }),
}));
countries.unshift({
label: 'No country',
value: '',
Icon: IconCircleOff,
});
const defaultDefaultValue = {
addressStreet1: "''",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: addressStreet1 default value of "''" contains nested quotes which may cause issues. Consider using just '' or an empty string

Expand Down Expand Up @@ -69,7 +72,7 @@ export const SettingsDataModelFieldAddressForm = ({
description="The default country for new addresses"
>
<Select<string>
dropdownWidth={'auto'}
dropdownWidth={220}
disabled={disabled}
dropdownId="selectDefaultCountry"
value={stripSimpleQuotesFromString(defaultCountry)}
Expand All @@ -81,6 +84,7 @@ export const SettingsDataModelFieldAddressForm = ({
}
options={countries}
selectSizeVariant="small"
withSearchInput={true}
/>
</SettingsOptionCardContentSelect>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const SettingsDataModelFieldBooleanForm = ({
onChange={onChange}
dropdownId="object-field-default-value-select-boolean"
dropdownWidth={120}
needIconCheck={false}
options={[
{
value: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ export const SettingsDataModelFieldCurrencyForm = ({
description="Choose the default currency that will apply"
>
<Select<string>
dropdownWidth={'auto'}
dropdownWidth={220}
value={value}
onChange={onChange}
disabled={disabled}
dropdownId="object-field-default-value-select-currency"
options={OPTIONS}
selectSizeVariant="small"
withSearchInput={true}
/>
</SettingsOptionCardContentSelect>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const SettingsDataModelFieldNumberForm = ({
value={type}
onChange={(value) => onChange({ type: value, decimals: count })}
disabled={disabled}
needIconCheck={false}
options={[
{
Icon: IconNumber9,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled';
import { MouseEvent, useMemo, useRef, useState } from 'react';
import { IconComponent, MenuItem } from 'twenty-ui';
import { IconComponent, MenuItem, MenuItemSelect } from 'twenty-ui';

import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
Expand Down Expand Up @@ -43,6 +43,7 @@ export type SelectProps<Value extends SelectValue> = {
options: SelectOption<Value>[];
value?: Value;
withSearchInput?: boolean;
needIconCheck?: boolean;
callToActionButton?: CallToActionButton;
};

Expand Down Expand Up @@ -73,6 +74,7 @@ export const Select = <Value extends SelectValue>({
options,
value,
withSearchInput,
needIconCheck,
callToActionButton,
}: SelectProps<Value>) => {
const selectContainerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -148,10 +150,12 @@ export const Select = <Value extends SelectValue>({
{!!filteredOptions.length && (
<DropdownMenuItemsContainer hasMaxHeight>
{filteredOptions.map((option) => (
<MenuItem
<MenuItemSelect
key={`${option.value}-${option.label}`}
LeftIcon={option.Icon}
text={option.label}
selected={selectedOption.value === option.value}
needIconCheck={needIconCheck}
onClick={() => {
onChange?.(option.value);
onBlur?.();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const StyledMenuItemSelect = styled(StyledMenuItemBase)<{
type MenuItemSelectProps = {
LeftIcon?: IconComponent | null | undefined;
selected: boolean;
needIconCheck?: boolean;
text: string;
className?: string;
onClick?: () => void;
Expand All @@ -52,6 +53,7 @@ export const MenuItemSelect = ({
LeftIcon,
text,
selected,
needIconCheck = true,
className,
onClick,
disabled,
Expand All @@ -69,7 +71,7 @@ export const MenuItemSelect = ({
hovered={hovered}
>
<MenuItemLeftContent LeftIcon={LeftIcon} text={text} />
{selected && <IconCheck size={theme.icon.size.md} />}
{selected && needIconCheck && <IconCheck size={theme.icon.size.md} />}
{hasSubMenu && (
<IconChevronRight
size={theme.icon.size.sm}
Expand Down
Loading