Skip to content

Commit

Permalink
Remove legacy field arguments and methods (#5244)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Mar 25, 2021
1 parent 18f4504 commit 0e14873
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 97 deletions.
6 changes: 6 additions & 0 deletions .changeset/sour-plants-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/fields-legacy': major
'@keystone-next/fields-cloudinary-image-legacy': major
---

Removed the legacy arguments `adminDoc` and `adminConfig`, and the method `extendAdminMeta`.
5 changes: 0 additions & 5 deletions packages/fields-cloudinary-image/src/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class CloudinaryImage extends File.implementation {
return [`${this.path}: ${this.graphQLOutputType}`];
}

extendAdminMeta(meta) {
// Overwrite so we have only the original meta
return meta;
}

getFileUploadType() {
return 'Upload';
}
Expand Down
27 changes: 0 additions & 27 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ Fields share some standard configuration options.
| Option | Type | Default | Description |
| -------------- | ----------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | `FieldType` | (required) | |
| `adminDoc` | `String` | `false` | A description for the field used in the AdminUI. |
| `schemaDoc` | `String` | `false` | A description for the field used in the GraphQL schema. |
| `defaultValue` | `Any` \| `Function` | `undefined` | A valid default value for the field type. Functions must return a valid value. Use `undefined` to set no default, and `null` to set an empty default. |
| `isUnique` | `Boolean` | `false` | Whether or not the field should be unique. |
| `isRequired` | `Boolean` | `false` | Whether or not the field should be mandatory. |
| `access` | `Boolean` \| `Function` \| `Object` | `true` | See: [Access control](https://keystonejs.com/guides/access-control) options for fields. |
| `label` | `String` | | Label for the field. |
| `adminConfig` | `Object` | `{}` | Additional config which can be used when customizing `admin-ui` |

> **Note:** Many field types have additional config options. See the documentation for individual field types for more detail.
Expand All @@ -72,35 +70,10 @@ A valid `Keystone` field type.

Sets the label for the field in the AdminUI

### `adminDoc`

A description of the field used in the AdminUI.

### `schemaDoc`

A description of the field used used in the GraphQL schema.

### `adminConfig`

Additional field configs affecting field rendering or display in `admin-ui`.

#### `adminConfig.isReadOnly`

Fields with `isReadOnly` set to `true` will be disabled preventing users from modifying them in the Admin UI. This does not affect access control and fields can still be updated via GraphQL.

```javascript
keystone.createList('Post', {
fields: {
title: { type: Text },
slug: {
type: Text,
adminConfig: {
isReadOnly: true, //slug can be created automatically and you may want to show this as read only
},
},
},
});
```

### `defaultValue`

Expand Down
25 changes: 2 additions & 23 deletions packages/fields/src/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@ import { parseFieldAccess } from '@keystone-next/access-control-legacy';
class Field {
constructor(
path,
{
hooks = {},
isRequired,
defaultValue,
access,
label,
schemaDoc,
adminDoc,
adminConfig,
...config
},
{ hooks = {}, isRequired, defaultValue, access, label, schemaDoc, ...config },
{ getListByKey, listKey, listAdapter, fieldAdapterClass, defaultAccess, schemaNames }
) {
this.path = path;
this.isPrimaryKey = path === 'id';
this.schemaDoc = schemaDoc;
this.adminDoc = adminDoc;
this.adminConfig = adminConfig;
this.config = config;
this.isRequired = !!isRequired;
this.defaultValue = defaultValue;
Expand All @@ -48,13 +36,7 @@ class Field {
// Should be overwritten by types that implement a Relationship interface
this.isRelationship = false;

this.access = parseFieldAccess({
schemaNames,
listKey,
fieldKey: path,
defaultAccess,
access,
});
this.access = parseFieldAccess({ schemaNames, listKey, fieldKey: path, defaultAccess, access });
}

// By default we assume that fields do not support unique constraints.
Expand Down Expand Up @@ -168,9 +150,6 @@ class Field {
gqlUpdateInputFields() {
return [];
}
extendAdminMeta(meta) {
return meta;
}
getDefaultValue({ context, originalInput }) {
if (typeof this.defaultValue !== 'undefined') {
if (typeof this.defaultValue === 'function') {
Expand Down
3 changes: 0 additions & 3 deletions packages/fields/src/types/DateTimeUtc/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export class DateTimeUtcImplementation extends Implementation {
return [`scalar String`];
}

extendAdminMeta(meta) {
return { ...meta, format: this.format };
}
getBackingTypes() {
return { [this.path]: { optional: true, type: 'Date | null' } };
}
Expand Down
6 changes: 0 additions & 6 deletions packages/fields/src/types/Decimal/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ export class Decimal extends Implementation {
gqlCreateInputFields() {
return [`${this.path}: String`];
}
extendAdminMeta(meta) {
return {
...meta,
symbol: this.symbol,
};
}
getBackingTypes() {
return { [this.path]: { optional: true, type: 'string | null' } };
}
Expand Down
5 changes: 0 additions & 5 deletions packages/fields/src/types/Password/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ export class Password extends Implementation {
return this.bcrypt.hashSync(plaintext, this.workFactor);
}

extendAdminMeta(meta) {
const { minLength } = this;
return { ...meta, minLength };
}

// Force values to be hashed when set
validateNewPassword(password) {
if (this.rejectCommon && dumbPasswords.check(password)) {
Expand Down
5 changes: 0 additions & 5 deletions packages/fields/src/types/Relationship/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ export class Relationship extends Implementation {
}
}

extendAdminMeta(meta) {
const { refListKey: ref, refFieldPath, many } = this;
return { ...meta, ref, refFieldPath, many };
}

gqlQueryInputFields({ schemaName }) {
const { refList } = this.tryResolveRefList();

Expand Down
4 changes: 0 additions & 4 deletions packages/fields/src/types/Select/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ export class Select extends Implementation {
: [];
}

extendAdminMeta(meta) {
const { options, dataType } = this;
return { ...meta, options, dataType };
}
gqlQueryInputFields() {
// TODO: This could be extended for Int type options with numeric filters
return [
Expand Down
4 changes: 0 additions & 4 deletions packages/fields/src/types/Text/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export class Text extends Implementation {
gqlCreateInputFields() {
return [`${this.path}: String`];
}
extendAdminMeta(meta) {
const { isMultiline } = this;
return { isMultiline, ...meta };
}
getBackingTypes() {
return { [this.path]: { optional: true, type: 'string | null' } };
}
Expand Down
7 changes: 0 additions & 7 deletions packages/fields/src/types/Virtual/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ export class Virtual extends Implementation {
gqlQueryInputFields() {
return [];
}
extendAdminMeta(meta) {
return {
...meta,
graphQLSelection: this.graphQLReturnFragment,
isReadOnly: true,
};
}

parseFieldAccess(args) {
const parsedAccess = parseFieldAccess(args);
Expand Down
8 changes: 0 additions & 8 deletions packages/fields/tests/Implementation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ test('gqlOutputFieldResolvers', () => {
expect(impl.gqlOutputFieldResolvers({ schemaName })).toEqual({});
});

test('extendAdminMeta()', () => {
const impl = new Field('path', {}, args);

const meta = { a: 1 };
const value = impl.extendAdminMeta(meta);
expect(value).toEqual(meta);
});

describe('getDefaultValue()', () => {
test('undefined by default', () => {
const impl = new Field('path', {}, args);
Expand Down

1 comment on commit 0e14873

@vercel
Copy link

@vercel vercel bot commented on 0e14873 Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.