forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify field preview logic in Settings (twentyhq#5541)
Closes twentyhq#5382 TODO: - [x] Test all field previews in app - [x] Fix tests - [x] Fix JSON preview
- Loading branch information
1 parent
1ae7fbe
commit c7d61e1
Showing
33 changed files
with
1,182 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../modules/object-record/record-field/validation-schemas/currencyFieldDefaultValueSchema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { z } from 'zod'; | ||
|
||
import { CurrencyCode } from '@/object-record/record-field/types/CurrencyCode'; | ||
import { currencyCodeSchema } from '@/object-record/record-field/validation-schemas/currencyCodeSchema'; | ||
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString'; | ||
import { simpleQuotesStringSchema } from '~/utils/validation-schemas/simpleQuotesStringSchema'; | ||
|
||
export const currencyFieldDefaultValueSchema = z.object({ | ||
amountMicros: z.number().nullable(), | ||
currencyCode: simpleQuotesStringSchema.refine( | ||
(value): value is `'${CurrencyCode}'` => | ||
currencyCodeSchema.safeParse(stripSimpleQuotesFromString(value)).success, | ||
{ message: 'String is not a valid currencyCode' }, | ||
), | ||
}); |
26 changes: 26 additions & 0 deletions
26
...dules/object-record/record-field/validation-schemas/multiSelectFieldDefaultValueSchema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { z } from 'zod'; | ||
|
||
import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString'; | ||
import { simpleQuotesStringSchema } from '~/utils/validation-schemas/simpleQuotesStringSchema'; | ||
|
||
export const multiSelectFieldDefaultValueSchema = ( | ||
options?: FieldMetadataItemOption[], | ||
) => { | ||
if (!options?.length) return z.array(simpleQuotesStringSchema).nullable(); | ||
|
||
const optionValues = options.map(({ value }) => value); | ||
|
||
return z | ||
.array( | ||
simpleQuotesStringSchema.refine( | ||
(value) => optionValues.includes(stripSimpleQuotesFromString(value)), | ||
{ | ||
message: `String is not a valid multi-select option, available options are: ${options.join( | ||
', ', | ||
)}`, | ||
}, | ||
), | ||
) | ||
.nullable(); | ||
}; |
22 changes: 22 additions & 0 deletions
22
...rc/modules/object-record/record-field/validation-schemas/selectFieldDefaultValueSchema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString'; | ||
import { simpleQuotesStringSchema } from '~/utils/validation-schemas/simpleQuotesStringSchema'; | ||
|
||
export const selectFieldDefaultValueSchema = ( | ||
options?: FieldMetadataItemOption[], | ||
) => { | ||
if (!options?.length) return simpleQuotesStringSchema.nullable(); | ||
|
||
const optionValues = options.map(({ value }) => value); | ||
|
||
return simpleQuotesStringSchema | ||
.refine( | ||
(value) => optionValues.includes(stripSimpleQuotesFromString(value)), | ||
{ | ||
message: `String is not a valid select option, available options are: ${options.join( | ||
', ', | ||
)}`, | ||
}, | ||
) | ||
.nullable(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.