Skip to content

Commit 0545506

Browse files
committed
make save as example button dependant on if an example repo has been provided
1 parent aeb1c61 commit 0545506

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ You can customize a few optional attributes when calling the custom element:
147147
></sparql-editor>
148148
```
149149

150+
### 🎨 Styling
151+
152+
The web component uses a light DOM, instead of a shadow DOM, to make it easier for the developers to style the application at their convenience, using the usual tool they know: CSS. Just inspect the elements you want to change and write the appropriate CSS.
153+
150154
### 📝 Basic example
151155

152156
No need for a complex project you can integrate SPARQL editor in any HTML page by importing from a CDN!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"email": "vincent.emonet@gmail.com"
1616
},
1717
"scripts": {
18-
"dev": "npm run dev --workspace=@sib-swiss/sparql-editor",
18+
"dev": "npm run dev -w packages/sparql-editor",
1919
"build": "npm run build --workspaces",
2020
"test": "npm run test -w packages/sparql-editor",
2121
"build:editor": "npm run build -w packages/sparql-editor",

packages/sparql-editor/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
<meta name="description" content="SPARQL editor development page" />
88
<link rel="icon" type="image/png" href="demo/sib-logo.png" />
99

10-
<!-- <script type="module" src="./src/sparql-editor.ts"></script> -->
10+
<script type="module" src="./src/sparql-editor.ts"></script>
1111

12-
<!-- DOES NOT WORK -->
13-
<script type="module" src="https://esm.sh/@sib-swiss/sparql-editor"></script>
12+
<!-- <script type="module" src="https://esm.sh/@sib-swiss/sparql-editor"></script> -->
1413
<!-- <script type="module" src="https://esm.sh/@sib-swiss/sparql-editor/dist/sparql-editor.js"></script> -->
1514

1615
<!-- <script src="https://cdn.jsdelivr.net/npm/@sib-swiss/sparql-editor/dist/sparql-editor.umd.js"></script> -->

packages/sparql-editor/src/sparql-editor.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,37 @@ export class SparqlEditor extends HTMLElement {
223223
display: none !important;
224224
}`;
225225
}
226+
console.log("this.examplesRepo", this.examplesRepo);
227+
const saveAsExampleBtn = this.examplesRepo
228+
? `<button id="sparql-save-example-btn" class="btn top-btn" title="Save the current query as example">
229+
Save query as example
230+
</button>`
231+
: "";
226232
this.className = "sparql-editor-container";
227233
this.innerHTML = `
228234
<div style="width: 100%;">
229235
<a id="status-link" href="" target="_blank" title="Loading..." style="display: inline-flex; width: 16px; height: 16px;">
230236
<div id="status-light" style="width: 10px; height: 10px; background-color: purple; border-radius: 50%; margin: 0 auto;"></div>
231237
</a><button id="sparql-add-prefixes-btn" class="btn top-btn" title="Add prefixes commonly used in the selected endpoint to the query">
232238
Add common prefixes
233-
</button><button id="sparql-save-example-btn" class="btn top-btn" title="Save the current query as example">
234-
Save query as example
235-
</button><button id="sparql-examples-top-btn" class="btn top-btn" title="Browse examples available for the selected endpoint">
239+
</button>${saveAsExampleBtn}<button id="sparql-examples-top-btn" class="btn top-btn" title="Browse examples available for the selected endpoint">
236240
Browse examples
237241
</button><button id="sparql-cls-overview-btn" class="btn top-btn" title="Overview of classes and their relations in the endpoint">
238242
Classes overview
239-
</button><button id="sparql-clear-cache-btn" class="btn top-btn" title="Clear and update the endpoints metadata stored in the cache">
240-
Clear cache
243+
</button><button id="sparql-clear-cache-btn" class="btn top-btn" title="Refresh and update the endpoints metadata stored in the cache">
244+
Refresh cache
241245
</button><button id="sparql-toggle-examples-btn" class="btn top-btn" title="Toggle display of the examples panel">
242246
Toggle examples
243247
</button>
244248
<div id="yasgui"></div>
245249
</div>`;
246250
this.appendChild(styleEl);
251+
// TODO: hide `Save query as example` button if examplesRepo is not set
252+
// // Hide "Save query as example" button if this.examplesRepo is not set
253+
// const saveExampleBtn = this.querySelector("#sparql-save-example-btn") as HTMLButtonElement;
254+
// if (!this.examplesRepo) {
255+
// saveExampleBtn.style.display = "none";
256+
// }
247257

248258
// NOTE: autocompleters are executed when Yasgui is instantiated
249259
Yasgui.Yasqe.defaults.autocompleters.splice(Yasgui.Yasqe.defaults.autocompleters.indexOf("prefixes"), 1);
@@ -432,21 +442,23 @@ export class SparqlEditor extends HTMLElement {
432442
});
433443

434444
// Button to pop a dialog to save the query as an example in a turtle file
435-
const saveExampleBtnEl = this.querySelector("#sparql-save-example-btn");
436-
saveExampleBtnEl?.addEventListener("click", () => {
437-
this.showSaveExampleDialog();
438-
});
445+
if (this.examplesRepo) {
446+
const saveExampleBtnEl = this.querySelector("#sparql-save-example-btn");
447+
saveExampleBtnEl?.addEventListener("click", () => {
448+
this.showSaveExampleDialog();
449+
});
450+
}
439451

440452
// NOTE: Yasqe already automatically loads search params from the URL in the editor and run the query
441453
// But it does not trigger the .on("query") event, so it does not add limit
442454
// http://localhost:3000/?endpoint=https://sparql.uniprot.org/sparql/&query=select%20*%20where%20{?s%20?p%20?o%20.}
443-
if (window.location.search) {
444-
const searchParams = new URLSearchParams(window.location.search);
445-
if (searchParams.get("query")) {
446-
this.addPrefixesToQueryInEditor();
447-
this.yasgui.getTab()?.getYasqe().query();
448-
}
449-
}
455+
// if (window.location.search) {
456+
// const searchParams = new URLSearchParams(window.location.search);
457+
// if (searchParams.get("query")) {
458+
// this.addPrefixesToQueryInEditor();
459+
// this.yasgui.getTab()?.getYasqe().query();
460+
// }
461+
// }
450462
}
451463

452464
// Original autocompleters: https://github.com/zazuko/Yasgui/blob/main/packages/yasqe/src/autocompleters/classes.ts#L8

packages/sparql-overview/src/sparql-overview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export class SparqlOverview {
134134
<p style="opacity: 60%; margin: 1.5em 0;">
135135
💡 <code>shift + left click</code> to select multiple nodes.
136136
</p>
137-
<button id="overview-clear-cache" title="Clear and update the endpoints metadata stored in the cache">
138-
Clear cache
137+
<button id="overview-clear-cache" title="Refresh and update the endpoints metadata stored in the cache">
138+
Refresh cache
139139
</button>
140140
<button id="overview-close-info">Close</button>
141141
</dialog>

0 commit comments

Comments
 (0)