Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@thegoodwork/orderable-document-list
Advanced tools
Readme
This is a Sanity Studio v3 plugin. For the v2 version, please refer to the v2-branch.
Drag-and-drop Document Ordering without leaving the Editing surface.
This plugin aims to be OS-like in that you can select and move multiple documents by holding shift
and clicking a second item, and toggling on/off selections by holding command/control
.
A Sanity Studio with Desk Structure configured:
import {defineConfig} from 'sanity'
import {deskTool, StructureBuilder} from 'sanity/desk'
export default defineConfig({
//...
plugins: [
deskTool({
structure: (S, context) => {
/* Structure code */
},
}),
],
})
Run the following command in your studio directory
npm install --save @sanity/orderable-document-list
or
yarn add @sanity/orderable-document-list
The config parameter requires type
, S
and context
. It also accepts title
, icon
, filter
and params
.
S
and context
are available in desk-tool structure callback, and should be forwarded as is:
import {defineConfig} from 'sanity'
import {deskTool, StructureBuilder} from 'sanity/desk'
import {orderableDocumentListDeskItem} from '@sanity/orderable-document-list'
export default defineConfig({
//...
plugins: [
deskTool({
structure: (S, context) => {
return S.list()
.title('Content')
.items([
// Minimum required configuration
orderableDocumentListDeskItem({type: 'category', S, context}),
// Optional configuration
orderableDocumentListDeskItem({
type: 'project',
title: 'Projects',
icon: Paint,
// Required if using multiple lists of the same 'type'
id: 'orderable-en-projects',
// See notes on adding a `filter` below
filter: `__i18n_lang == $lang`,
params: {
lang: 'en_US',
},
// pass from the structure callback params above
S,
context,
}),
// ... all other desk items
])
},
}),
],
})
Caution: Adding a filter
By default, the plugin will display all documents of the same type
. However, you may wish to add a filter
to reduce this down to a subset of documents. A typical usecase is for internationalized document schema to order documents of just the base language version.
However, order ranks are still computed based on all documents of the same type
. Creating multiple lists with different filter
settings could produce unexpected results.
orderRank
field to your schema(s).You must pass in the type
of the schema and the schema context
, to create an initialValue
value.
Context is available in the schema callback, and should be forwarded as is.
Additionally, pass in overrides for the field, such as making it visible by passing hidden: false
.
You cannot override the name
, type
or initialValue
attributes.
// sanity.config.js
import {defineConfig} from "sanity";
import {deskTool, StructureBuilder} from "sanity/desk";
import {orderRankField, orderRankOrdering} from '@sanity/orderable-document-list'
export default defineConfig({
//...
plugins: [
deskTool({structure: (S, context) => {/* snip */}})
],
schema: {
types: (previousTypes) => {
return [
...previousTypes,
{
name: "category",
title: "Category",
type: "document",
// Optional: The plugin also exports a set of 'orderings' for use in other Document Lists
// https://www.sanity.io/docs/sort-orders
orderings: [orderRankOrdering],
fields: [
// Minimum required configuration
orderRankField({ type: "category" }),
// OR you can override _some_ of the field settings
orderRankField({ type: 'category', hidden: false }),
// ...all other fields
],
},
]
}
}
}
On first load, your Document list will not have any Order. You can select "Reset Order" from the menu in the top right of the list. You can also re-run this at any time.
The orderRankField
will query the last Document to set an initialValue
to come after it.
New Documents always start at the end of the Ordered list.
New Documents appear at the end of the list by default. You can configure where new Documents are inserted by configuring orderRankField
with the optional newItemPosition
option:
// default value of newItemPosition is "after"
orderRankField({ type: "category", newItemPosition: "before" }),
Now when writing a GROQ Query for Documents, use the orderRank
field value to return ordered results:
*[_type == "category"]|order(orderRank)
If fetching documents using the document-internationalization
plugin, you may want to sort by the rank of the base document when the document is not in the base language, so all locales share the same order. When changing the order of documents using this plugin, the orderRank
field of documents in alternate locales won't be updated. The query below ensures a consistent order for documents in the base language and in alternate languages.
*[_type == "category" && __i18n_lang == $lang]|order(coalesce(__i18n_base->orderRank, orderRank))
To get this first version out the door there are few configuration settings and a lot of opinions. Such as:
name
of the orderRank
field is constanttype
Feedback and PRs welcome :)
orderableDocumentListDeskItem
requires context from sanity config now.
See the examples above.
Uses kvandakes's TypeScript implementation of Jira's Lexorank to create a "lexographical" Document order.
Put simply it updates the position of an individual – or many – Documents in an ordered list without updating any others. It's fast.
This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.
See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.
Run "CI & Release" workflow. Make sure to select the v3 branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.
MIT © Sanity.io
FAQs
Drag-and-drop Document Ordering without leaving the Editing surface
The npm package @thegoodwork/orderable-document-list receives a total of 3 weekly downloads. As such, @thegoodwork/orderable-document-list popularity was classified as not popular.
We found that @thegoodwork/orderable-document-list demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.