Skip to content

Commit

Permalink
chore: clarify types for helper and plugin options
Browse files Browse the repository at this point in the history
chore: clarify types for helper and plugin options
  • Loading branch information
andybywire committed Jun 11, 2023
2 parents 51d21ef + 746a1db commit 5dfc2a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Collapse / expand functionality to tree view
- Keyboard and screen reader support for collapse/expand, editing actions, and detail links
- Clarify types and parameters for plugin and helpers

## [2.2.2] - 2023-06-06

Expand Down
16 changes: 7 additions & 9 deletions src/helpers/branchFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
* Pluggable Function for Filtering to a Top Concept Branch within a SKOS Concept Scheme
*/

type branchFilterResult = {
filter: string
params: {
schemeId: string
branchId: string
}
}
type Options = {
type BranchOptions = {
schemeId: string
branchId: string
}

export function branchFilter(options: Options): branchFilterResult {
type BranchFilterResult = {
filter: string
params: BranchOptions
}

export function branchFilter(options: BranchOptions): BranchFilterResult {
const {schemeId, branchId} = options || {}
return {
filter: `!(_id in path("drafts.**")) && _id in *[_type=="skosConceptScheme" && schemeId == $schemeId].concepts[]._ref
Expand Down
13 changes: 6 additions & 7 deletions src/helpers/schemeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
* Pluggable Function for Filtering to a Single SKOS Concept Scheme
*/

type SchemeOptions = {
schemeId: string
}

type SchemeFilterResult = {
filter: string
params: {
schemeId: string
}
}
type Options = {
schemeId: string
params: SchemeOptions
}

export function schemeFilter(options: Options): SchemeFilterResult {
export function schemeFilter(options: SchemeOptions): SchemeFilterResult {
const {schemeId} = options || {}
return {
filter: `!(_id in path("drafts.**"))
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ import baseIri from './objects/baseIri'
import TreeView from './components/TreeView'
import {schemeFilter, branchFilter} from './helpers'

const taxonomyManager = definePlugin((options: any) => {
interface Options {
baseUri?: string
}

/**
* Defines a Sanity plugin for managing taxonomies.
* @param options - Optional configuration options for the plugin.
* @param options.baseUri - The base URI to use for SKOS concepts and concept schemes.
* baseURI should follow an IANA http/s scheme and should terminate with either a / or #.
* @returns A Sanity plugin object.
*/

const taxonomyManager = definePlugin((options?: Options) => {
const {baseUri} = options || {}

return {
Expand Down

0 comments on commit 5dfc2a9

Please sign in to comment.