• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FAIRsharing / fairsharing.github.io / 24769584990

22 Apr 2026 08:57AM UTC coverage: 95.892% (-4.1%) from 100.0%
24769584990

push

github

web-flow
Merge pull request #2746 from FAIRsharing/dev

Dev

3653 of 3813 branches covered (95.8%)

Branch coverage included in aggregate %.

17344 of 18229 new or added lines in 282 files covered. (95.15%)

766 existing lines in 50 files now uncovered.

38617 of 40268 relevant lines covered (95.9%)

5.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.0
/src/store/editor.js
1
import descriptionData from "@/data/fieldsDescription.json";
1✔
2
import recordTooltipData from "@/data/recordTooltips.json";
1✔
3
import status from "@/data/status.json";
1✔
4
import supportLinksTypes from "@/data/SupportLinksTypes.json";
1✔
5
import RESTClient from "@/lib/Client/RESTClient.js";
1✔
6
import GraphClient from "@/lib/GraphClient/GraphClient.js";
1✔
7
import getRecordsQuery from "@/lib/GraphClient/queries/editor/getRecordsSummary.json";
1✔
8
import tagsQuery from "@/lib/GraphClient/queries/geTags.json";
1✔
9
import countriesQuery from "@/lib/GraphClient/queries/getCountries.json";
1✔
10
import getDuplicates from "@/lib/GraphClient/queries/getDuplicates.json";
1✔
11
import getLicencesQuery from "@/lib/GraphClient/queries/getLicences.json";
1✔
12
import objectTypesQuery from "@/lib/GraphClient/queries/getObjectTypes.json";
1✔
13
import getPublicationsQuery from "@/lib/GraphClient/queries/getPublications.json";
1✔
14
import typesQuery from "@/lib/GraphClient/queries/getRecordsTypes.json";
1✔
15
import getGrantsQuery from "@/lib/GraphClient/queries/Organisations/getGrants.json";
1✔
16
import getOrganisationsQuery from "@/lib/GraphClient/queries/Organisations/getOrganisations.json";
1✔
17
import getOrganisationsTypesQuery from "@/lib/GraphClient/queries/Organisations/getOrganisationTypes.json";
1✔
18
const graphClient = new GraphClient();
1✔
19
const restClient = new RESTClient();
1✔
20

21
const recordTypes = [
1✔
22
  "standard",
1✔
23
  "database",
1✔
24
  "policy",
1✔
25
  "collection",
1✔
26
  "fairassist",
1✔
27
  "journal_publisher",
1✔
28
  "repository",
1✔
29
  "knowledgebase",
1✔
30
  "model_and_format",
1✔
31
  "terminology_artefact",
1✔
32
  "reporting_guideline",
1✔
33
  "identifier_schema",
1✔
34
  "journal",
1✔
35
  "collection",
1✔
36
  "metric",
1✔
37
  "knowledgebase_and_repository",
1✔
38
  "project",
1✔
39
  "funder",
1✔
40
  "institution",
1✔
41
  "society",
1✔
42
  "benchmark",
1✔
43
  "principle",
1✔
44
];
1✔
45

46
let editorStore = {
1✔
47
  namespaced: true,
1✔
48
  state: {
1✔
49
    countries: null,
1✔
50
    recordTypes: null,
1✔
51
    status: status.status,
1✔
52
    tooltips: descriptionData.descriptions,
1✔
53
    recordTooltips: recordTooltipData.descriptions,
1✔
54
    tags: [],
1✔
55
    objectTypes: [],
1✔
56
    years() {
1✔
NEW
57
      let years = [];
×
NEW
58
      let d = new Date();
×
NEW
59
      let thisYear = d.getFullYear();
×
NEW
60
      [...Array(100).keys()].forEach(function (year) {
×
NEW
61
        years.push(thisYear - year);
×
NEW
62
      });
×
NEW
63
      return years;
×
64
    },
1✔
65
    colors: {
1✔
66
      domain: "domain_color",
1✔
67
      taxonomy: "taxonomic_color",
1✔
68
      subject: "subject_color",
1✔
69
      user_defined_tag: "tags_color",
1✔
70
      object_type: "object_type_color",
1✔
71
    },
1✔
72
    allTags: false,
1✔
73
    organisations: null,
1✔
74
    organisationsTypes: null,
1✔
75
    organisationsRelations: [
1✔
76
      "maintains",
1✔
77
      "funds",
1✔
78
      "collaborates_on",
1✔
79
      "associated_with",
1✔
80
      "undefined",
1✔
81
    ],
1✔
82
    grants: null,
1✔
83
    availablePublications: [],
1✔
84
    supportLinksTypes: supportLinksTypes,
1✔
85
    availableLicences: [],
1✔
86
    licenceRelations: ["applies_to_content", "undefined"],
1✔
87
    accessPointTypes: ["REST", "SOAP", "SPARQL", "Other"],
1✔
88
    availableRecords: [],
1✔
89
    possibleDuplicates: [],
1✔
90
    relationsTypes: [],
1✔
91
    allowedFields: {},
1✔
92
  },
1✔
93
  mutations: {
1✔
94
    setCountries(state, countries) {
1✔
95
      state.countries = countries;
15✔
96
    },
1✔
97
    setRecordTypes(state, recordTypes) {
1✔
98
      state.recordTypes = recordTypes;
8✔
99
    },
1✔
100
    setObjectTypes(state, objectTypes) {
1✔
101
      state.objectTypes = objectTypes;
6✔
102
    },
1✔
103
    setTags(state, tags) {
1✔
104
      state.tags = tags.data;
10✔
105
      if (tags.firstTime) {
10✔
106
        state.allTags = tags.data;
4✔
107
      }
4✔
108
    },
1✔
109
    setOrganisations(state, organisations) {
1✔
110
      state.organisations = organisations;
20✔
111
    },
1✔
112
    setOrganisationsTypes(state, organisationsTypes) {
1✔
113
      state.organisationsTypes = organisationsTypes;
16✔
114
    },
1✔
115
    setGrants(state, grants) {
1✔
116
      state.grants = grants;
1✔
117
    },
1✔
118
    setAvailablePublications(state, publications) {
1✔
119
      state.availablePublications = publications;
31✔
120
    },
1✔
121
    setAvailableLicences(state, licences) {
1✔
122
      state.availableLicences = licences;
4✔
123
    },
1✔
124
    cleanEditorStore(state) {
1✔
125
      state.countries = null;
2✔
126
      state.recordTypes = null;
2✔
127
      state.allTags = [];
2✔
128
      state.tags = [];
2✔
129
      state.objectTypes = [];
2✔
130
      state.organisations = null;
2✔
131
      state.organisationsTypes = null;
2✔
132
      state.grants = null;
2✔
133
      state.availablePublications = [];
2✔
134
      state.possibleDuplicates = [];
2✔
135
    },
1✔
136
    setAvailableRecords(state, records) {
1✔
NEW
137
      state.availableRecords = records;
×
138
    },
1✔
139
    setAvailableRelationsTypes(state, types) {
1✔
NEW
140
      state.relationsTypes = types;
×
141
    },
1✔
142
    setAllowedFields(state, fields) {
1✔
143
      state.allowedFields = fields;
10✔
144
    },
1✔
145
    setPossibleDuplicates(state, records) {
1✔
146
      state.possibleDuplicates = records;
5✔
147
    },
1✔
148
    clearPossibleDuplicates(state) {
1✔
149
      state.possibleDuplicates = [];
13✔
150
    },
1✔
151
  },
1✔
152
  actions: {
1✔
153
    async getCountries(state) {
1✔
154
      try {
15✔
155
        let countries = await graphClient.executeQuery(countriesQuery);
15✔
156
        state.commit("setCountries", countries?.searchCountries || []);
15✔
157
      } catch (e) {
15!
NEW
158
        state.commit("setCountries", []);
×
NEW
159
      }
×
160
    },
1✔
161
    async getRecordTypes(state, fairassistOnly = false) {
1✔
162
      let recordTypes = [];
8✔
163
      try {
8✔
164
        let data = await graphClient.executeQuery(typesQuery);
8✔
165
        let registries = data?.fairsharingRegistries?.records || [];
8✔
166
        let filteredRegistries = registries.filter((type) => {
8✔
167
          if (!type || !type.name) return false;
12!
168
          return !fairassistOnly || type.name.toLowerCase() === "fairassist";
12✔
169
        });
8✔
170

171
        filteredRegistries.forEach(function (type, index) {
8✔
172
          recordTypes.push({
11✔
173
            header: type.name,
11✔
174
          });
11✔
175
          (type.recordTypes || []).forEach(function (subType) {
11✔
176
            recordTypes.push({
10✔
177
              name: subType.name,
10✔
178
              group: type.name,
10✔
179
              id: subType.id,
10✔
180
              description: subType.description,
10✔
181
            });
10✔
182
          });
11✔
183
          if (index < filteredRegistries.length - 1) {
11✔
184
            recordTypes.push({ divider: true });
5✔
185
          }
5✔
186
        });
8✔
187
      } catch (e) {
8!
NEW
188
        recordTypes = [];
×
NEW
189
      }
×
190
      state.commit("setRecordTypes", recordTypes);
8✔
191
    },
1✔
192
    async getObjectTypes(state) {
1✔
193
      let objectTypes = [];
6✔
194
      try {
6✔
195
        let data = await graphClient.executeQuery(objectTypesQuery);
6✔
196
        (data?.objectTypes?.records || []).forEach(function (type) {
6✔
197
          objectTypes.push(type);
3✔
198
        });
6✔
199
      } catch (e) {
6!
NEW
200
        objectTypes = [];
×
NEW
201
      }
×
202
      state.commit("setObjectTypes", objectTypes);
6✔
203
    },
1✔
204
    async getTags(state, queryString) {
1✔
205
      let tagQueryCopy = JSON.parse(JSON.stringify(tagsQuery));
10✔
206
      if (queryString) tagQueryCopy.queryParam = { q: queryString };
10✔
207
      try {
10✔
208
        let data = await graphClient.executeQuery(tagQueryCopy);
10✔
209
        let first = !state.state.allTags;
10✔
210
        state.commit("setTags", {
10✔
211
          data: data?.searchTags || [],
10✔
212
          firstTime: first,
10✔
213
        });
10✔
214
      } catch (e) {
10!
NEW
215
        let first = !state.state.allTags;
×
NEW
216
        state.commit("setTags", { data: [], firstTime: first });
×
NEW
217
      }
×
218
    },
1✔
219
    async getOrganisations(state) {
1✔
220
      let organisations = await graphClient.executeQuery(getOrganisationsQuery);
20✔
221
      state.commit("setOrganisations", organisations["searchOrganisations"]);
20✔
222
    },
1✔
223
    async getOrganisationsTypes(state) {
1✔
224
      let organisationsTypes = await graphClient.executeQuery(
16✔
225
        getOrganisationsTypesQuery,
16✔
226
      );
16✔
227
      state.commit(
16✔
228
        "setOrganisationsTypes",
16✔
229
        organisationsTypes["searchOrganisationTypes"],
16✔
230
      );
16✔
231
    },
1✔
232
    async getGrants(state) {
1✔
233
      let grants = await graphClient.executeQuery(getGrantsQuery);
1✔
234
      state.commit("setGrants", grants["searchGrants"]);
1✔
235
    },
1✔
236
    async getAvailablePublications({ commit }, publications) {
1✔
237
      let pubs = [],
31✔
238
        position = 0;
31✔
239
      let response = await graphClient.executeQuery(getPublicationsQuery);
31✔
240
      response.searchPublications.forEach((pub) => {
31✔
241
        pub.isCitation = false;
93✔
242
        publications.forEach((publication) => {
93✔
243
          if (pub.id === publication.id) {
186✔
244
            publication.tablePosition = position;
31✔
245
            pub.tablePosition = position;
31✔
246
          }
31✔
247
        });
93✔
248
        pubs.push(pub);
93✔
249
        position += 1;
93✔
250
      });
31✔
251
      commit("setAvailablePublications", pubs);
31✔
252
    },
1✔
253
    async getLicences({ commit }) {
1✔
254
      let licences = await graphClient.executeQuery(getLicencesQuery);
4✔
255
      commit("setAvailableLicences", licences["searchLicences"]);
4✔
256
    },
1✔
257
    async getAvailableRecords({ commit }, options) {
1✔
NEW
258
      getRecordsQuery.queryParam = { perPage: 100 };
×
NEW
259
      if (options.q) getRecordsQuery.queryParam.q = options.q;
×
NEW
260
      getRecordsQuery.queryParam.fairsharingRegistry =
×
NEW
261
        options.fairsharingRegistry;
×
NEW
262
      getRecordsQuery.queryParam.recordType = options.recordType;
×
NEW
263
      getRecordsQuery.queryParam.searchAnd = false;
×
NEW
264
      getRecordsQuery.queryParam.excludeId = options.excludeId;
×
NEW
265
      let data = await graphClient.executeQuery(getRecordsQuery);
×
NEW
266
      commit("setAvailableRecords", data.searchFairsharingRecords.records);
×
267
    },
1✔
268
    async getPossibleDuplicates({ commit }, options) {
1✔
269
      getDuplicates.queryParam = { fields: options.fields };
5✔
270
      let data = await graphClient.executeQuery(getDuplicates);
5✔
271
      commit("setPossibleDuplicates", data.duplicateCheck);
5✔
272
    },
1✔
273
    async getAvailableRelationsTypes({ commit }) {
1✔
NEW
274
      let types = await restClient.getRelationsTypes();
×
NEW
275
      let allowed = {};
×
NEW
276
      for (let typeObject of types) {
×
NEW
277
        let relationName = typeObject.name,
×
NEW
278
          id = typeObject.id;
×
NEW
279
        /* istanbul ignore else */
×
NEW
280
        if (typeObject["allowed_associations"].length > 0) {
×
NEW
281
          typeObject["allowed_associations"].forEach((allowed_association) => {
×
NEW
282
            let relationParent = allowed_association.from;
×
NEW
283
            let relationChild = allowed_association.to;
×
NEW
284
            /* istanbul ignore if */ if (
×
NEW
285
              !Object.keys(allowed).includes(relationParent)
×
NEW
286
            ) {
×
NEW
287
              allowed[relationParent] = [];
×
NEW
288
            }
×
NEW
289
            allowed[relationParent].push({
×
NEW
290
              relation: relationName,
×
NEW
291
              target: relationChild,
×
NEW
292
              id: id,
×
NEW
293
              relationId: typeObject.id,
×
UNCOV
294
            });
×
NEW
295
          });
×
NEW
296
        } else {
×
NEW
297
          recordTypes.forEach((relationParent) => {
×
NEW
298
            if (!Object.keys(allowed).includes(relationParent)) {
×
NEW
299
              allowed[relationParent] = [];
×
UNCOV
300
            }
×
NEW
301
            recordTypes.forEach((relationChild) => {
×
NEW
302
              allowed[relationParent].push({
×
NEW
303
                relation: relationName,
×
NEW
304
                target: relationChild,
×
NEW
305
                id: id,
×
NEW
306
                relationId: typeObject.id,
×
NEW
307
              });
×
NEW
308
            });
×
NEW
309
          });
×
NEW
310
        }
×
NEW
311
      }
×
NEW
312
      commit("setAvailableRelationsTypes", allowed);
×
313
    },
1✔
314
    async getAllowedFields({ commit }, options) {
1✔
315
      let response = await restClient.extraMetadataFields(
10✔
316
        options.type,
10✔
317
        options.token,
10✔
318
      );
10✔
319
      commit("setAllowedFields", response);
10✔
320
    },
1✔
321
  },
1✔
322
  modules: {},
1✔
323
  getters: {
1✔
324
    getPartialTags: (state) => (sections) => {
1✔
325
      let tags = [];
13✔
326
      for (let tag of state.tags) {
13✔
327
        if (sections.indexOf(tag.model) > -1) {
53✔
328
          tags.push(tag);
47✔
329
        }
47✔
330
      }
53✔
331
      return tags;
13✔
332
    },
1✔
333
    allowedRelations: (state) => (options) => {
1✔
NEW
334
      let output = [];
×
NEW
335
      let seen = [];
×
NEW
336
      [options.sourceType, options.sourceRegistry].forEach((type) => {
×
NEW
337
        // This undefined check prevents allowed relations from being pushed to the array twice,
×
NEW
338
        // as we're checking for both registry and record type here.
×
NEW
339
        /* istanbul ignore else */
×
NEW
340
        if (state.relationsTypes[type] !== undefined) {
×
NEW
341
          state.relationsTypes[type].forEach((relation) => {
×
NEW
342
            // Somehow, duplicate relations were being pushed into this array.
×
NEW
343
            // I've created a text label as the ID of a relation may be duplicated, i.e.
×
NEW
344
            // db->related_to->std would be the same ID as db->related_to->db.
×
NEW
345
            let label = relation.relation + "." + relation.target;
×
NEW
346
            if (!seen.includes(label)) {
×
NEW
347
              // This appears to be called when loading the page, to determine which currently-linked
×
NEW
348
              // records to show.
×
NEW
349
              if (options.target === null) {
×
NEW
350
                output.push(relation);
×
NEW
351
                seen.push(label);
×
NEW
352
              }
×
NEW
353
              // Whereas this is what determines what available links can be shown when adding a new one.
×
NEW
354
              else {
×
NEW
355
                if (
×
NEW
356
                  options.target.registry === relation.target ||
×
NEW
357
                  options.target.type === relation.target
×
NEW
358
                ) {
×
NEW
359
                  output.push(relation);
×
NEW
360
                  seen.push(label);
×
UNCOV
361
                }
×
NEW
362
              }
×
UNCOV
363
            }
×
NEW
364
          });
×
UNCOV
365
        }
×
NEW
366
      });
×
NEW
367
      return output;
×
368
    },
1✔
369
    allowedTargets: (state) => (source) => {
1✔
NEW
370
      let output = [];
×
NEW
371
      state.relationsTypes[source.toLowerCase()].forEach((relation) => {
×
NEW
372
        /* istanbul ignore else */
×
NEW
373
        if (recordTypes.includes(relation.target)) output.push(relation.target);
×
NEW
374
      });
×
NEW
375
      return [...new Set(output)];
×
376
    },
1✔
377
  },
1✔
378
};
1✔
379

380
export default editorStore;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc