sanity-plugin-taxonomy-manager 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  <!-- ## [TODO] -->
8
8
 
9
+ ## [1.0.3] - 2022-09-29
10
+ ### Fixed
11
+ - Concept Scheme Tree View bug that caused by missing parent document value on first render.
12
+ ### Changed
13
+ - Improved taxonomy scheme field descriptions.
14
+
9
15
  ## [1.0.2] - 2022-09-28
10
16
  ### Fixed
11
17
  - Fixed bug introduced by Sanity Studio update 2.33.0 that made `parent` unavailable to custom components directly.
@@ -55,7 +55,10 @@ var RecursiveConcept = props => {
55
55
  })));
56
56
  };
57
57
 
58
- var TreeView = (0, _formBuilder.withParent)( /*#__PURE__*/_react.default.forwardRef((props, ref) => {
58
+ var TreeView = (0, _formBuilder.withParent)(
59
+ /*#__PURE__*/
60
+ // Not using the ref right now, but likely will when the tree becomes interactive.
61
+ _react.default.forwardRef((props, ref) => {
59
62
  var _useState = (0, _react.useState)([]),
60
63
  _useState2 = _slicedToArray(_useState, 2),
61
64
  concepts = _useState2[0],
@@ -74,8 +77,9 @@ var TreeView = (0, _formBuilder.withParent)( /*#__PURE__*/_react.default.forward
74
77
  var _useState7 = (0, _react.useState)(false),
75
78
  _useState8 = _slicedToArray(_useState7, 2),
76
79
  isError = _useState8[0],
77
- setIsError = _useState8[1]; // This function builds the first level of hierarchy, noting Top Concepts and orphans, then calls the recursiveQuery() function
80
+ setIsError = _useState8[1];
78
81
 
82
+ var conceptScheme = props.parent._id ? props.parent._id.replace('drafts.', '') : undefined; // This function builds the first level of hierarchy, noting Top Concepts and orphans, then calls the recursiveQuery() function
79
83
 
80
84
  var queryBuilder = function queryBuilder() {
81
85
  var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
@@ -101,7 +105,7 @@ var TreeView = (0, _formBuilder.withParent)( /*#__PURE__*/_react.default.forward
101
105
  (0, _react.useEffect)(() => {
102
106
  var fetchConcepts = /*#__PURE__*/function () {
103
107
  var _ref = _asyncToGenerator(function* () {
104
- var conceptScheme = yield props.parent._id;
108
+ if (props.parent._id === undefined) return;
105
109
  setIsError(false);
106
110
  setNoConcept(false);
107
111
  setIsLoading(true);
@@ -115,6 +119,7 @@ var TreeView = (0, _formBuilder.withParent)( /*#__PURE__*/_react.default.forward
115
119
 
116
120
  if (response.length < 1) {
117
121
  setNoConcept(true);
122
+ setIsError(false);
118
123
  }
119
124
 
120
125
  setConcepts(response);
@@ -132,7 +137,7 @@ var TreeView = (0, _formBuilder.withParent)( /*#__PURE__*/_react.default.forward
132
137
  }();
133
138
 
134
139
  fetchConcepts();
135
- }, []);
140
+ }, [props.parent._id]);
136
141
  return /*#__PURE__*/_react.default.createElement(_ui.Box, null, /*#__PURE__*/_react.default.createElement(_ui.Stack, {
137
142
  space: 2
138
143
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/treeView.js"],"names":["client","sanityClient","withConfig","apiVersion","RecursiveConcept","props","isError","noConcept","isLoading","concepts","map","concept","id","topConcept","s","orphan","broaderSchemas","filter","parentScheme","length","polyHier","prefLabel","narrower","TreeView","React","forwardRef","ref","setConcepts","setIsLoading","setNoConcept","setIsError","queryBuilder","depth","recursiveQuery","count","fetchConcepts","conceptScheme","parent","_id","params","query","response","fetch","error","console","log","type","title","description"],"mappings":";;;;;;;AAWA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,gBAAaC,UAAb,CAAwB;AAACC,EAAAA,UAAU,EAAE;AAAb,CAAxB,CAAf,C,CAEA;;;AACA,IAAMC,gBAAgB,GAAIC,KAAD,IAAW;AAClC,sBACE,4DACGA,KAAK,CAACC,OAAN,iBAAiB,yEADpB,EAEGD,KA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,6BAAC,OAAD,qBACE,6BAAC,SAAD;AAAO,IAAA,KAAK,EAAE;AAAd,kBACE,6BAAC,QAAD;AAAM,IAAA,IAAI,EAAE,CAAZ;AAAe,IAAA,MAAM,EAAC;AAAtB,KACG9B,KAAK,CAACyC,IAAN,CAAWC,KADd,CADF,eAIE,6BAAC,QAAD;AAAM,IAAA,IAAI,EAAE,CAAZ;AAAe,IAAA,KAAK;AAApB,KACG1C,KAAK,CAACyC,IAAN,CAAWE,WADd,CAJF,eAOE,6BAAC,QAAD;AAAM,IAAA,IAAI,EAAE;AAAZ,kBACE,6BAAC,gBAAD;AACE,IAAA,QAAQ,EAAEvC,QADZ;AAEE,IAAA,SAAS,EAAED,SAFb;AAGE,IAAA,SAAS,EAAED,SAHb;AAIE,IAAA,OAAO,EAAED;AAJX,IADF,CAPF,CADF,CADF;AAoBD,CA9ED,CADe,CAAjB;eAkFeiB,Q","sourcesContent":["/**\n * Taxonomy Tree View input component for SKOS Concept Schemes\n * This component creates a hierarchical, linked (TDB) display of concepts associated with the associated Concept Scheme\n * @todo Add ability to set hierarchy depth from config file\n * @todo Add links to concepts that open in a pane to the right (see notes below)\n * @todo Add affordance for collapsing and expanding tree view (see notes below)\n * @todo Add affordance for creating new child concept in pane to the right (or modal) from a tree view concept\n * @todo Differentiate \"new concept scheme\" error state from other fetch() error states\n * @todo Add listener to JS client to reflect hierarchy updates as they happen: https://www.sanity.io/plugins/javascript-api-client\n */\n\nimport React, {useState, useEffect} from 'react'\nimport {Box, Stack, Text} from '@sanity/ui'\nimport {withParent} from 'part:@sanity/form-builder'\nimport sanityClient from 'part:@sanity/base/client'\nimport * as s from './treeView.module.css'\n\nconst client = sanityClient.withConfig({apiVersion: '2021-03-25'})\n\n// This component builds the hierarchy tree, messages loading state, messages no concepts found state.\nconst RecursiveConcept = (props) => {\n return (\n <>\n {props.isError && <p>Sorry, could not get concepts.</p>}\n {props.noConcept && <p>This scheme does not yet have any concepts assigned to it.</p>}\n {props.isLoading ? (\n <p>Loading hierarchy ...</p>\n ) : (\n <ul>\n {props.concepts.map((concept) => {\n return (\n <li\n key={concept.id}\n className={`${concept.topConcept ? s.topConcept : s.orphan} ${\n concept.broaderSchemas?.filter((id) => id === concept.parentScheme).length > 1 &&\n s.polyHier\n }`}\n >\n {concept.prefLabel}\n {concept.narrower?.length > 0 && <RecursiveConcept concepts={concept.narrower} />}\n </li>\n )\n })}\n </ul>\n )}\n </>\n )\n}\n\nconst TreeView = withParent(\n React.forwardRef((props, ref) => {\n const [concepts, setConcepts] = useState([])\n const [isLoading, setIsLoading] = useState(false)\n const [noConcept, setNoConcept] = useState(false)\n const [isError, setIsError] = useState(false)\n\n // This function builds the first level of hierarchy, noting Top Concepts and orphans, then calls the recursiveQuery() function\n const queryBuilder = (depth = 5) => {\n if (depth === 0) {\n return ''\n } else {\n return `*[_type==\"skosConcept\" && references($conceptScheme) && (count(broader[]) < 1 || broader == null) && !(_id in path(\"drafts.**\"))]|order(prefLabel) {\n \"level\": 0,\n \"id\": _id,\n prefLabel,\n topConcept,\n ${recursiveQuery(depth)}\n }`\n }\n }\n // This function builds all subsequent levels found in the data and notes any concepts that exist in two places in this Concept Scheme (i.e. which are polyhierarchical)\n const recursiveQuery = (depth, count = 1) => {\n if (depth === 0) {\n return ''\n } else {\n return `\"narrower\": *[_type == \"skosConcept\" && references($conceptScheme) && references(^._id) && !(_id in path(\"drafts.**\"))]|order(prefLabel) {\n \"level\": ${count},\n \"id\": _id,\n prefLabel,\n \"broaderSchemas\": broader[]->scheme->._id, \n \"parentScheme\": $conceptScheme, ${recursiveQuery(depth - 1, count + 1)} \n }`\n }\n }\n\n useEffect(() => {\n const fetchConcepts = async () => {\n const conceptScheme = await props.parent._id;\n setIsError(false)\n setNoConcept(false)\n setIsLoading(true)\n try {\n const params = {conceptScheme: conceptScheme}\n const query = `${queryBuilder()}`\n const response = await client.fetch(query, params)\n if (response.length < 1) {\n setNoConcept(true)\n }\n setConcepts(response)\n } catch (error) {\n setIsError(true)\n console.log(error)\n }\n setIsLoading(false)\n }\n fetchConcepts()\n }, [])\n\n return (\n <Box>\n <Stack space={2}>\n <Text size={1} weight=\"semibold\">\n {props.type.title}\n </Text>\n <Text size={1} muted>\n {props.type.description}\n </Text>\n <Text size={2}>\n <RecursiveConcept\n concepts={concepts}\n isLoading={isLoading}\n noConcept={noConcept}\n isError={isError}\n />\n </Text>\n </Stack>\n </Box>\n )\n })\n)\n\nexport default TreeView\n"],"file":"treeView.js"}
1
+ {"version":3,"sources":["../../src/components/treeView.js"],"names":["client","sanityClient","withConfig","apiVersion","RecursiveConcept","props","isError","noConcept","isLoading","concepts","map","concept","id","topConcept","s","orphan","broaderSchemas","filter","parentScheme","length","polyHier","prefLabel","narrower","TreeView","React","forwardRef","ref","setConcepts","setIsLoading","setNoConcept","setIsError","conceptScheme","parent","_id","replace","undefined","queryBuilder","depth","recursiveQuery","count","fetchConcepts","params","query","response","fetch","error","console","log","type","title","description"],"mappings":";;;;;;;AAWA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,gBAAaC,UAAb,CAAwB;AAACC,EAAAA,UAAU,EAAE;AAAb,CAAxB,CAAf,C,CAEA;;;AACA,IAAMC,gBAAgB,GAAIC,KAAD,IAAW;AAClC,sBACE,4DACGA,KAAK,CAACC,OAAN,iBAAiB,yEADpB,EAEGD,KAAK,CAACE,SAAN,iBAAmB,qGAFtB,EAGGF,KAAK,CAACG,SAAN,gBACC,gEADD,gBAGC,yCACGH,KAAK,CAACI,QAAN,CAAeC,GAAf,CAAoBC,OAAD,IAAa;AAAA;;AAC/B,wBACE;AACE,MAAA,GAAG,EAAEA,OAAO,CAACC,EADf;AAEE,MAAA,SAAS,YAAKD,OAAO,CAACE,UAAR,GAAqBC,CAAC,CAACD,UAAvB,GAAoCC,CAAC,CAACC,MAA3C,cACP,0BAAAJ,OAAO,CAACK,cAAR,gFAAwBC,MAAxB,CAAgCL,EAAD,IAAQA,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,IAAI,EAAE,CAAZ;AAAe,IAAA,MAAM,EAAC;AAAtB,KACG5B,KAAK,CAAC2C,IAAN,CAAWC,KADd,CADF,eAIE,6BAAC,QAAD;AAAM,IAAA,IAAI,EAAE,CAAZ;AAAe,IAAA,KAAK;AAApB,KACG5C,KAAK,CAAC2C,IAAN,CAAWE,WADd,CAJF,eAOE,6BAAC,QAAD;AAAM,IAAA,IAAI,EAAE;AAAZ,kBACE,6BAAC,gBAAD;AACE,IAAA,QAAQ,EAAEzC,QADZ;AAEE,IAAA,SAAS,EAAED,SAFb;AAGE,IAAA,SAAS,EAAED,SAHb;AAIE,IAAA,OAAO,EAAED;AAJX,IADF,CAPF,CADF,CADF;AAoBD,CAlFD,CAHe,CAAjB;eAwFeiB,Q","sourcesContent":["/**\n * Taxonomy Tree View input component for SKOS Concept Schemes\n * This component creates a hierarchical, linked (TDB) display of concepts associated with the associated Concept Scheme\n * @todo Add ability to set hierarchy depth from config file\n * @todo Add links to concepts that open in a pane to the right (see notes below)\n * @todo Add affordance for collapsing and expanding tree view (see notes below)\n * @todo Add affordance for creating new child concept in pane to the right (or modal) from a tree view concept\n * @todo Differentiate \"new concept scheme\" error state from other fetch() error states\n * @todo Add listener to JS client to reflect hierarchy updates as they happen: https://www.sanity.io/plugins/javascript-api-client\n */\n\nimport React, {useState, useEffect} from 'react'\nimport {Box, Stack, Text} from '@sanity/ui'\nimport {withParent} from 'part:@sanity/form-builder'\nimport sanityClient from 'part:@sanity/base/client'\nimport * as s from './treeView.module.css'\n\nconst client = sanityClient.withConfig({apiVersion: '2021-03-25'})\n\n// This component builds the hierarchy tree, messages loading state, messages no concepts found state.\nconst RecursiveConcept = (props) => {\n return (\n <>\n {props.isError && <p>Sorry, could not get concepts.</p>}\n {props.noConcept && <p>This scheme does not yet have any concepts assigned to it.</p>}\n {props.isLoading ? (\n <p>Loading hierarchy ...</p>\n ) : (\n <ul>\n {props.concepts.map((concept) => {\n return (\n <li\n key={concept.id}\n className={`${concept.topConcept ? s.topConcept : s.orphan} ${\n concept.broaderSchemas?.filter((id) => id === concept.parentScheme).length > 1 &&\n s.polyHier\n }`}\n >\n {concept.prefLabel}\n {concept.narrower?.length > 0 && <RecursiveConcept concepts={concept.narrower} />}\n </li>\n )\n })}\n </ul>\n )}\n </>\n )\n}\n\nconst TreeView = withParent(\n \n // Not using the ref right now, but likely will when the tree becomes interactive. \n React.forwardRef((props, ref) => {\n const [concepts, setConcepts] = useState([])\n const [isLoading, setIsLoading] = useState(false)\n const [noConcept, setNoConcept] = useState(false)\n const [isError, setIsError] = useState(false)\n\n const conceptScheme = props.parent._id ? props.parent._id.replace('drafts.', '') : undefined\n // This function builds the first level of hierarchy, noting Top Concepts and orphans, then calls the recursiveQuery() function\n const queryBuilder = (depth = 5) => {\n if (depth === 0) {\n return ''\n } else {\n return `*[_type==\"skosConcept\" && references($conceptScheme) && (count(broader[]) < 1 || broader == null) && !(_id in path(\"drafts.**\"))]|order(prefLabel) {\n \"level\": 0,\n \"id\": _id,\n prefLabel,\n topConcept,\n ${recursiveQuery(depth)}\n }`\n }\n }\n // This function builds all subsequent levels found in the data and notes any concepts that exist in two places in this Concept Scheme (i.e. which are polyhierarchical)\n const recursiveQuery = (depth, count = 1) => {\n if (depth === 0) {\n return ''\n } else {\n return `\"narrower\": *[_type == \"skosConcept\" && references($conceptScheme) && references(^._id) && !(_id in path(\"drafts.**\"))]|order(prefLabel) {\n \"level\": ${count},\n \"id\": _id,\n prefLabel,\n \"broaderSchemas\": broader[]->scheme->._id, \n \"parentScheme\": $conceptScheme, ${recursiveQuery(depth - 1, count + 1)} \n }`\n }\n }\n\n useEffect(() => {\n const fetchConcepts = async () => {\n \n if (props.parent._id === undefined ) return\n\n setIsError(false)\n setNoConcept(false)\n setIsLoading(true)\n try {\n const params = {conceptScheme: conceptScheme}\n const query = `${queryBuilder()}`\n const response = await client.fetch(query, params)\n if (response.length < 1) {\n setNoConcept(true)\n setIsError(false)\n }\n setConcepts(response)\n } catch (error) {\n setIsError(true)\n console.log(error)\n }\n setIsLoading(false)\n }\n fetchConcepts()\n }, [props.parent._id])\n\n return (\n <Box>\n <Stack space={2}>\n <Text size={1} weight=\"semibold\">\n {props.type.title}\n </Text>\n <Text size={1} muted>\n {props.type.description}\n </Text>\n <Text size={2}>\n <RecursiveConcept\n concepts={concepts}\n isLoading={isLoading}\n noConcept={noConcept}\n isError={isError}\n />\n </Text>\n </Stack>\n </Box>\n )\n })\n)\n\nexport default TreeView\n"],"file":"treeView.js"}
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _react = _interopRequireDefault(require("react"));
9
+
8
10
  var _ri = require("react-icons/ri");
9
11
 
10
12
  var _treeView = _interopRequireDefault(require("./components/treeView"));
@@ -26,18 +28,17 @@ var _default = {
26
28
  name: 'title',
27
29
  title: 'Taxonomy Concept Scheme',
28
30
  type: 'string',
29
- description: 'Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like.'
31
+ description: 'Schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like'
30
32
  }, {
31
33
  name: 'treeView',
32
34
  title: 'Concept Scheme Tree View',
33
35
  type: 'string',
34
- description: 'Concept hierarchy is determined by \'Broader Than\' and \'Top Concept\' relationships assigned to each concept. A holistic view of these relationships is shown below. Top Concepts are indicated in bold. Italicized concepts represent polyhierarchy (concepts that appear in more than one branch of the hierarchy tree.)',
36
+ description: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "Top Concepts are indicated in ", /*#__PURE__*/_react.default.createElement("strong", null, "bold"), ". Concepts in ", /*#__PURE__*/_react.default.createElement("em", null, "italics"), " represent polyhierarchy (concepts that appear in more than one branch of the hierarchy tree)."),
35
37
  inputComponent: _treeView.default
36
38
  }, {
37
39
  name: 'description',
38
40
  title: 'Description',
39
41
  type: 'text',
40
- rows: 3,
41
42
  description: 'Describe the intended use of this scheme.'
42
43
  }],
43
44
  preview: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/skosConceptScheme.js"],"names":["name","title","type","icon","RiNodeTree","fields","description","inputComponent","TreeView","rows","preview","select","prepare","media"],"mappings":";;;;;;;AAMA;;AACA;;;;AAPA;AACA;AACA;AACA;AACA;AACA;eAIe;AACbA,EAAAA,IAAI,EAAE,mBADO;AAEbC,EAAAA,KAAK,EAAE,kBAFM;AAGbC,EAAAA,IAAI,EAAE,UAHO;AAIbC,EAAAA,IAAI,EAAEC,cAJO;AAKbC,EAAAA,MAAM,EAAE,CACN;AACEL,IAAAA,IAAI,EAAE,OADR;AAEEC,IAAAA,KAAK,EAAE,yBAFT;AAGEC,IAAAA,IAAI,EAAE,QAHR;AAIEI,IAAAA,WAAW,EACT;AALJ,GADM,EAQN;AACEN,IAAAA,IAAI,EAAE,UADR;AAEEC,IAAAA,KAAK,EAAE,0BAFT;AAGEC,IAAAA,IAAI,EAAE,QAHR;AAIEI,IAAAA,WAAW,EACT,8TALJ;AAMEC,IAAAA,cAAc,EAAEC;AANlB,GARM,EAgBN;AACER,IAAAA,IAAI,EAAE,aADR;AAEEC,IAAAA,KAAK,EAAE,aAFT;AAGEC,IAAAA,IAAI,EAAE,MAHR;AAIEO,IAAAA,IAAI,EAAE,CAJR;AAKEH,IAAAA,WAAW,EAAE;AALf,GAhBM,CALK;AA6BbI,EAAAA,OAAO,EAAE;AACPC,IAAAA,MAAM,EAAE;AACNV,MAAAA,KAAK,EAAE;AADD,KADD;;AAIPW,IAAAA,OAAO,OAAU;AAAA,UAARX,KAAQ,QAARA,KAAQ;AACf,aAAO;AACLA,QAAAA,KAAK,EAAEA,KADF;AAELY,QAAAA,KAAK,EAAET;AAFF,OAAP;AAID;;AATM;AA7BI,C","sourcesContent":["/**\n * Sanity document scheme for SKOS Concept Schemes\n * @todo Afford setting a \"default\" scheme which is used as an initial value for new concepts. When no default is set, concepts are created without any scheme.\n * @todo Add administrative metadata: author, date, last revised, etc.\n * @todo Consider adding informational lists to this view (via custom input component): number of terms, list of terms, links. Perhaps eventually a navigable tree view.\n */\nimport {RiNodeTree} from 'react-icons/ri'\nimport TreeView from './components/treeView'\n\nexport default {\n name: 'skosConceptScheme',\n title: 'Taxonomy Schemes',\n type: 'document',\n icon: RiNodeTree,\n fields: [\n {\n name: 'title',\n title: 'Taxonomy Concept Scheme',\n type: 'string',\n description:\n 'Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like.',\n },\n {\n name: 'treeView',\n title: 'Concept Scheme Tree View',\n type: 'string',\n description: \n 'Concept hierarchy is determined by \\'Broader Than\\' and \\'Top Concept\\' relationships assigned to each concept. A holistic view of these relationships is shown below. Top Concepts are indicated in bold. Italicized concepts represent polyhierarchy (concepts that appear in more than one branch of the hierarchy tree.)',\n inputComponent: TreeView\n },\n {\n name: 'description',\n title: 'Description',\n type: 'text',\n rows: 3,\n description: 'Describe the intended use of this scheme.',\n },\n ],\n preview: {\n select: {\n title: 'title',\n },\n prepare({title}) {\n return {\n title: title,\n media: RiNodeTree,\n }\n },\n },\n}\n"],"file":"skosConceptScheme.js"}
1
+ {"version":3,"sources":["../src/skosConceptScheme.js"],"names":["name","title","type","icon","RiNodeTree","fields","description","inputComponent","TreeView","preview","select","prepare","media"],"mappings":";;;;;;;AAOA;;AACA;;AACA;;;;AATA;AACA;AACA;AACA;AACA;AACA;eAMe;AACbA,EAAAA,IAAI,EAAE,mBADO;AAEbC,EAAAA,KAAK,EAAE,kBAFM;AAGbC,EAAAA,IAAI,EAAE,UAHO;AAIbC,EAAAA,IAAI,EAAEC,cAJO;AAKbC,EAAAA,MAAM,EAAE,CACN;AACEL,IAAAA,IAAI,EAAE,OADR;AAEEC,IAAAA,KAAK,EAAE,yBAFT;AAGEC,IAAAA,IAAI,EAAE,QAHR;AAIEI,IAAAA,WAAW,EAAG;AAJhB,GADM,EAON;AACEN,IAAAA,IAAI,EAAE,UADR;AAEEC,IAAAA,KAAK,EAAE,0BAFT;AAGEC,IAAAA,IAAI,EAAE,QAHR;AAIEI,IAAAA,WAAW,eAAE,2GAAgC,oDAAhC,iCAAmE,mDAAnE,mGAJf;AAKEC,IAAAA,cAAc,EAAEC;AALlB,GAPM,EAcN;AACER,IAAAA,IAAI,EAAE,aADR;AAEEC,IAAAA,KAAK,EAAE,aAFT;AAGEC,IAAAA,IAAI,EAAE,MAHR;AAIEI,IAAAA,WAAW,EAAE;AAJf,GAdM,CALK;AA0BbG,EAAAA,OAAO,EAAE;AACPC,IAAAA,MAAM,EAAE;AACNT,MAAAA,KAAK,EAAE;AADD,KADD;;AAIPU,IAAAA,OAAO,OAAU;AAAA,UAARV,KAAQ,QAARA,KAAQ;AACf,aAAO;AACLA,QAAAA,KAAK,EAAEA,KADF;AAELW,QAAAA,KAAK,EAAER;AAFF,OAAP;AAID;;AATM;AA1BI,C","sourcesContent":["/**\n * Sanity document scheme for SKOS Concept Schemes\n * @todo Afford setting a \"default\" scheme which is used as an initial value for new concepts. When no default is set, concepts are created without any scheme.\n * @todo Add administrative metadata: author, date, last revised, etc.\n * @todo Consider adding informational lists to this view (via custom input component): number of terms, list of terms, links. Perhaps eventually a navigable tree view.\n */\n\nimport React from 'react';\nimport {RiNodeTree} from 'react-icons/ri'\nimport TreeView from './components/treeView'\n\nexport default {\n name: 'skosConceptScheme',\n title: 'Taxonomy Schemes',\n type: 'document',\n icon: RiNodeTree,\n fields: [\n {\n name: 'title',\n title: 'Taxonomy Concept Scheme',\n type: 'string',\n description: 'Schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like'\n },\n {\n name: 'treeView',\n title: 'Concept Scheme Tree View',\n type: 'string',\n description: <>Top Concepts are indicated in <strong>bold</strong>. Concepts in <em>italics</em> represent polyhierarchy (concepts that appear in more than one branch of the hierarchy tree).</>,\n inputComponent: TreeView\n },\n {\n name: 'description',\n title: 'Description',\n type: 'text',\n description: 'Describe the intended use of this scheme.',\n },\n ],\n preview: {\n select: {\n title: 'title',\n },\n prepare({title}) {\n return {\n title: title,\n media: RiNodeTree,\n }\n },\n },\n}\n"],"file":"skosConceptScheme.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-taxonomy-manager",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Create and manage SKOS compliant taxonomies, thesauri, and classification schemes in Sanity Studio.",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -48,12 +48,15 @@ const RecursiveConcept = (props) => {
48
48
  }
49
49
 
50
50
  const TreeView = withParent(
51
+
52
+ // Not using the ref right now, but likely will when the tree becomes interactive.
51
53
  React.forwardRef((props, ref) => {
52
54
  const [concepts, setConcepts] = useState([])
53
55
  const [isLoading, setIsLoading] = useState(false)
54
56
  const [noConcept, setNoConcept] = useState(false)
55
57
  const [isError, setIsError] = useState(false)
56
58
 
59
+ const conceptScheme = props.parent._id ? props.parent._id.replace('drafts.', '') : undefined
57
60
  // This function builds the first level of hierarchy, noting Top Concepts and orphans, then calls the recursiveQuery() function
58
61
  const queryBuilder = (depth = 5) => {
59
62
  if (depth === 0) {
@@ -85,7 +88,9 @@ const TreeView = withParent(
85
88
 
86
89
  useEffect(() => {
87
90
  const fetchConcepts = async () => {
88
- const conceptScheme = await props.parent._id;
91
+
92
+ if (props.parent._id === undefined ) return
93
+
89
94
  setIsError(false)
90
95
  setNoConcept(false)
91
96
  setIsLoading(true)
@@ -95,6 +100,7 @@ const TreeView = withParent(
95
100
  const response = await client.fetch(query, params)
96
101
  if (response.length < 1) {
97
102
  setNoConcept(true)
103
+ setIsError(false)
98
104
  }
99
105
  setConcepts(response)
100
106
  } catch (error) {
@@ -104,7 +110,7 @@ const TreeView = withParent(
104
110
  setIsLoading(false)
105
111
  }
106
112
  fetchConcepts()
107
- }, [])
113
+ }, [props.parent._id])
108
114
 
109
115
  return (
110
116
  <Box>
@@ -4,6 +4,8 @@
4
4
  * @todo Add administrative metadata: author, date, last revised, etc.
5
5
  * @todo Consider adding informational lists to this view (via custom input component): number of terms, list of terms, links. Perhaps eventually a navigable tree view.
6
6
  */
7
+
8
+ import React from 'react';
7
9
  import {RiNodeTree} from 'react-icons/ri'
8
10
  import TreeView from './components/treeView'
9
11
 
@@ -17,22 +19,19 @@ export default {
17
19
  name: 'title',
18
20
  title: 'Taxonomy Concept Scheme',
19
21
  type: 'string',
20
- description:
21
- 'Concept schemes are used to group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like.',
22
+ description: 'Schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong on many (or no) concept schemes, and you may create as many (or few) concept schemes as you like'
22
23
  },
23
24
  {
24
25
  name: 'treeView',
25
26
  title: 'Concept Scheme Tree View',
26
27
  type: 'string',
27
- description:
28
- 'Concept hierarchy is determined by \'Broader Than\' and \'Top Concept\' relationships assigned to each concept. A holistic view of these relationships is shown below. Top Concepts are indicated in bold. Italicized concepts represent polyhierarchy (concepts that appear in more than one branch of the hierarchy tree.)',
28
+ description: <>Top Concepts are indicated in <strong>bold</strong>. Concepts in <em>italics</em> represent polyhierarchy (concepts that appear in more than one branch of the hierarchy tree).</>,
29
29
  inputComponent: TreeView
30
30
  },
31
31
  {
32
32
  name: 'description',
33
33
  title: 'Description',
34
34
  type: 'text',
35
- rows: 3,
36
35
  description: 'Describe the intended use of this scheme.',
37
36
  },
38
37
  ],