VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

Panel multi select not hiding correctly #374

Closed craftzneko closed 7 months ago

craftzneko commented 8 months ago

I have an option that should hide other form elements but if the form elements have values in it doesnt hide it the first time

Example, i select software from this dropdown

image

I then switch over to "Filter" search and the form element changes to "Model" from "Software" but the value stays defined in the selection

image

My code to hide the box looks like this and is in the form show if value is true

const select = elements.find((element) => element.id === "Search");

if (select && select.value === 'Software') {
  return true;
}

If i select another "search option" at the top of my form it then correctly clears it and continue to work even if i select "search option software" again

craftzneko commented 8 months ago

@mikhail-vl or @asimonok any ideas on the above i am using the documented example to clear the values but it appears they are not cleared. I have this code in element value changed which should clear certain elements when switching

/**
 * Find Search element
 */
const searchElement = context.panel.elements.find((element) => element.id === "Search");

/**
 * Define mapping of Search options to element IDs that should not be cleared
 */
const elementsToKeep = {
  "Single": ["FetchLimit", "Search", "AssetName"],
  "Filter": ["FetchLimit", "Search", "DeviceModel", "OSBuild"],
  "Software": ["FetchLimit", "Search", "Software"],
  "Custom": ["FetchLimit", "Search"]
};

/**
 * Get array of element IDs that should not be cleared based on the current Search option
 */
const elementIdsToKeep = elementsToKeep[searchElement.value] || [];

/**
 * Update Panel Options
 */
context.panel.onOptionsChange({
  ...context.panel.options,
  elements: context.panel.elements.map((element) => {
    return elementIdsToKeep.includes(element.id) ? element : { ...element, value: "" };
  }),
});
craftzneko commented 8 months ago

So looking at the object mutli select "value" is being cleared but its query lookup so how do i clear that?