Kong / Kong/insomnia

plugin used to set a variable is forgotten

Open
#5,878 1 comment 0 reactions 0 assignees View on GitHub
B-bug S-unverified
Dominant language
TypeScript
Stars
40k
Forks
2.4k
Avg merge
2d 13h
Merged PRs (30d)
61

Description

### Expected Behavior

When using a plugin like DateAdd (I am writing a variant IsoDateTimeAdd without using moment.js, and used the Generate Plugin button), I can create a variable in the environment. The Edit Tag dialog shows up and my IsoDateTimeAdd is in the Function To Perform select box. The live preview shows up nicely.
When I click OK, the environment JSON shows like I defined in the plugin:
![image](https://user-images.githubusercontent.com/126855543/230016811-1ad6476b-82b2-4606-976c-9b081b6f9d24.png)

### Actual Behavior

But when I close the environment modal and open it again, the JSON shows this:
![image](https://user-images.githubusercontent.com/126855543/230016700-20924e01-c3fb-4ff7-8ebb-d2a3c30a8edb.png)

The calling of the plugin just disappears.

### Reproduction Steps

_No response_

### Is there an existing issue for this?

- [X] I have searched the [issue tracker](https://www.github.com/Kong/insomnia/issues) for this problem.

### Additional Information

My (partial) `main.js` file:
```js
function getIsoDateString(y, m, d, h, i, s, z){
let d1 = new Date();
let d2 = new Date(d1.setFullYear(d1.getFullYear() + y));
let d3 = new Date(d2.setMonth(d2.getMonth() + m));
let d4 = new Date(d3.setDate(d3.getDate() + d));
let d5 = new Date(d4.setHours(d4.getHours() + z));
let d6 = new Date(d5.setMinutes(d5.getMinutes() + z));
let d7 = new Date(d6.setSeconds(d6.getSeconds() + z));
let d8 = new Date(d7.setMilliseconds(d7.getMilliseconds() + z));
return d8.toISOString();
}

module.exports.templateTags = [{
name: 'IsoDateTimeAdd',
displayName: 'IsoDateTimeAdd',
description: 'Provides an ISO date/time string with addition to the current date/time.',
args: [
{
displayName: 'Years to add',
description: 'The years to add to the date.',
type: 'number',
defaultValue: 0
},
// ...
{
displayName: 'Milliseconds to add',
description: 'The milliseconds to add to the date.',
type: 'number',
defaultValue: 0
}
],
async run (context, y, m, d, h, i, s, z) {
return getIsoDateString(y, m, d, h, i, s, z);
},
liveDisplayName (context) {
let values = context.map(c => c.value);
return "DateAdd (" + getIsoDateString(...values) + ")";
}
}];
```

Any idea? I must be missing something really simple...

Thanks!

Version: Insomnia 2023.1.0
Build date: 2023-03-09
OS: Windows_NT x64 10.0.22621
Electron: 22.0.0
Node: 16.17.1
V8: 10.8.168.20-electron.0
Architecture: x64

### Insomnia Version

2023.1.0

### What operating system are you using?

Windows

### Operating System Version

Windows 11 Business 22H2

### Installation method

forgot, probably MS Store

### Last Known Working Insomnia version

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the plugin's main.js templateTags definition and trace how the Edit Tag dialog saves its selected function into the environment JSON. Reopen the environment modal to compare the saved value with the value shown immediately after clicking OK. Done means the plugin call remains present after closing and reopening the modal.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
desktop, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.