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

Breadcrumb DropDown improvement #7546

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,3 +1,4 @@
import { SettingsFieldType } from '@/settings/data-model/types/SettingsFieldType';
import { Button } from '@/ui/input/button/components/Button';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
Expand All @@ -6,13 +7,18 @@ import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { IconChevronDown } from 'twenty-ui';
import {
useLocation,
useNavigate,
useParams,
useSearchParams,
} from 'react-router-dom';
import { IconChevronDown, isDefined } from 'twenty-ui';

const StyledContainer = styled.div`
align-items: center;
color: ${({ theme }) => theme.font.color.tertiary};
cursor: pointer;
cursor: default;
display: flex;
font-size: ${({ theme }) => theme.font.size.md};
`;
Expand All @@ -30,10 +36,24 @@ const StyledDownChevron = styled(IconChevronDown)`
transform: translateY(-50%);
`;

const StyledMenuItem = styled(MenuItem)<{ selected?: boolean }>`
const StyledMenuItemWrapper = styled.div<{ disabled?: boolean }>`
cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};
width: 100%;
`;

const StyledMenuItem = styled(MenuItem)<{
selected?: boolean;
disabled?: boolean;
}>`
background: ${({ theme, selected }) =>
selected ? theme.background.quaternary : 'transparent'};
cursor: pointer;
opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};
pointer-events: ${({ disabled }) => (disabled ? 'none' : 'auto')};

&:hover {
background: ${({ theme, disabled }) =>
disabled ? 'transparent' : theme.background.tertiary};
}
`;

const StyledSpan = styled.span`
Expand All @@ -51,15 +71,25 @@ export const SettingsDataModelNewFieldBreadcrumbDropDown = () => {
const navigate = useNavigate();
const location = useLocation();
const { objectSlug = '' } = useParams();
const [searchParams] = useSearchParams();
const theme = useTheme();

const fieldType = searchParams.get('fieldType') as SettingsFieldType;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a type guard or assertion function instead of type assertion

const isConfigureStep = location.pathname.includes('/configure');

const handleClick = (isConfigureStep: boolean) => {
if (isConfigureStep) {
navigate(`/settings/objects/${objectSlug}/new-field/configure`);
const handleClick = (step: 'select' | 'configure') => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: handleClick function could be simplified by using early returns

if (step === 'configure') {
if (isDefined(fieldType)) {
navigate(
`/settings/objects/${objectSlug}/new-field/configure?fieldType=${fieldType}`,
);
} else {
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
return;
}
} else {
navigate(`/settings/objects/${objectSlug}/new-field/select`);
navigate(
`/settings/objects/${objectSlug}/new-field/select${fieldType ? `?fieldType=${fieldType}` : ''}`,
);
}
closeDropdown();
};
Expand All @@ -83,16 +113,21 @@ export const SettingsDataModelNewFieldBreadcrumbDropDown = () => {
dropdownComponents={
<DropdownMenu>
<DropdownMenuItemsContainer>
<StyledMenuItem
text="1. Type"
onClick={() => handleClick(false)}
selected={!isConfigureStep}
/>
<StyledMenuItem
text="2. Configure"
onClick={() => handleClick(true)}
selected={isConfigureStep}
/>
<StyledMenuItemWrapper>
<StyledMenuItem
text="1. Type"
onClick={() => handleClick('select')}
selected={!isConfigureStep}
/>
</StyledMenuItemWrapper>
<StyledMenuItemWrapper disabled={!isDefined(fieldType)}>
<StyledMenuItem
text="2. Configure"
onClick={() => handleClick('configure')}
selected={isConfigureStep}
disabled={!isDefined(fieldType)}
/>
</StyledMenuItemWrapper>
</DropdownMenuItemsContainer>
</DropdownMenu>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { SETTINGS_FIELD_TYPE_CATEGORIES } from '@/settings/data-model/constants/
import { SETTINGS_FIELD_TYPE_CATEGORY_DESCRIPTIONS } from '@/settings/data-model/constants/SettingsFieldTypeCategoryDescriptions';
import { SETTINGS_FIELD_TYPE_CONFIGS } from '@/settings/data-model/constants/SettingsFieldTypeConfigs';
import { SettingsFieldTypeConfig } from '@/settings/data-model/constants/SettingsNonCompositeFieldTypeConfigs';

import { useBooleanSettingsFormInitialValues } from '@/settings/data-model/fields/forms/boolean/hooks/useBooleanSettingsFormInitialValues';
import { useCurrencySettingsFormInitialValues } from '@/settings/data-model/fields/forms/currency/hooks/useCurrencySettingsFormInitialValues';
import { useSelectSettingsFormInitialValues } from '@/settings/data-model/fields/forms/select/hooks/useSelectSettingsFormInitialValues';
Expand Down Expand Up @@ -63,7 +62,8 @@ export const SettingsObjectNewFieldSelector = ({
objectSlug,
}: SettingsObjectNewFieldSelectorProps) => {
const theme = useTheme();
const { control } = useFormContext<SettingsDataModelFieldTypeFormValues>();
const { control, setValue } =
useFormContext<SettingsDataModelFieldTypeFormValues>();
const [searchQuery, setSearchQuery] = useState('');
const fieldTypeConfigs = Object.entries<SettingsFieldTypeConfig<any>>(
SETTINGS_FIELD_TYPE_CONFIGS,
Expand Down Expand Up @@ -131,9 +131,10 @@ export const SettingsObjectNewFieldSelector = ({
<UndecoratedLink
to={`/settings/objects/${objectSlug}/new-field/configure?fieldType=${key}`}
fullWidth
onClick={() =>
resetDefaultValueField(key as SettingsFieldType)
}
onClick={() => {
setValue('type', key as SettingsFieldType);
resetDefaultValueField(key as SettingsFieldType);
}}
>
<SettingsCard
key={key}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export const SettingsObjectNewFieldConfigure = () => {
isSaveDisabled={!canSave}
isCancelDisabled={isSubmitting}
onCancel={() =>
navigate(`/settings/objects/${objectSlug}/new-field/select`)
navigate(
`/settings/objects/${objectSlug}/new-field/select?fieldType=${fieldType}`,
)
}
onSave={formConfig.handleSubmit(handleSave)}
/>
Expand Down
Loading