From 670939858d6865affe05aeee5ef5df04abfb4c5c Mon Sep 17 00:00:00 2001 From: jreyesr Date: Sat, 18 Mar 2023 22:04:22 -0500 Subject: [PATCH] Add config for delay between requests --- CHANGELOG.md | 18 ++++++++++++++++++ README.md | 15 +++++++++++++++ components/BatchDialog.js | 17 +++++++++++++++++ components/DelaySelector.js | 11 +++++++++++ package-lock.json | 5 +++-- package.json | 2 +- 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 components/DelaySelector.js diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cb4bf00 --- /dev/null +++ b/CHANGELOG.md @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index 363e9b5..6f345cf 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/components/BatchDialog.js b/components/BatchDialog.js index 59cf422..b1a3986 100644 --- a/components/BatchDialog.js +++ b/components/BatchDialog.js @@ -10,6 +10,7 @@ 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(""); @@ -17,6 +18,7 @@ export default function BatchDialog({context, request}) { const [csvData, setCsvData] = useState([]); const [outputConfig, setOutputConfig] = useState([]); const [sent, setSent] = useState(0); + const [delay, setDelay] = useState(0); const onFileChosen = (path => { setCsvPath(path); @@ -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.`) @@ -75,6 +82,11 @@ export default function BatchDialog({context, request}) { setOutputConfig(x) } + const onChangeDelay = ({target: {value}}) => { + if(value < 0) return; + setDelay(value) + } + return ( @@ -86,6 +98,11 @@ export default function BatchDialog({context, request}) { ) :

Choose a file above to preview it!

} + + + + + diff --git a/components/DelaySelector.js b/components/DelaySelector.js new file mode 100644 index 0000000..155d0b2 --- /dev/null +++ b/components/DelaySelector.js @@ -0,0 +1,11 @@ +export default function DelaySelector({value, onChange}) { + return +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d4e7d18..149ca24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,13 @@ { "name": "insomnia-plugin-batch-requests", - "version": "0.0.1", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "insomnia-plugin-batch-requests", - "version": "0.0.1", + "version": "1.1.0", + "license": "MIT", "dependencies": { "csv-stringify": "^6.2.4", "csvtojson": "^2.0.10", diff --git a/package.json b/package.json index 24220b2..ddc2d40 100644 --- a/package.json +++ b/package.json @@ -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"