Skip to content

Commit

Permalink
Merge pull request #2 from jreyesr/feat/delay
Browse files Browse the repository at this point in the history
Add config for delay between requests
  • Loading branch information
jreyesr authored Mar 19, 2023
2 parents 5244786 + 6709398 commit 17b7142
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# v1.1.0
**Date:** 2023/03/18

### New features

* Added a configuration option to set a delay between consecutive requests ([#1](https://github.com/jreyesr/insomnia-plugin-batch-requests/issues/1))

# v1.0.1
**Date:** 2023/02/19

Initial version

# v1.0.0
**Date:** 2023/02/18

~~Initial version~~

Pulled from NPM because of missing main file.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ On the plugin dialog (see the image below), you should:
5. Click the `Save` button to write the extracted data back to the CSV file, if you need it.

![A screenshot showing the main plugin UI. From top to bottom, there is a button to load a file, a table showing a preview of the data, a series of fields to specify output data, and a button to run the request multiple times](images/runner_ui.png)

## Development

1. Identify your Insomnia plugin folder. On Ubuntu, it should be `~/.config/Insomnia/plugins`. Alternatively, open Insomnia, select the `Application>Preferences` menu, go to the Plugins tab, then click the `Reveal Plugins Folder` button.
2. On that folder, run `git clone https://github.com/jreyesr/insomnia-plugin-batch-requests`.
3. Run `npm i`.
3. Run `npm run dev`. This will start a dev server that will generate the `dist/main.js` file and keep it updated whenever you change the source files.
4. Open the Insomnia Plugins dialog (see the first step). It should display the plugin, since it's in the correct folder. It's not necessary to manually install it.
5. Create and checkout a new branch.
6. Hackity hack on the source files.
7. Whenever you save a file, the `dist/main.js` file will be updated. To make Insomnia pick up the changes, select the `Tools>Reload plugins` option from the top menus. Alternatively, press `Alt+T`, then release both, then press `R`.
8. Make commit.
9. GOTO 6
10. Update the package version in `package.json`.
11. When done, submit a PR and merge it. The CD should pick it up, compile a package and upload it to NPM.
17 changes: 17 additions & 0 deletions components/BatchDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import FileChooserButton from './FileChooserButton';
import ActionButton from './ActionButton';
import OutputFieldsChooser from './OutputFieldsChooser';
import ProgressBar from './ProgressBar';
import DelaySelector from './DelaySelector';

export default function BatchDialog({context, request}) {
const [csvPath, setCsvPath] = useState("");
const [csvHeaders, setCsvHeaders] = useState([]);
const [csvData, setCsvData] = useState([]);
const [outputConfig, setOutputConfig] = useState([]);
const [sent, setSent] = useState(0);
const [delay, setDelay] = useState(0);

const onFileChosen = (path => {
setCsvPath(path);
Expand All @@ -43,6 +45,11 @@ export default function BatchDialog({context, request}) {
setSent(s => s + 1);
console.debug(response);

// Sleep for a bit
console.debug("sleep started, delay =", delay)
await new Promise(r => setTimeout(r, delay * 1000));
console.debug("sleep ended")

// If we need to extract response data, check that the Content-Type header is sensible, otherwise error out
if(outputConfig.length > 0 && !response.contentType.startsWith("application/json")) {
context.app.alert("Error!", `The response has invalid Content-Type "${response.contentType}", needs "application/json"! Alternatively, delete all Outputs and try again.`)
Expand Down Expand Up @@ -75,6 +82,11 @@ export default function BatchDialog({context, request}) {
setOutputConfig(x)
}

const onChangeDelay = ({target: {value}}) => {
if(value < 0) return;
setDelay(value)
}

return (<React.Fragment>
<FormRow label="Choose CSV">
<FileChooserButton onChange={onFileChosen} extensions={["csv"]}/>
Expand All @@ -86,6 +98,11 @@ export default function BatchDialog({context, request}) {
) : <p>Choose a file above to preview it!</p>}

<OutputFieldsChooser colNames={csvHeaders} onChange={onChangeOutputFields} />

<FormRow label="Run config">
<DelaySelector value={delay} onChange={onChangeDelay}/>
</FormRow>

<FormRow label="Progress">
<ProgressBar bgcolor="#a11" completed={sent * 100 / totalRequests} text={`${sent}/${totalRequests}`} />
</FormRow>
Expand Down
11 changes: 11 additions & 0 deletions components/DelaySelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function DelaySelector({value, onChange}) {
return <label>
Delay in seconds
<input
type="number"
step="0.1"
value={value}
onChange={onChange}
/>
</label>
}
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repository": {
"url": "https://github.com/jreyesr/insomnia-plugin-batch-requests"
},
"version": "1.0.1",
"version": "1.1.0",
"author": {
"name": "jreyesr",
"url": "https://github.com/jreyesr"
Expand Down

0 comments on commit 17b7142

Please sign in to comment.