Skip to content

Commit

Permalink
add readme and changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamsi committed May 21, 2020
1 parent 15a6eb5 commit e098330
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .changeset/wise-icons-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@keystonejs/app-admin-ui': minor
'@keystonejs/list-plugins': major
---

* Added `singleton` list plugin which prevents creating more items for a list or delete the only item in the list.

* Updated `admin-ui` to
- Redirect to the only item if there is an item in singleton list
- Hide `Search` field, `Back` and `AddNew` buttons on item details page
38 changes: 37 additions & 1 deletion packages/list-plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const { createdAt, updatedAt } = require('@keystonejs/list-plugins');

_Note_: The API is the same.

## byTracking
# byTracking

Adds `createdBy` and `updatedBy` fields to a list. These fields are read-only by will be updated automatically when items are created or updated.

Expand Down Expand Up @@ -103,3 +103,39 @@ const { createdBy, updatedBy } = require('@keystonejs/list-plugins');
```

_Note_: The API is the same.

# singleton

This plugin makes a list singleton by allowing only one item in the list. Useful for list which must contain only one items.

## Usage

```js
const { singleton } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
fields: {...},
plugins: [
singleton({...}),
],
});
```

## Config

| Option | Type | Default | Description |
| --------------- | --------- | ------- | ------------------------------------------------- |
| `preventDelete` | `Boolean` | `true` | Prevents deletion of the (only) item in the list. |

### `preventDelete`

By default the plugin will prevent deletion of the only item in the list by setting `delete` access to false. If you want to control the access yourself, set this value to false.

```javascript allowCopy=false showLanguage=false
keystone.createList('ListWithPlugin', {
fields: {...},
plugins: [
singleton({ preventDelete: false }),
],
});
```
40 changes: 40 additions & 0 deletions packages/list-plugins/singleton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--[meta]
section: list-plugins
title: singletoon
[meta]-->

# singleton Plugin

This plugin makes a list singleton by allowing only one item in the list. Useful for list which must contain only one items.

## Usage

```js
const { singleton } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
fields: {...},
plugins: [
singleton({...}),
],
});
```

## Config

| Option | Type | Default | Description |
| --------------- | --------- | ------- | ------------------------------------------------- |
| `preventDelete` | `Boolean` | `true` | Prevents deletion of the (only) item in the list. |

### `preventDelete`

By default the plugin will prevent deletion of the only item in the list by setting `delete` access to false. If you want to control the access yourself, set this value to false.

```javascript allowCopy=false showLanguage=false
keystone.createList('ListWithPlugin', {
fields: {...},
plugins: [
singleton({ preventDelete: false }),
],
});
```

0 comments on commit e098330

Please sign in to comment.