Skip to content

Commit

Permalink
Add ui.hideNowInfo option to timestamp field
Browse files Browse the repository at this point in the history
  • Loading branch information
wysher authored and dcousens committed Aug 29, 2023
1 parent 859257a commit c4d2b37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/pages/docs/fields/timestamp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/fields/types/timestamp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export type TimestampFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
map?: string;
extendPrismaSchema?: (field: string) => string;
};
ui?: {
hideNowInfo?: boolean;
}
};

export const timestamp =
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -128,6 +132,7 @@ export const timestamp =
defaultValue: defaultValue ?? null,
isRequired: validation?.isRequired ?? false,
updatedAt: config.db?.updatedAt ?? false,
hideNowInfo: config.ui?.hideNowInfo ?? false,
};
},
});
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/fields/types/timestamp/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ export const Field = ({
{((value.kind === 'create' &&
typeof field.fieldMeta.defaultValue !== 'string' &&
field.fieldMeta.defaultValue?.kind === 'now') ||
field.fieldMeta.updatedAt) && (
<Text>When this item is saved, this field will be set to the current date and time</Text>
)}
field.fieldMeta.updatedAt) &&
!field.fieldMeta.hideNowInfo && (
<Text>
When this item is saved, this field will be set to the current date and time
</Text>
)}
</Stack>
</FieldContainer>
);
Expand Down Expand Up @@ -232,6 +235,7 @@ export type TimestampFieldMeta = {
defaultValue: string | { kind: 'now' } | null;
updatedAt: boolean;
isRequired: boolean;
hideNowInfo: boolean;
};
export const controller = (
config: FieldControllerConfig<TimestampFieldMeta>
Expand Down

0 comments on commit c4d2b37

Please sign in to comment.