From c4d2b37d708885a13acf5bb83ad04a9b75dddd3a Mon Sep 17 00:00:00 2001 From: Mariusz Wachowski Date: Thu, 20 Jul 2023 19:57:09 +0100 Subject: [PATCH] Add ui.hideNowInfo option to timestamp field --- docs/pages/docs/fields/timestamp.md | 4 ++++ packages/core/src/fields/types/timestamp/index.ts | 5 +++++ .../core/src/fields/types/timestamp/views/index.tsx | 10 +++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/pages/docs/fields/timestamp.md b/docs/pages/docs/fields/timestamp.md index 877f26c0c0a..bf026cf794a 100644 --- a/docs/pages/docs/fields/timestamp.md +++ b/docs/pages/docs/fields/timestamp.md @@ -17,6 +17,9 @@ Options: - `db.updatedAt` (default: `false`) If `true` then this field will add the `@updatedAt` attribute to this field in the Prisma schema. This will update this field to the current time whenever an item is created/updated with the GraphQL API or any other usage of the Prisma Client if this field is not explicitly set in the request. Note this happens at the Prisma Client level, not at the database so if you update an item in your database directly, fields with `db.updatedAt: true` will not automatically update. +- `ui.hideNowInfo` (default: `false`) If `true` field will do not show additional info message: `When this item is saved, this field will be set to the current date and time` + - `ui` (default: `{ displayMode: 'input' }`): Configures the display mode of the field in the Admin UI. + Can be one of `['input', 'textarea']`. - `isIndexed` (default: `false`) - If `true` then this field will be indexed by the database. - If `'unique'` then all values of this field must be unique. @@ -28,6 +31,7 @@ Options: you can set this to true and the create field will be non-nullable and have a default value at the GraphQL level. This is only allowed when you have no create access control because otherwise, the item will always fail access control if a user doesn't have access to create the particular field regardless of whether or not they specify the field in the create. +- ```typescript import { config, list } from '@keystone-6/core'; diff --git a/packages/core/src/fields/types/timestamp/index.ts b/packages/core/src/fields/types/timestamp/index.ts index ab0fbcc7f58..06267c24cfb 100644 --- a/packages/core/src/fields/types/timestamp/index.ts +++ b/packages/core/src/fields/types/timestamp/index.ts @@ -25,6 +25,9 @@ export type TimestampFieldConfig = map?: string; extendPrismaSchema?: (field: string) => string; }; + ui?: { + hideNowInfo?: boolean; + } }; export const timestamp = @@ -75,6 +78,7 @@ export const timestamp = updatedAt: config.db?.updatedAt, map: config.db?.map, extendPrismaSchema: config.db?.extendPrismaSchema, + hideNowInfo: config.ui?.hideNowInfo, })({ ...config, hooks: { @@ -128,6 +132,7 @@ export const timestamp = defaultValue: defaultValue ?? null, isRequired: validation?.isRequired ?? false, updatedAt: config.db?.updatedAt ?? false, + hideNowInfo: config.ui?.hideNowInfo ?? false, }; }, }); diff --git a/packages/core/src/fields/types/timestamp/views/index.tsx b/packages/core/src/fields/types/timestamp/views/index.tsx index 710ca58f210..5c9e80215e7 100644 --- a/packages/core/src/fields/types/timestamp/views/index.tsx +++ b/packages/core/src/fields/types/timestamp/views/index.tsx @@ -148,9 +148,12 @@ export const Field = ({ {((value.kind === 'create' && typeof field.fieldMeta.defaultValue !== 'string' && field.fieldMeta.defaultValue?.kind === 'now') || - field.fieldMeta.updatedAt) && ( - When this item is saved, this field will be set to the current date and time - )} + field.fieldMeta.updatedAt) && + !field.fieldMeta.hideNowInfo && ( + + When this item is saved, this field will be set to the current date and time + + )} ); @@ -232,6 +235,7 @@ export type TimestampFieldMeta = { defaultValue: string | { kind: 'now' } | null; updatedAt: boolean; isRequired: boolean; + hideNowInfo: boolean; }; export const controller = ( config: FieldControllerConfig