Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbordeau committed Oct 9, 2024
1 parent 2a84df2 commit a3fba06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import styled from '@emotion/styled';
import { useMemo, useState } from 'react';
import { useRecoilValue } from 'recoil';
import {
IconApps,
IconComponent,
IconLayoutKanban,
IconTable,
useIcons,
} from 'twenty-ui';
import { IconApps, IconComponent, useIcons } from 'twenty-ui';

import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
Expand Down Expand Up @@ -35,7 +29,6 @@ export type IconPickerProps = {
variant?: IconButtonVariant;
className?: string;
disableBlur?: boolean;
takeControlOfCustomIcon?: boolean;
};

const StyledMenuIconItemsContainer = styled.div`
Expand Down Expand Up @@ -94,7 +87,6 @@ export const IconPicker = ({
variant = 'secondary',
disableBlur = false,
className,
takeControlOfCustomIcon = false,
}: IconPickerProps) => {
const [searchString, setSearchString] = useState('');
const {
Expand Down Expand Up @@ -155,15 +147,7 @@ export const IconPicker = ({
[matchingSearchIconKeys],
);

const getIconForIconPicker = () => {
if (
!takeControlOfCustomIcon &&
(selectedIconKey === 'table' || selectedIconKey === 'kanban')
) {
return selectedIconKey === 'table' ? IconTable : IconLayoutKanban;
}
return selectedIconKey ? getIcon(selectedIconKey) : IconApps;
};
const icon = selectedIconKey ? getIcon(selectedIconKey) : IconApps;

return (
<div className={className}>
Expand All @@ -178,7 +162,7 @@ export const IconPicker = ({
: `(no icon selected)`
}`}
disabled={disabled}
Icon={getIconForIconPicker()}
Icon={icon}
variant={variant}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { viewPickerIsPersistingComponentState } from '@/views/view-picker/states
import { viewPickerKanbanFieldMetadataIdComponentState } from '@/views/view-picker/states/viewPickerKanbanFieldMetadataIdComponentState';
import { viewPickerSelectedIconComponentState } from '@/views/view-picker/states/viewPickerSelectedIconComponentState';
import { viewPickerTypeComponentState } from '@/views/view-picker/states/viewPickerTypeComponentState';
import { useState } from 'react';

const StyledNoKanbanFieldAvailableContainer = styled.div`
color: ${({ theme }) => theme.font.color.light};
Expand All @@ -41,6 +42,7 @@ const StyledNoKanbanFieldAvailableContainer = styled.div`

export const ViewPickerContentCreateMode = () => {
const { setViewPickerMode } = useViewPickerMode();
const [hasManuallySelectedIcon, setHasManuallySelectedIcon] = useState(false);

const [viewPickerInputName, setViewPickerInputName] =
useRecoilComponentStateV2(viewPickerInputNameComponentState);
Expand Down Expand Up @@ -87,10 +89,17 @@ export const ViewPickerContentCreateMode = () => {
ViewsHotkeyScope.ListDropdown,
);

const defaultIcon =
viewPickerType === ViewType.Kanban ? 'IconLayoutKanban' : 'IconTable';

const selectedIcon = hasManuallySelectedIcon
? viewPickerSelectedIcon
: defaultIcon;

const onIconChange = ({ iconKey }: { iconKey: string }) => {
toggleTakeControlOfCustomIcon(true);
setViewPickerIsDirty(true);
setViewPickerSelectedIcon(iconKey);
setHasManuallySelectedIcon(true);
};

const handleClose = async () => {
Expand All @@ -107,12 +116,9 @@ export const ViewPickerContentCreateMode = () => {
<ViewPickerIconAndNameContainer>
<IconPicker
onChange={onIconChange}
selectedIconKey={
takeControlOfCustomIcon ? viewPickerSelectedIcon : viewPickerType
}
selectedIconKey={selectedIcon}
disableBlur
onClose={() => setHotkeyScope(ViewsHotkeyScope.ListDropdown)}
takeControlOfCustomIcon={takeControlOfCustomIcon}
/>
<DropdownMenuInput
value={viewPickerInputName}
Expand Down
5 changes: 4 additions & 1 deletion packages/twenty-ui/src/display/icon/hooks/useIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const useIcons = () => {
};

const getIcon = (iconKey?: string | null) => {
if (!iconKey) return defaultIcon;
if (!iconKey) {
return defaultIcon;
}

return icons[iconKey] ?? defaultIcon;
};

Expand Down

0 comments on commit a3fba06

Please sign in to comment.