From 36cbafe4ccd361345d70df513b01ac51f8b2732c Mon Sep 17 00:00:00 2001 From: josoriomarin <67794031+Jmarin123@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:28:17 -0400 Subject: [PATCH] Unset companies and owners (#1185) * unselect users and companies * Icon now works with theme --------- Co-authored-by: vboxuser Co-authored-by: Charles Bochet --- .../companies/components/CompanyPickerCell.tsx | 9 ++++++++- .../components/SingleEntitySelect.tsx | 4 +++- .../components/SingleEntitySelectBase.tsx | 18 ++++++++++++++++++ .../ui/table/hooks/useUpdateEntityField.ts | 3 +-- .../modules/users/components/UserPicker.tsx | 9 ++++++++- server/src/ability/ability.util.ts | 5 ++++- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/front/src/modules/companies/components/CompanyPickerCell.tsx b/front/src/modules/companies/components/CompanyPickerCell.tsx index 4e6f58d0e3..82ab41777f 100644 --- a/front/src/modules/companies/components/CompanyPickerCell.tsx +++ b/front/src/modules/companies/components/CompanyPickerCell.tsx @@ -77,7 +77,13 @@ export function CompanyPickerCell({ }); setIsCreating(false); } - + const noUser: EntityForSelect = { + entityType: Entity.Company, + id: '', + name: 'No Company', + avatarType: 'rounded', + avatarUrl: '', + }; return isCreating ? ( ); } diff --git a/front/src/modules/ui/input/relation-picker/components/SingleEntitySelect.tsx b/front/src/modules/ui/input/relation-picker/components/SingleEntitySelect.tsx index 93f5fb9be9..54e8e89670 100644 --- a/front/src/modules/ui/input/relation-picker/components/SingleEntitySelect.tsx +++ b/front/src/modules/ui/input/relation-picker/components/SingleEntitySelect.tsx @@ -27,6 +27,7 @@ export function SingleEntitySelect< onCancel, width, disableBackgroundBlur = false, + noUser, }: { onCancel?: () => void; onCreate?: () => void; @@ -34,6 +35,7 @@ export function SingleEntitySelect< onEntitySelected: (entity: CustomEntityForSelect | null | undefined) => void; disableBackgroundBlur?: boolean; width?: number; + noUser?: CustomEntityForSelect; }) { const containerRef = useRef(null); @@ -53,7 +55,6 @@ export function SingleEntitySelect< onCancel?.(); }, }); - return ( {showCreateButton && ( <> diff --git a/front/src/modules/ui/input/relation-picker/components/SingleEntitySelectBase.tsx b/front/src/modules/ui/input/relation-picker/components/SingleEntitySelectBase.tsx index 784d47a204..dbb0ce6d55 100644 --- a/front/src/modules/ui/input/relation-picker/components/SingleEntitySelectBase.tsx +++ b/front/src/modules/ui/input/relation-picker/components/SingleEntitySelectBase.tsx @@ -1,8 +1,10 @@ import { useRef } from 'react'; +import { useTheme } from '@emotion/react'; import { Key } from 'ts-key-enum'; import { DropdownMenuItem } from '@/ui/dropdown/components/DropdownMenuItem'; import { DropdownMenuSelectableItem } from '@/ui/dropdown/components/DropdownMenuSelectableItem'; +import { IconBuildingSkyscraper, IconUserCircle } from '@/ui/icon'; import { StyledDropdownMenuItemsContainer } from '@/ui/dropdown/components/StyledDropdownMenuItemsContainer'; import { OverflowingTextWithTooltip } from '@/ui/tooltip/OverflowingTextWithTooltip'; import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys'; @@ -12,6 +14,7 @@ import { isNonEmptyString } from '~/utils/isNonEmptyString'; import { useEntitySelectScroll } from '../hooks/useEntitySelectScroll'; import { EntityForSelect } from '../types/EntityForSelect'; +import { Entity } from '../types/EntityTypeForSelect'; import { RelationPickerHotkeyScope } from '../types/RelationPickerHotkeyScope'; import { DropdownMenuSkeletonItem } from './skeletons/DropdownMenuSkeletonItem'; @@ -30,10 +33,12 @@ export function SingleEntitySelectBase< entities, onEntitySelected, onCancel, + noUser, }: { entities: EntitiesForSingleEntitySelect; onEntitySelected: (entity: CustomEntityForSelect | null | undefined) => void; onCancel?: () => void; + noUser?: CustomEntityForSelect; }) { const containerRef = useRef(null); let entitiesInDropdown = isDefined(entities.selectedEntity) @@ -71,9 +76,22 @@ export function SingleEntitySelectBase< entitiesInDropdown = entitiesInDropdown.filter((entity) => isNonEmptyString(entity.name.trim()), ); + const theme = useTheme(); return ( + {noUser && ( + onEntitySelected(noUser)}> + {noUser.entityType === Entity.User ? ( + + ) : ( + + )} + {noUser.name} + + )} {entities.loading ? ( ) : entitiesInDropdown.length === 0 ? ( diff --git a/front/src/modules/ui/table/hooks/useUpdateEntityField.ts b/front/src/modules/ui/table/hooks/useUpdateEntityField.ts index d0c3a03af7..074fb9bdaf 100644 --- a/front/src/modules/ui/table/hooks/useUpdateEntityField.ts +++ b/front/src/modules/ui/table/hooks/useUpdateEntityField.ts @@ -91,8 +91,7 @@ export function useUpdateEntityField() { const newSelectedEntity = newFieldValueUnknown; const fieldName = viewField.metadata.fieldName; - - if (!newSelectedEntity) { + if (!newSelectedEntity || newSelectedEntity.id === '') { updateEntity({ variables: { where: { id: currentEntityId }, diff --git a/front/src/modules/users/components/UserPicker.tsx b/front/src/modules/users/components/UserPicker.tsx index 80fed0bd2a..a8fa580e4e 100644 --- a/front/src/modules/users/components/UserPicker.tsx +++ b/front/src/modules/users/components/UserPicker.tsx @@ -47,7 +47,13 @@ export function UserPicker({ ) { onSubmit(selectedUser ?? null); } - + const noUser: UserForSelect = { + entityType: Entity.User, + id: '', + name: 'No Owner', + avatarType: 'rounded', + avatarUrl: '', + }; return ( ); } diff --git a/server/src/ability/ability.util.ts b/server/src/ability/ability.util.ts index bba6c16810..ebf45c7a20 100644 --- a/server/src/ability/ability.util.ts +++ b/server/src/ability/ability.util.ts @@ -74,6 +74,10 @@ const simpleAbilityCheck: OperationAbilityChecker = async ( // Extract entity name from model name const entity = camelCase(modelName); + //TODO: Fix boolean data types so that disconnects are possible + if (typeof data === 'boolean') { + return true; + } // Handle all operations cases const operations = !Array.isArray(data) ? [data] : data; // Handle where case @@ -139,7 +143,6 @@ export async function relationAbilityChecker( // Extract operation name and value const operationType = Object.keys(operation)[0] as OperationType; const operationValue = operation[operationType]; - // Get operation checker for the operation type const operationChecker = operationAbilityCheckers[operationType];