Skip to content
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

[question]How to get the query when press run button from the Yasgui #229

Open
Chankami opened this issue Oct 15, 2023 · 0 comments
Open

Comments

@Chankami
Copy link

According to the API documentation, it is possible to retrieve the query value from the editor using the following method:

const queryValue = yasgui.getTab().yasqe.getValue();

However, the challenge lies in needing to call this method each time a user presses the "run" button. The current code snippet only returns the query value during the page load and does not capture it for multiple queries executed by the user.

Is there any alternative approach to achieve this?
current code

import React, { useEffect } from 'react';
import Yasgui from '@triply/yasgui';
import '@triply/yasgui/build/yasgui.min.css';

function YasguiComponent() {
  useEffect(() => {
    const script = document.createElement('script');
    script.src = 'https://unpkg.com/@triply/yasgui/build/yasgui.min.js';
    script.async = true;

    script.onload = () => {
      const yasgui = new Yasgui(document.getElementById('yasgui'), {
        requestConfig: { endpoint: 'http://test/sparql' },
        copyEndpointOnNewTab: false,
      });
      
     // console.log("loooooog"+yasgui.getTab().yasqe.getValue());
      //});
      // Get the element with the class 'yasqe_queryButton'
      var yasqeQueryButton = document.getElementsByClassName(document.getElementById('yasgui').
      getElementsByClassName('yasqe')[0].getElementsByClassName('CodeMirror')
      [0].getElementsByClassName('yasqe_buttons')[0].getElementsByClassName('yasqe_queryButton'));
if (yasqeQueryButton) {
     alert("New ");
  yasqeQueryButton.onclick = null;
  yasqeQueryButton.onclick = (function() {
    console.log("Query"+yasgui.getTab().yasqe.getValue());
   
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant