-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JENA-2282: Fuseki2 Query Store #1459
Open
jamiefeiss
wants to merge
2
commits into
apache:main
Choose a base branch
from
jamiefeiss:query-library
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
jena-fuseki2/jena-fuseki-ui/src/components/dataset/EditQueryModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<b-modal title="Edit SPARQL query" size="lg" :id="id" v-model="show" @hide="$emit('editQueryModalHide')"> | ||
<b-form-group label="Name"> | ||
<b-form-input v-model="editQuery.name" type="text" placeholder="Query name"></b-form-input> | ||
</b-form-group> | ||
<b-spinner v-if="loading"></b-spinner> | ||
<div id="edit-yasqe"></div> | ||
<template #modal-footer> | ||
<b-button variant="outline-secondary" @click="show = false"> | ||
Cancel | ||
</b-button> | ||
<b-button variant="primary" @click="saveQuery" :disabled="!validName"> | ||
Save | ||
</b-button> | ||
</template> | ||
</b-modal> | ||
</template> | ||
|
||
<script> | ||
import Yasqe from '@triply/yasqe' | ||
|
||
export default { | ||
name: 'EditQueryModal', | ||
props: { | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
editId: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
data () { | ||
return { | ||
show: false, | ||
editQuery: { | ||
name: '', | ||
query: '' | ||
}, | ||
yasqe: null, | ||
loading: true | ||
} | ||
}, | ||
computed: { | ||
validName () { | ||
return this.editQuery.name.length > 0 | ||
} | ||
}, | ||
methods: { | ||
saveQuery () { | ||
this.$store.dispatch('queryLibrary/editSavedQuery', this.editQuery) | ||
this.show = false | ||
} | ||
}, | ||
mounted () { | ||
this.editQuery = this.$store.getters['queryLibrary/getSavedQuery'](this.editId) | ||
this.$bvModal.show(this.id) | ||
this.$nextTick(() => { | ||
setTimeout(() => { | ||
const vm = this | ||
vm.yasqe = new Yasqe(document.getElementById('edit-yasqe'), { | ||
showQueryButton: false, | ||
queryingDisabled: true, | ||
resizeable: false, | ||
createShareableLink: null, | ||
persistenceId: null | ||
}) | ||
vm.yasqe.setValue(this.editQuery.query) | ||
this.loading = false | ||
vm.yasqe.on('change', (yasqe) => { this.editQuery.query = yasqe.getValue() }) | ||
}, 300) | ||
}) | ||
} | ||
} | ||
</script> |
79 changes: 79 additions & 0 deletions
79
jena-fuseki2/jena-fuseki-ui/src/components/dataset/QueryLibraryModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<template> | ||
<b-modal title="SPARQL Query Library" size="lg" :id="id" v-model="show" @hide="$emit('queryLibraryModalHide')"> | ||
<b-list-group> | ||
<b-list-group-item | ||
class="d-flex justify-content-between align-items-center" | ||
button | ||
v-for="item in $store.getters['queryLibrary/listSavedQueries']" | ||
:key="item.id" | ||
@click="handleLoad(item.id)" | ||
> | ||
{{ item.name }} | ||
<div> | ||
<b-button variant="outline-warning" size="sm" class="mr-2" @click.stop="handleEdit(item.id)"> | ||
<FontAwesomeIcon icon="pen-to-square" /> | ||
</b-button> | ||
<b-button variant="outline-danger" size="sm" @click.stop="handleDelete(item.id)"> | ||
<FontAwesomeIcon icon="trash" /> | ||
</b-button> | ||
</div> | ||
</b-list-group-item> | ||
</b-list-group> | ||
<EditQueryModal v-if="editQueryModal" id="query-library" @editQueryModalHide="editQueryModal=false" :editId="editId"/> | ||
<template #modal-footer> | ||
<b-button variant="secondary" @click="show = false"> | ||
Close | ||
</b-button> | ||
</template> | ||
</b-modal> | ||
</template> | ||
|
||
<script> | ||
import EditQueryModal from '@/components/dataset/EditQueryModal' | ||
import { library } from '@fortawesome/fontawesome-svg-core' | ||
import { faTrash, faPenToSquare } from '@fortawesome/free-solid-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' | ||
|
||
library.add(faTrash, faPenToSquare) | ||
|
||
export default { | ||
name: 'QueryLibraryModal', | ||
components: { | ||
EditQueryModal, | ||
FontAwesomeIcon | ||
}, | ||
props: { | ||
id: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
data () { | ||
return { | ||
show: false, | ||
editQueryModal: false, | ||
editId: '' | ||
} | ||
}, | ||
mounted () { | ||
this.$bvModal.show(this.id) | ||
}, | ||
methods: { | ||
handleLoad (id) { | ||
const query = this.$store.getters['queryLibrary/getSavedQuery'](id) | ||
this.$emit('loadSavedQuery', query.query) | ||
this.show = false | ||
}, | ||
handleEdit (id) { | ||
this.editId = id | ||
this.editQueryModal = true | ||
}, | ||
handleDelete (id) { | ||
const query = this.$store.getters['queryLibrary/getSavedQuery'](id) | ||
if (confirm(`Are you sure you want to delete "${query.name}"?`)) { | ||
this.$store.dispatch('queryLibrary/deleteSavedQuery', id) | ||
} | ||
} | ||
} | ||
} | ||
</script> |
89 changes: 89 additions & 0 deletions
89
jena-fuseki2/jena-fuseki-ui/src/components/dataset/SaveQueryModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<template> | ||
<b-modal title="Save SPARQL query" size="lg" :id="id" v-model="show" @hide="$emit('saveQueryModalHide')"> | ||
<b-form-group label="Name"> | ||
<b-form-input v-model="name" type="text" placeholder="Query name"></b-form-input> | ||
</b-form-group> | ||
<b-spinner v-if="loading"></b-spinner> | ||
<div id="save-yasqe"></div> | ||
<template #modal-footer> | ||
<b-button | ||
variant="outline-secondary" | ||
@click="show=false" | ||
> | ||
Cancel | ||
</b-button> | ||
<b-button | ||
variant="primary" | ||
@click="saveQuery" | ||
:disabled="!validName" | ||
> | ||
Save | ||
</b-button> | ||
</template> | ||
</b-modal> | ||
</template> | ||
|
||
<style lang="scss"> | ||
#save-yasqe { | ||
opacity: 0.6; | ||
} | ||
</style> | ||
|
||
<script> | ||
import { v4 as uuidv4 } from 'uuid' | ||
import Yasqe from '@triply/yasqe' | ||
|
||
export default { | ||
name: 'SaveQueryModal', | ||
props: { | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
query: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
data () { | ||
return { | ||
show: false, | ||
name: '', | ||
loading: true | ||
} | ||
}, | ||
computed: { | ||
validName () { | ||
return this.name.length > 0 | ||
} | ||
}, | ||
methods: { | ||
saveQuery () { | ||
this.$store.dispatch('queryLibrary/addSavedQuery', { | ||
id: uuidv4(), | ||
name: this.name, | ||
query: this.query | ||
}) | ||
this.show = false | ||
} | ||
}, | ||
mounted () { | ||
this.$bvModal.show(this.id) | ||
this.$nextTick(() => { | ||
setTimeout(() => { | ||
const vm = this | ||
vm.yasqe = new Yasqe(document.getElementById('save-yasqe'), { | ||
showQueryButton: false, | ||
queryingDisabled: true, | ||
resizeable: false, | ||
createShareableLink: null, | ||
persistenceId: null, | ||
readOnly: 'nocursor' | ||
}) | ||
vm.yasqe.setValue(this.query) | ||
this.loading = false | ||
}, 300) | ||
}) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,14 @@ | |
import { createApp, h } from 'vue' | ||
import App from './App.vue' | ||
import router from './router' | ||
import store from './store' | ||
import 'bootstrap/dist/js/bootstrap.bundle.min' | ||
import { FusekiServicePlugin, ToastPlugin } from '@/plugins/index' | ||
|
||
const app = createApp(App) | ||
|
||
app.use(router) | ||
app.use(store) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Create the global Fuseki Service instance. | ||
app.use(FusekiServicePlugin) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createStore } from 'vuex' | ||
import VuexPersistence from 'vuex-persist' | ||
import { queryLibraryStore } from './queryLibraryStore' | ||
|
||
export default createStore({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used |
||
modules: { | ||
queryLibrary: queryLibraryStore | ||
}, | ||
plugins: [new VuexPersistence({ | ||
storage: window.localStorage, | ||
modules: ['queryLibrary'] | ||
}).plugin] | ||
}) |
55 changes: 55 additions & 0 deletions
55
jena-fuseki2/jena-fuseki-ui/src/store/queryLibraryStore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const getWithId = (array, id) => { | ||
const idx = array.map(x => x.id).indexOf(id) | ||
const idMatch = array[idx] | ||
return [idMatch, idx] | ||
} | ||
|
||
export const queryLibraryStore = { | ||
namespaced: true, | ||
state: () => ({ | ||
savedQueries: [] // [{ id: '', name: '', query: ''}, ...] | ||
}), | ||
getters: { | ||
listSavedQueries (state) { | ||
return state.savedQueries.sort((a, b) => a.name.localeCompare(b.name)) | ||
}, | ||
getSavedQuery: (state) => (payload) => { | ||
const query = getWithId(state.savedQueries, payload)[0] | ||
return query | ||
} | ||
}, | ||
mutations: { | ||
addSavedQuery (state, payload) { | ||
const tempSavedQueries = [...state.savedQueries] | ||
tempSavedQueries.push(payload) | ||
state.savedQueries = tempSavedQueries | ||
}, | ||
editSavedQuery (state, payload) { | ||
const tempSavedQueries = [...state.savedQueries] | ||
const index = getWithId(tempSavedQueries, payload.id)[1] | ||
if (index !== -1) { | ||
tempSavedQueries[index] = payload | ||
state.savedQueries = tempSavedQueries | ||
} | ||
}, | ||
deleteSavedQuery (state, payload) { | ||
const tempSavedQueries = [...state.savedQueries] | ||
const index = getWithId(tempSavedQueries, payload)[1] | ||
if (index !== -1) { | ||
tempSavedQueries.splice(index, 1) | ||
state.savedQueries = tempSavedQueries | ||
} | ||
} | ||
}, | ||
actions: { | ||
addSavedQuery ({ commit }, payload) { | ||
commit('addSavedQuery', payload) | ||
}, | ||
editSavedQuery ({ commit }, payload) { | ||
commit('editSavedQuery', payload) | ||
}, | ||
deleteSavedQuery ({ commit }, payload) { | ||
commit('deleteSavedQuery', payload) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the version of Vuex as we are using Vue 3 now too.