Skip to content

Commit

Permalink
Add ability to force picker width (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet authored Aug 5, 2023
1 parent 35395c2 commit 14f9e89
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions front/src/modules/companies/components/CompanyPickerCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export type OwnProps = {
onSubmit: (newCompany: EntityForSelect | null) => void;
onCancel?: () => void;
createModeEnabled?: boolean;
width?: number;
};

export function CompanyPickerCell({
companyId,
onSubmit,
onCancel,
createModeEnabled,
width,
}: OwnProps) {
const [, setIsCreating] = useRecoilScopedState(isCreateModeScopedState);

Expand Down Expand Up @@ -46,6 +48,7 @@ export function CompanyPickerCell({

return (
<SingleEntitySelect
width={width}
onCreate={createModeEnabled ? handleCreate : undefined}
onCancel={onCancel}
onEntitySelected={handleEntitySelected}
Expand Down
7 changes: 7 additions & 0 deletions front/src/modules/companies/constants/companyViewFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
contentFieldName: 'name',
relationType: Entity.Company,
},
isVisible: true,
} as ViewFieldDefinition<ViewFieldChipMetadata>,
{
id: 'domainName',
Expand All @@ -44,6 +45,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'domainName',
placeHolder: 'example.com',
},
isVisible: true,
} as ViewFieldDefinition<ViewFieldURLMetadata>,
{
id: 'accountOwner',
Expand All @@ -56,6 +58,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'accountOwner',
relationType: Entity.User,
},
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldRelationMetadata>,
{
id: 'createdAt',
Expand All @@ -67,6 +70,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
type: 'date',
fieldName: 'createdAt',
},
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldDateMetadata>,
{
id: 'employees',
Expand All @@ -78,6 +82,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
type: 'number',
fieldName: 'employees',
},
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldNumberMetadata>,
{
id: 'linkedin',
Expand All @@ -90,6 +95,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'linkedinUrl',
placeHolder: 'LinkedIn URL',
},
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldURLMetadata>,
{
id: 'address',
Expand All @@ -102,5 +108,6 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
fieldName: 'address',
placeHolder: 'Addre​ss', // Hack: Fake character to prevent password-manager from filling the field
},
isVisible: true,
} satisfies ViewFieldDefinition<ViewFieldTextMetadata>,
];
9 changes: 6 additions & 3 deletions front/src/modules/ui/dropdown/components/DropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import styled from '@emotion/styled';

export const DropdownMenu = styled.div<{ disableBlur?: boolean }>`
export const DropdownMenu = styled.div<{
disableBlur?: boolean;
width?: number;
}>`
backdrop-filter: ${({ disableBlur }) =>
disableBlur ? 'none' : 'blur(20px)'};
Expand All @@ -13,7 +16,7 @@ export const DropdownMenu = styled.div<{ disableBlur?: boolean }>`
flex-direction: column;
min-width: 160px;
overflow: hidden;
width: ${({ width }) => width ?? 160}px;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export function SingleEntitySelect<
onEntitySelected,
onCreate,
onCancel,
width,
disableBackgroundBlur = false,
}: {
onCancel?: () => void;
onCreate?: () => void;
entities: EntitiesForSingleEntitySelect<CustomEntityForSelect>;
onEntitySelected: (entity: CustomEntityForSelect | null | undefined) => void;
disableBackgroundBlur?: boolean;
width?: number;
}) {
const containerRef = useRef<HTMLDivElement>(null);

Expand All @@ -58,7 +60,11 @@ export function SingleEntitySelect<
});

return (
<DropdownMenu disableBlur={disableBackgroundBlur} ref={containerRef}>
<DropdownMenu
disableBlur={disableBackgroundBlur}
ref={containerRef}
width={width}
>
<DropdownMenuSearch
value={searchFilter}
onChange={handleSearchFilterChange}
Expand Down
2 changes: 0 additions & 2 deletions front/src/modules/ui/link/components/RawLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const StyledClickable = styled.div`
`;

export function RawLink({ className, href, children, onClick }: OwnProps) {
console.log(children);

return (
<div>
<StyledClickable className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function GenericEditableRelationCellEditMode({ viewField }: OwnProps) {
companyId={fieldValueEntity?.id ?? null}
onSubmit={handleEntitySubmit}
onCancel={handleCancel}
width={viewField.columnSize}
/>
);
}
Expand All @@ -63,6 +64,7 @@ export function GenericEditableRelationCellEditMode({ viewField }: OwnProps) {
userId={fieldValueEntity?.id ?? null}
onSubmit={handleEntitySubmit}
onCancel={handleCancel}
width={viewField.columnSize}
/>
);
}
Expand Down
4 changes: 3 additions & 1 deletion front/src/modules/users/components/UserPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export type OwnProps = {
userId: string;
onSubmit: (newUser: EntityForSelect | null) => void;
onCancel?: () => void;
width?: number;
};

type UserForSelect = EntityForSelect & {
entityType: Entity.User;
};

export function UserPicker({ userId, onSubmit, onCancel }: OwnProps) {
export function UserPicker({ userId, onSubmit, onCancel, width }: OwnProps) {
const [searchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState,
);
Expand Down Expand Up @@ -44,6 +45,7 @@ export function UserPicker({ userId, onSubmit, onCancel }: OwnProps) {

return (
<SingleEntitySelect
width={width}
onEntitySelected={handleEntitySelected}
onCancel={onCancel}
entities={{
Expand Down

0 comments on commit 14f9e89

Please sign in to comment.