Skip to content

Commit

Permalink
Merge branch 'main' into upsert-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMalfait committed Jun 25, 2024
2 parents a54be3e + 3b7901b commit 47e08fe
Show file tree
Hide file tree
Showing 240 changed files with 3,808 additions and 2,110 deletions.
2 changes: 1 addition & 1 deletion packages/twenty-chrome-extension/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ export type Captcha = {
};

export enum CaptchaDriverType {
GoogleRecatpcha = 'GoogleRecatpcha',
GoogleRecaptcha = 'GoogleRecaptcha',
Turnstile = 'Turnstile'
}

Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-front/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const jestConfig: JestConfigWithTsJest = {
coverageThreshold: {
global: {
statements: 65,
lines: 65,
lines: 64,
functions: 55,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-front/src/generated-metadata/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export type Captcha = {
};

export enum CaptchaDriverType {
GoogleRecatpcha = 'GoogleRecatpcha',
GoogleRecaptcha = 'GoogleRecaptcha',
Turnstile = 'Turnstile'
}

Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export type Captcha = {
};

export enum CaptchaDriverType {
GoogleRecatpcha = 'GoogleRecatpcha',
GoogleRecaptcha = 'GoogleRecaptcha',
Turnstile = 'Turnstile'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CaptchaProviderScriptLoaderEffect = () => {
scriptElement = document.createElement('script');
scriptElement.src = scriptUrl;
scriptElement.onload = () => {
if (captchaProvider.provider === CaptchaDriverType.GoogleRecatpcha) {
if (captchaProvider.provider === CaptchaDriverType.GoogleRecaptcha) {
window.grecaptcha?.ready(() => {
setIsCaptchaScriptLoaded(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useRequestFreshCaptchaToken = () => {
let captchaWidget: any;

switch (captchaProvider.provider) {
case CaptchaDriverType.GoogleRecatpcha:
case CaptchaDriverType.GoogleRecaptcha:
window.grecaptcha
.execute(captchaProvider.siteKey, {
action: 'submit',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect } from '@storybook/test';

import { CaptchaDriverType } from '~/generated/graphql';

import { getCaptchaUrlByProvider } from '../getCaptchaUrlByProvider';

describe('getCaptchaUrlByProvider', () => {
it('handles GoogleRecaptcha', async () => {
const captchaUrl = getCaptchaUrlByProvider(
CaptchaDriverType.GoogleRecaptcha,
'siteKey',
);

expect(captchaUrl).toEqual(
'https://www.google.com/recaptcha/api.js?render=siteKey',
);

expect(() =>
getCaptchaUrlByProvider(CaptchaDriverType.GoogleRecaptcha, ''),
).toThrow(
'SiteKey must be provided while generating url for GoogleRecaptcha provider',
);
});

it('handles Turnstile', async () => {
const captchaUrl = getCaptchaUrlByProvider(CaptchaDriverType.Turnstile, '');

expect(captchaUrl).toEqual(
'https://challenges.cloudflare.com/turnstile/v0/api.js',
);
});

it('handles unknown provider', async () => {
expect(() =>
getCaptchaUrlByProvider('Unknown' as CaptchaDriverType, ''),
).toThrow('Unknown captcha provider');
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { CaptchaDriverType } from '~/generated-metadata/graphql';
import { isNonEmptyString } from '@sniptt/guards';

export const getCaptchaUrlByProvider = (name: string, siteKey: string) => {
if (!name) {
return '';
}
import { CaptchaDriverType } from '~/generated-metadata/graphql';

export const getCaptchaUrlByProvider = (
name: CaptchaDriverType,
siteKey: string,
) => {
switch (name) {
case CaptchaDriverType.GoogleRecatpcha:
case CaptchaDriverType.GoogleRecaptcha:
if (!isNonEmptyString(siteKey)) {
throw new Error(
'SiteKey must be provided while generating url for GoogleRecaptcha provider',
);
}
return `https://www.google.com/recaptcha/api.js?render=${siteKey}`;
case CaptchaDriverType.Turnstile:
return 'https://challenges.cloudflare.com/turnstile/v0/api.js';
default:
return '';
throw new Error('Unknown captcha provider');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getForeignDataWrapperType } from '../getForeignDataWrapperType';

describe('getForeignDataWrapperType', () => {
it('should handle postgres', () => {
expect(getForeignDataWrapperType('postgresql')).toBe('postgres_fdw');
});

it('should handle stripe', () => {
expect(getForeignDataWrapperType('stripe')).toBe('stripe_fdw');
});

it('should return null for unknown', () => {
expect(getForeignDataWrapperType('unknown')).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AppPath } from '@/types/AppPath';

import indexAppPath from '../indexAppPath';

describe('getIndexAppPath', () => {
it('returns the index app path', () => {
const { getIndexAppPath } = indexAppPath;
expect(getIndexAppPath()).toEqual(AppPath.Index);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({
FieldMetadataType.Address,
FieldMetadataType.Relation,
FieldMetadataType.Select,
FieldMetadataType.MultiSelect,
FieldMetadataType.Currency,
].includes(field.type)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export type UUIDFilter = {
is?: IsFilter;
};

export type RelationFilter = {
is?: IsFilter;
in?: UUIDFilterValue[];
};

export type BooleanFilter = {
eq?: boolean;
is?: IsFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Person } from '@/people/types/Person';

export const query = gql`
mutation CreatePeople($data: [PersonCreateInput!]!, $upsert: Boolean) {
createPeople(data: $data) {
createPeople(data: $data, upsert: $upsert) {
__typename
xLink {
label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { getPeopleMock } from '~/testing/mock-data/people';
const peopleMock = getPeopleMock();

export const query = gql`
query FindDuplicatePerson($id: ID!) {
personDuplicates(id: $id) {
query FindDuplicatePerson($id: [ID!]!) {
personDuplicates(ids: [$id]) {
edges {
node {
__typename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { RecoilRoot } from 'recoil';
import { useCreateManyRecordsMutation } from '@/object-record/hooks/useCreateManyRecordsMutation';

const expectedQueryTemplate = `
mutation CreatePeople($data: [PersonCreateInput!]!) {
createPeople(data: $data) {
mutation CreatePeople($data: [PersonCreateInput!]!, $upsert: Boolean) {
createPeople(data: $data, upsert: $upsert) {
__typename
xLink {
label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { RecoilRoot } from 'recoil';
import { useFindDuplicateRecordsQuery } from '@/object-record/hooks/useFindDuplicatesRecordsQuery';

const expectedQueryTemplate = `
query FindDuplicatePerson($id: ID!) {
personDuplicates(id: $id) {
query FindDuplicatePerson($ids: [ID!]!) {
personDuplicates(ids: $ids) {
edges {
node {
__typename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRecoilValue } from 'recoil';
import { ObjectFilterDropdownSearchInput } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownSearchInput';
import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';

import { MultipleFiltersDropdownFilterOnFilterChangedEffect } from './MultipleFiltersDropdownFilterOnFilterChangedEffect';
import { ObjectFilterDropdownDateInput } from './ObjectFilterDropdownDateInput';
Expand Down Expand Up @@ -36,13 +37,20 @@ export const MultipleFiltersDropdownContent = ({
const selectedOperandInDropdown = useRecoilValue(
selectedOperandInDropdownState,
);
const isEmptyOperand =
selectedOperandInDropdown &&
[ViewFilterOperand.IsEmpty, ViewFilterOperand.IsNotEmpty].includes(
selectedOperandInDropdown,
);

return (
<>
{!filterDefinitionUsedInDropdown ? (
<ObjectFilterDropdownFilterSelect />
) : isObjectFilterDropdownOperandSelectUnfolded ? (
<ObjectFilterDropdownOperandSelect />
) : isEmptyOperand ? (
<ObjectFilterDropdownOperandButton />
) : (
selectedOperandInDropdown && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { FilterDefinition } from '@/object-record/object-filter-dropdown/types/FilterDefinition';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
Expand Down Expand Up @@ -34,10 +35,27 @@ export const ObjectFilterDropdownOperandSelect = () => {
filterDefinitionUsedInDropdown?.type,
);

const handleOperangeChange = (newOperand: ViewFilterOperand) => {
const handleOperandChange = (newOperand: ViewFilterOperand) => {
const isEmptyOperand = [
ViewFilterOperand.IsEmpty,
ViewFilterOperand.IsNotEmpty,
].includes(newOperand);

setSelectedOperandInDropdown(newOperand);
setIsObjectFilterDropdownOperandSelectUnfolded(false);

if (isEmptyOperand) {
selectFilter?.({
id: v4(),
fieldMetadataId: filterDefinitionUsedInDropdown?.fieldMetadataId ?? '',
displayValue: '',
operand: newOperand,
value: '',
definition: filterDefinitionUsedInDropdown as FilterDefinition,
});
return;
}

if (
isDefined(filterDefinitionUsedInDropdown) &&
isDefined(selectedFilter)
Expand All @@ -63,7 +81,7 @@ export const ObjectFilterDropdownOperandSelect = () => {
<MenuItem
key={`select-filter-operand-${index}`}
onClick={() => {
handleOperangeChange(filterOperand);
handleOperandChange(filterOperand);
}}
text={getOperandLabel(filterOperand)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@ import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { getOperandsForFilterType } from '../getOperandsForFilterType';

describe('getOperandsForFilterType', () => {
const emptyOperands = [
ViewFilterOperand.IsEmpty,
ViewFilterOperand.IsNotEmpty,
];

const containsOperands = [
ViewFilterOperand.Contains,
ViewFilterOperand.DoesNotContain,
];

const numberOperands = [
ViewFilterOperand.GreaterThan,
ViewFilterOperand.LessThan,
];

const relationOperand = [ViewFilterOperand.Is, ViewFilterOperand.IsNot];

const testCases = [
['TEXT', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]],
['EMAIL', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]],
[
'FULL_NAME',
[ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain],
],
['ADDRESS', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]],
['LINK', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]],
['LINKS', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]],
['CURRENCY', [ViewFilterOperand.GreaterThan, ViewFilterOperand.LessThan]],
['NUMBER', [ViewFilterOperand.GreaterThan, ViewFilterOperand.LessThan]],
['DATE_TIME', [ViewFilterOperand.GreaterThan, ViewFilterOperand.LessThan]],
['RELATION', [ViewFilterOperand.Is, ViewFilterOperand.IsNot]],
['TEXT', [...containsOperands, ...emptyOperands]],
['EMAIL', [...containsOperands, ...emptyOperands]],
['FULL_NAME', [...containsOperands, ...emptyOperands]],
['ADDRESS', [...containsOperands, ...emptyOperands]],
['LINK', [...containsOperands, ...emptyOperands]],
['LINKS', [...containsOperands, ...emptyOperands]],
['CURRENCY', [...numberOperands, ...emptyOperands]],
['NUMBER', [...numberOperands, ...emptyOperands]],
['DATE_TIME', [...numberOperands, ...emptyOperands]],
['RELATION', [...relationOperand, ...emptyOperands]],
[undefined, []],
[null, []],
['UNKNOWN_TYPE', []],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const getOperandLabel = (
return 'Is not';
case ViewFilterOperand.IsNotNull:
return 'Is not null';
case ViewFilterOperand.IsEmpty:
return 'Is empty';
case ViewFilterOperand.IsNotEmpty:
return 'Is not empty';
default:
return '';
}
Expand All @@ -35,6 +39,10 @@ export const getOperandLabelShort = (
return ': Not';
case ViewFilterOperand.IsNotNull:
return ': NotNull';
case ViewFilterOperand.IsNotEmpty:
return ': NotEmpty';
case ViewFilterOperand.IsEmpty:
return ': Empty';
case ViewFilterOperand.GreaterThan:
return '\u00A0> ';
case ViewFilterOperand.LessThan:
Expand Down
Loading

0 comments on commit 47e08fe

Please sign in to comment.