Add ability to force picker width (#1093)

This commit is contained in:
Charles Bochet 2023-08-05 15:41:18 -07:00 committed by GitHub
parent 35395c2e67
commit 14f9e892d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 7 deletions

View File

@ -12,6 +12,7 @@ export type OwnProps = {
onSubmit: (newCompany: EntityForSelect | null) => void; onSubmit: (newCompany: EntityForSelect | null) => void;
onCancel?: () => void; onCancel?: () => void;
createModeEnabled?: boolean; createModeEnabled?: boolean;
width?: number;
}; };
export function CompanyPickerCell({ export function CompanyPickerCell({
@ -19,6 +20,7 @@ export function CompanyPickerCell({
onSubmit, onSubmit,
onCancel, onCancel,
createModeEnabled, createModeEnabled,
width,
}: OwnProps) { }: OwnProps) {
const [, setIsCreating] = useRecoilScopedState(isCreateModeScopedState); const [, setIsCreating] = useRecoilScopedState(isCreateModeScopedState);
@ -46,6 +48,7 @@ export function CompanyPickerCell({
return ( return (
<SingleEntitySelect <SingleEntitySelect
width={width}
onCreate={createModeEnabled ? handleCreate : undefined} onCreate={createModeEnabled ? handleCreate : undefined}
onCancel={onCancel} onCancel={onCancel}
onEntitySelected={handleEntitySelected} onEntitySelected={handleEntitySelected}

View File

@ -32,6 +32,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
contentFieldName: 'name', contentFieldName: 'name',
relationType: Entity.Company, relationType: Entity.Company,
}, },
isVisible: true,
} as ViewFieldDefinition<ViewFieldChipMetadata>, } as ViewFieldDefinition<ViewFieldChipMetadata>,
{ {
id: 'domainName', id: 'domainName',
@ -44,6 +45,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'domainName', fieldName: 'domainName',
placeHolder: 'example.com', placeHolder: 'example.com',
}, },
isVisible: true,
} as ViewFieldDefinition<ViewFieldURLMetadata>, } as ViewFieldDefinition<ViewFieldURLMetadata>,
{ {
id: 'accountOwner', id: 'accountOwner',
@ -56,6 +58,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'accountOwner', fieldName: 'accountOwner',
relationType: Entity.User, relationType: Entity.User,
}, },
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldRelationMetadata>, } satisfies ViewFieldDefinition<ViewFieldRelationMetadata>,
{ {
id: 'createdAt', id: 'createdAt',
@ -67,6 +70,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
type: 'date', type: 'date',
fieldName: 'createdAt', fieldName: 'createdAt',
}, },
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldDateMetadata>, } satisfies ViewFieldDefinition<ViewFieldDateMetadata>,
{ {
id: 'employees', id: 'employees',
@ -78,6 +82,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
type: 'number', type: 'number',
fieldName: 'employees', fieldName: 'employees',
}, },
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldNumberMetadata>, } satisfies ViewFieldDefinition<ViewFieldNumberMetadata>,
{ {
id: 'linkedin', id: 'linkedin',
@ -90,6 +95,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'linkedinUrl', fieldName: 'linkedinUrl',
placeHolder: 'LinkedIn URL', placeHolder: 'LinkedIn URL',
}, },
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldURLMetadata>, } satisfies ViewFieldDefinition<ViewFieldURLMetadata>,
{ {
id: 'address', id: 'address',
@ -102,5 +108,6 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'address', fieldName: 'address',
placeHolder: 'Address', // Hack: Fake character to prevent password-manager from filling the field placeHolder: 'Address', // Hack: Fake character to prevent password-manager from filling the field
}, },
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldTextMetadata>, } satisfies ViewFieldDefinition<ViewFieldTextMetadata>,
]; ];

View File

@ -1,6 +1,9 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
export const DropdownMenu = styled.div<{ disableBlur?: boolean }>` export const DropdownMenu = styled.div<{
disableBlur?: boolean;
width?: number;
}>`
backdrop-filter: ${({ disableBlur }) => backdrop-filter: ${({ disableBlur }) =>
disableBlur ? 'none' : 'blur(20px)'}; disableBlur ? 'none' : 'blur(20px)'};
@ -13,7 +16,7 @@ export const DropdownMenu = styled.div<{ disableBlur?: boolean }>`
flex-direction: column; flex-direction: column;
min-width: 160px;
overflow: hidden; overflow: hidden;
width: ${({ width }) => width ?? 160}px;
`; `;

View File

@ -30,6 +30,7 @@ export function SingleEntitySelect<
onEntitySelected, onEntitySelected,
onCreate, onCreate,
onCancel, onCancel,
width,
disableBackgroundBlur = false, disableBackgroundBlur = false,
}: { }: {
onCancel?: () => void; onCancel?: () => void;
@ -37,6 +38,7 @@ export function SingleEntitySelect<
entities: EntitiesForSingleEntitySelect<CustomEntityForSelect>; entities: EntitiesForSingleEntitySelect<CustomEntityForSelect>;
onEntitySelected: (entity: CustomEntityForSelect | null | undefined) => void; onEntitySelected: (entity: CustomEntityForSelect | null | undefined) => void;
disableBackgroundBlur?: boolean; disableBackgroundBlur?: boolean;
width?: number;
}) { }) {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
@ -58,7 +60,11 @@ export function SingleEntitySelect<
}); });
return ( return (
<DropdownMenu disableBlur={disableBackgroundBlur} ref={containerRef}> <DropdownMenu
disableBlur={disableBackgroundBlur}
ref={containerRef}
width={width}
>
<DropdownMenuSearch <DropdownMenuSearch
value={searchFilter} value={searchFilter}
onChange={handleSearchFilterChange} onChange={handleSearchFilterChange}

View File

@ -20,8 +20,6 @@ const StyledClickable = styled.div`
`; `;
export function RawLink({ className, href, children, onClick }: OwnProps) { export function RawLink({ className, href, children, onClick }: OwnProps) {
console.log(children);
return ( return (
<div> <div>
<StyledClickable className={className}> <StyledClickable className={className}>

View File

@ -54,6 +54,7 @@ export function GenericEditableRelationCellEditMode({ viewField }: OwnProps) {
companyId={fieldValueEntity?.id ?? null} companyId={fieldValueEntity?.id ?? null}
onSubmit={handleEntitySubmit} onSubmit={handleEntitySubmit}
onCancel={handleCancel} onCancel={handleCancel}
width={viewField.columnSize}
/> />
); );
} }
@ -63,6 +64,7 @@ export function GenericEditableRelationCellEditMode({ viewField }: OwnProps) {
userId={fieldValueEntity?.id ?? null} userId={fieldValueEntity?.id ?? null}
onSubmit={handleEntitySubmit} onSubmit={handleEntitySubmit}
onCancel={handleCancel} onCancel={handleCancel}
width={viewField.columnSize}
/> />
); );
} }

View File

@ -10,13 +10,14 @@ export type OwnProps = {
userId: string; userId: string;
onSubmit: (newUser: EntityForSelect | null) => void; onSubmit: (newUser: EntityForSelect | null) => void;
onCancel?: () => void; onCancel?: () => void;
width?: number;
}; };
type UserForSelect = EntityForSelect & { type UserForSelect = EntityForSelect & {
entityType: Entity.User; entityType: Entity.User;
}; };
export function UserPicker({ userId, onSubmit, onCancel }: OwnProps) { export function UserPicker({ userId, onSubmit, onCancel, width }: OwnProps) {
const [searchFilter] = useRecoilScopedState( const [searchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState, relationPickerSearchFilterScopedState,
); );
@ -44,6 +45,7 @@ export function UserPicker({ userId, onSubmit, onCancel }: OwnProps) {
return ( return (
<SingleEntitySelect <SingleEntitySelect
width={width}
onEntitySelected={handleEntitySelected} onEntitySelected={handleEntitySelected}
onCancel={onCancel} onCancel={onCancel}
entities={{ entities={{