kinow commented on code in PR #1792: URL: https://github.com/apache/jena/pull/1792#discussion_r1518885768
########## jena-fuseki2/jena-fuseki-ui/tests/unit/views/dataset/edit.vue.spec.js: ########## @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils' +import Edit from '@/views/dataset/Edit.vue' + +describe('Edit', () => { + const mountFunction = options => { + return mount(Edit, { + ...options, + global: { + mocks: { + $fusekiService: { + async listGraphs(datasetName, endpoint) { + return ["default"] + } + } + } + } + }) + } + it('show default graph without numbers by default', () => { + const component = mountFunction({ + propsData: { + datasetName: "myDataSet" + } + }) + expect(component.find('.card-body h3').text()).to.equal('Available Graphs') + + // TODO: should return 1 instead + // expect(component.findAll('tr').length).to.equal(1) Review Comment: :+1: ########## jena-fuseki2/jena-fuseki-ui/src/services/fuseki.service.js: ########## @@ -22,6 +22,7 @@ import { BUS } from '@/events' const DATASET_SIZE_QUERY_1 = 'select (count(*) as ?count) {?s ?p ?o}' const DATASET_SIZE_QUERY_2 = 'select ?g (count(*) as ?count) {graph ?g {?s ?p ?o}} group by ?g' +const DATASET_GRAPHS = 'select ?g {graph ?g {}}' Review Comment: Maybe we can rename this to `$same_QUERY`... ########## jena-fuseki2/jena-fuseki-ui/src/services/fuseki.service.js: ########## @@ -157,6 +158,15 @@ class FusekiService { return axios.get(this.getFusekiUrl('/$/tasks')) } + async listGraphs (datasetName, endpoint) { + const result = await axios.get(this.getFusekiUrl(`/${datasetName}/${endpoint}`), { + params: { + query: DATASET_GRAPHS + } + }) + return ["default", ...result.data.results.bindings.map(binding => binding.g.value)] Review Comment: Cleaner than the other methods doing the `forEach`! Will apply that to the rest of the code in a future PR. Thanks! ########## jena-fuseki2/jena-fuseki-ui/src/views/dataset/Edit.vue: ########## @@ -237,13 +238,19 @@ export default { this.content = newVal this.codemirrorEditor.scrollTo(scrollInfo.left, scrollInfo.top) }, - listCurrentGraphs: async function () { + listCurrentGraphs: async function (count=true) { this.loadingGraphs = true this.loadingGraph = true this.code = '' this.selectedGraph = '' try { - this.graphs = await this.$fusekiService.countGraphsTriples(this.datasetName, this.services.query['srv.endpoints'][0]) + const endpoint = this.services.query['srv.endpoints'][0] + if (count) { + this.graphs = await this.$fusekiService.countGraphsTriples(this.datasetName, endpoint) + } else { + const graphs = await this.$fusekiService.listGraphs(this.datasetName, endpoint) + this.graphs = Object.fromEntries(graphs.map(name => [name, ""])) + } Review Comment: Yeah, it looks like one function with a bool=true returns just the count, and for bool=false the graphs (with the counts too?). I think one is bringing the count to display the graphs and the count. The other is bringing the graphs and services available. If so, we can probably split this function into two, one for the graph services, and another for the counts. (Need to confirm) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
