@abi-software/map-side-bar 2.14.8-demo.6 → 2.14.8-demo.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/map-side-bar",
3
- "version": "2.14.8-demo.6",
3
+ "version": "2.14.8-demo.7",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -310,12 +310,21 @@
310
310
  </div>
311
311
  <ul class="block consultant-block">
312
312
  <li v-for="consultant in expertConsultants" :key="consultant.url">
313
- <template v-if="consultant.name">
314
- <contributor-item :contributor="consultant" />
315
- </template>
316
- <div class="consultant-loading" v-else>
313
+ <contributor-item :contributor="consultant" v-if="consultant.name" />
314
+ <div class="consultant-loading" v-else-if="!consultant.error">
317
315
  <span>Loading {{ consultant.url }}</span>
318
316
  </div>
317
+ <div class="consultant-error" v-if="consultant.error">
318
+ <span v-if="consultant.errorMessage">{{ consultant.errorMessage }}</span>
319
+ <span v-else>Sorry, something went wrong.</span>
320
+ <template v-if="consultant.refreshable">
321
+ <br />
322
+ Please try again.
323
+ <span class="reload-button" @click="reloadConsultant(consultant)">
324
+ Reload
325
+ </span>
326
+ </template>
327
+ </div>
319
328
  </li>
320
329
  </ul>
321
330
  </div>
@@ -896,69 +905,148 @@ export default {
896
905
  return data
897
906
  },
898
907
  fetchExpertConsultants: async function () {
899
- this.expertConsultants = this.expertConsultantURLs.map(url => ({ name: '', url }));
908
+ this.expertConsultants = this.expertConsultantURLs.map((url) => ({
909
+ name: '',
910
+ url,
911
+ error: false,
912
+ errorMessage: '',
913
+ refreshable: false,
914
+ }));
900
915
 
901
916
  for (const url of this.expertConsultantURLs) {
902
- const scicrunchBase = 'https://scicrunch.org';
903
- const orcidBase = 'https://orcid.org';
904
- const orcidAPIBase = 'https://pub.orcid.org/v2.1';
905
- const apiLocationBase = (this.envVars.API_LOCATION ?? '').replace(/\/?$/, '/');
906
- const isScicrunchURL = url.startsWith(scicrunchBase);
907
- const isOrcidURL = url.startsWith(orcidBase);
908
-
909
- if (!isScicrunchURL && !isOrcidURL) {
910
- console.warn(`Unsupported expert consultant URL: ${url}`);
911
- continue;
917
+ await this.fetchSingleExpertConsultant(url);
918
+ }
919
+
920
+ this.updatedCopyContent = this.getUpdateCopyContent(this.storedReferences);
921
+ },
922
+ buildExpertConsultantRequestInfo: function (url) {
923
+ const scicrunchBase = 'https://scicrunch.org';
924
+ const orcidBase = 'https://orcid.org';
925
+ const orcidAPIBase = 'https://pub.orcid.org/v2.1';
926
+ const apiLocationBase = (this.envVars.API_LOCATION ?? '').replace(/\/?$/, '/');
927
+ const isScicrunchURL = url.startsWith(scicrunchBase);
928
+ const isOrcidURL = url.startsWith(orcidBase);
929
+
930
+ if (!isScicrunchURL && !isOrcidURL) {
931
+ return null;
932
+ }
933
+
934
+ const APIURL = isScicrunchURL
935
+ ? url.replace(scicrunchBase, `${apiLocationBase}scicrunch`)
936
+ : url.replace(orcidBase, orcidAPIBase);
937
+
938
+ return {
939
+ APIURL,
940
+ isScicrunchURL,
941
+ };
942
+ },
943
+ fetchSingleExpertConsultant: async function (url) {
944
+ const requestInfo = this.buildExpertConsultantRequestInfo(url);
945
+ if (!requestInfo) {
946
+ console.warn(`Unsupported expert consultant URL: ${url}`);
947
+ this.updateExpertConsultantByURL(url, {
948
+ name: '',
949
+ error: true,
950
+ errorMessage: 'Unsupported expert consultant URL.',
951
+ refreshable: false,
952
+ orcidId: '',
953
+ organization: '',
954
+ role: '',
955
+ });
956
+ return;
957
+ }
958
+
959
+ const { APIURL, isScicrunchURL } = requestInfo;
960
+
961
+ // Reset the consultant data before fetching
962
+ this.updateExpertConsultantByURL(url, {
963
+ name: '',
964
+ error: false,
965
+ errorMessage: '',
966
+ refreshable: false,
967
+ orcidId: '',
968
+ organization: '',
969
+ role: '',
970
+ });
971
+
972
+ try {
973
+ const response = await fetch(APIURL, {
974
+ headers: {
975
+ Accept: 'application/json',
976
+ },
977
+ });
978
+
979
+ if (!response.ok) {
980
+ throw new Error(`Response status: ${response.status}`);
912
981
  }
913
982
 
914
- const scicrunchAPIURL = (targetURL) => targetURL.replace(scicrunchBase, `${apiLocationBase}scicrunch`);
915
- const orcidAPIURL = (targetURL) => targetURL.replace(orcidBase, orcidAPIBase);
916
- const APIURL = isScicrunchURL ? scicrunchAPIURL(url) : orcidAPIURL(url);
983
+ const data = await response.json();
917
984
 
918
- try {
919
- const response = await fetch(APIURL, {
920
- headers: {
921
- 'Accept': 'application/json'
922
- }
985
+ if (isScicrunchURL) {
986
+ const { hits } = data?.hits || {};
987
+ const name = hits?.[0]?._source?.item?.name || '';
988
+
989
+ if (!name) {
990
+ throw new Error('No consultant data returned from SciCrunch.');
991
+ }
992
+
993
+ this.updateExpertConsultantByURL(url, {
994
+ name,
995
+ error: false,
996
+ errorMessage: '',
997
+ refreshable: false,
923
998
  });
924
- const data = await response.json();
925
- if (isScicrunchURL) {
926
- const { hits } = data?.hits || {};
927
- if (hits?.length) {
928
- const name = hits[0]?._source?.item?.name;
929
- if (name) {
930
- const consultantIndex = this.expertConsultants.findIndex((consultant) => consultant.url === url);
931
- if (consultantIndex !== -1) {
932
- this.expertConsultants[consultantIndex].name = name;
933
- }
934
- }
935
- }
936
- } else {
937
- const nameInfo = data?.person?.name;
938
- if (nameInfo) {
939
- const givenName = nameInfo['given-names']?.value || '';
940
- const familyName = nameInfo['family-name']?.value || '';
941
- const creditName = nameInfo['credit-name']?.value || '';
942
- const fullName = creditName || `${givenName} ${familyName}`.trim();
943
- if (fullName) {
944
- const consultantIndex = this.expertConsultants.findIndex((consultant) => consultant.url === url);
945
- if (consultantIndex !== -1) {
946
- this.expertConsultants[consultantIndex].name = fullName;
947
- const orcidId = data['orcid-identifier']?.path || '';
948
- this.expertConsultants[consultantIndex].orcidId = orcidId;
949
- const employmentSummary = data?.['activities-summary']?.['employments']?.['employment-summary'] || [];
950
- const latestEmployment = employmentSummary[0] || {};
951
- this.expertConsultants[consultantIndex].organization = latestEmployment?.organization?.name || '';
952
- this.expertConsultants[consultantIndex].role = latestEmployment?.['role-title'] || '';
953
- }
954
- }
955
- }
999
+ } else {
1000
+ const nameInfo = data?.person?.name;
1001
+ const givenName = nameInfo?.['given-names']?.value || '';
1002
+ const familyName = nameInfo?.['family-name']?.value || '';
1003
+ const creditName = nameInfo?.['credit-name']?.value || '';
1004
+ const fullName = creditName || `${givenName} ${familyName}`.trim();
1005
+
1006
+ if (!fullName) {
1007
+ throw new Error('No consultant data returned from ORCID.');
956
1008
  }
957
- } catch (error) {
958
- console.error('Error fetching expert consultant:', error);
1009
+
1010
+ const orcidId = data?.['orcid-identifier']?.path || '';
1011
+ const employmentSummary = data?.['activities-summary']?.['employments']?.['employment-summary'] || [];
1012
+ const latestEmployment = employmentSummary[0] || {};
1013
+
1014
+ this.updateExpertConsultantByURL(url, {
1015
+ name: fullName,
1016
+ error: false,
1017
+ errorMessage: '',
1018
+ refreshable: false,
1019
+ orcidId,
1020
+ organization: latestEmployment?.organization?.name || '',
1021
+ role: latestEmployment?.['role-title'] || '',
1022
+ });
959
1023
  }
1024
+ } catch (error) {
1025
+ console.error('Error fetching expert consultant:', error);
1026
+ this.updateExpertConsultantByURL(url, {
1027
+ name: '',
1028
+ error: true,
1029
+ errorMessage: 'Failed to fetch expert consultant data.',
1030
+ refreshable: true,
1031
+ orcidId: '',
1032
+ organization: '',
1033
+ role: '',
1034
+ });
1035
+ }
1036
+ },
1037
+ updateExpertConsultantByURL: function (url, fields = {}) {
1038
+ const consultantIndex = this.expertConsultants.findIndex((consultant) => consultant.url === url);
1039
+ if (consultantIndex === -1) {
1040
+ return;
960
1041
  }
961
1042
 
1043
+ this.expertConsultants.splice(consultantIndex, 1, {
1044
+ ...this.expertConsultants[consultantIndex],
1045
+ ...fields,
1046
+ });
1047
+ },
1048
+ reloadConsultant: async function (consultant) {
1049
+ await this.fetchSingleExpertConsultant(consultant.url);
962
1050
  this.updatedCopyContent = this.getUpdateCopyContent(this.storedReferences);
963
1051
  },
964
1052
  onConnectivityHovered: function (label) {
@@ -1684,6 +1772,14 @@ export default {
1684
1772
  }
1685
1773
  }
1686
1774
 
1775
+ .consultant-error {
1776
+ padding: 0.25rem 0.5rem;
1777
+ font-style: italic;
1778
+ color: var(--el-color-info);
1779
+ border: 1px dotted red;
1780
+ border-radius: 4px;
1781
+ }
1782
+
1687
1783
  .alert-chip {
1688
1784
  margin-left: 5px;
1689
1785
  background-color: $app-primary-color;
@@ -1718,6 +1814,12 @@ export default {
1718
1814
  width: 1px;
1719
1815
  }
1720
1816
 
1817
+ .reload-button {
1818
+ color: $app-primary-color;
1819
+ text-decoration: underline;
1820
+ cursor: pointer;
1821
+ }
1822
+
1721
1823
  @keyframes loadingAnimation {
1722
1824
  0% {
1723
1825
  background-position: -30vw 0;