Skip to content

Instantly share code, notes, and snippets.

@steffensbola
Created August 21, 2024 13:18
Show Gist options
  • Select an option

  • Save steffensbola/413cf3e5315a01c85eabc7f7ddee8c27 to your computer and use it in GitHub Desktop.

Select an option

Save steffensbola/413cf3e5315a01c85eabc7f7ddee8c27 to your computer and use it in GitHub Desktop.
Converts LaunchDarkly values in rules to str
/*
When you paste numeric values to https://app.launchdarkly.com/ `Rules` it will automatically parse them to numbers, even if the field type is string.
This clicks every chip in the flag configuration page to switch from int to str.
Must be run from browser console.
Credits: B Roldao
*/
function triggerReactEventOnSpansWithNum() {
const spans = document.querySelectorAll('span.Chip.Chip--default.Chip--subtle.SelectAttributeValue-type.SelectAttributeValue-type--number');
spans.forEach(span => {
if (span.textContent.trim() === 'num') {
const reactFiber = Object.keys(span).find(key => key.startsWith('__reactFiber'));
if (reactFiber) {
const fiberNode = span[reactFiber];
const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
fiberNode.stateNode.dispatchEvent(event);
}
}
});
}
triggerReactEventOnSpansWithNum();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment