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

Save current variable and username together with text input with data manipulation panel #572

Open
FRA2EI opened this issue Jan 10, 2025 · 1 comment
Assignees

Comments

@FRA2EI
Copy link

FRA2EI commented Jan 10, 2025

Hi VokovLabs Team,

I would like to check if I can achieve the following with the data manipulation plugin before I start working on it.

I want to add a text box where comments on the currently loaded dashboard can be submitted. Together with the entered text I also want to submit a variable that is currently selected and information of the user currently logged in and providing the comment. (without her/him entering the mail adress, because I'm scared of typos).

Would that be possible?

@vitPinchuk
Copy link
Contributor

@FRA2EI Thank you for your question

If I understand the idea correctly, you need to add to the payload some data that does not need to be entered through form elements, such as the value of the selected variable and some user data.

You can use variable syntax ('${var}') in the code editor to get variable value and some user info through global variable syntax ('${__user.login}'

global-variables

Here are some examples:

code example to create payload

const payload = {};

/**
 * console.log for example
 */
console.log('create payload user.email:', '${__user.email}')
console.log('create payload user.id:', '${__user.id}')
console.log('create payload user.login:', '${__user.login}')
console.log('create payload org.name:', '${__org.name}')
console.log('create payload Var variable:', '${var}')

context.panel.elements.forEach((element) => {
  if (!element.value) {
    return;
  }

  payload[element.id] = element.value;
})

/**
 * Add fields
 */
payload.userName = '${__user.login}'
payload.email = '${__user.email}'
payload.variable = '${var}'

console.log('payload: ', payload)

/**
 * return payload
 */
return payload;

Console:
image

Network:
image

SQL example

create payload code:

const payload = {};

context.panel.elements.forEach((element) => {
  if (!element.value) {
    return;
  }

  payload[element.id] = element.value;
})

payload.email = '${__user.email}'

console.log('payload -> ', payload)

/**
 * Data Source payload
 */
return payload;

Query Editor:

update
  configuration
set
  min = ${payload.min},
  max = ${payload.max},
  speed = ${payload.speed},
  email = ${payload.email},
where
  name = '$device'

The result:
image

Let me know if this is a good fit for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants