Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Clarify how to show the Vision tool only to administrators.
  • Loading branch information
geball authored Apr 19, 2023
1 parent 2d3b0cf commit b55bca8
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions packages/@sanity/vision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

Vision is a plugin for Sanity Studio for testing GROQ queries. It features:

- GROQ syntax highlighting so that the query is easier to read.
- Parsed response that's more convenient to navigate and explore.
- Switch between datasets
- GROQ syntax highlighting so that the query is easier to read
- Parsed response that's more convenient to navigate and explore
- Switching between datasets
- Listening for real-time updates

![Screenshot](assets/screenshot.png)

## Installation

`npm install --save-exact @sanity/vision@dev-preview`
`npm install --save-exact @sanity/vision`

### Configuring

Expand All @@ -34,7 +34,7 @@ export default defineConfig({

### Only enabling it for development

If you only want the tool available in development (eg not in deployed studios), you can import and use the `isDev` constant from the `sanity` package:
If you only want the Vision tool available in development (e.g., not in deployed studios), you can import and use the `isDev` constant from the `sanity` package:

```ts
// `sanity.config.ts` / `sanity.config.js`:
Expand All @@ -52,6 +52,31 @@ export default defineConfig({
})
```

### Only enabling it for administrators

If you only want the Vision tool available to administrators, you can use the [Tool API](https://www.sanity.io/docs/studio-tools) to filter out the tool based on role:

```ts
// `sanity.config.ts` / `sanity.config.js`:
import {defineConfig} from 'sanity'
import {visionTool} from '@sanity/vision'

export default defineConfig({
// ... name, title, projectId, dataset, etc.
plugins: [
// ... your other plugins here ...
visionTool(),
],
tools: (prev, {currentUser}) => {
const isAdmin = currentUser?.roles.some(role => role.name === 'administrator');

// If the user has the administrator role, return all tools.
// If the user does not have the administrator role, filter out the vision tool.
return isAdmin ? prev : prev.filter(tool => tool.name !== 'vision');
},
})
```

## License

MIT-licensed. See LICENSE.

2 comments on commit b55bca8

@vercel
Copy link

@vercel vercel bot commented on b55bca8 Apr 19, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on b55bca8 Apr 19, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio.sanity.build
performance-studio-git-next.sanity.build

Please sign in to comment.