From ef840cd5160c7899808fc39f39862e1062720487 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Thu, 1 Jul 2021 15:52:35 -0400 Subject: [PATCH 1/7] hotfix - INS-782 --- .../app/ui/redux/modules/global.tsx | 40 ++++++++++++------- packages/insomnia-app/package-lock.json | 13 ++++++ packages/insomnia-app/package.json | 1 + 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/packages/insomnia-app/app/ui/redux/modules/global.tsx b/packages/insomnia-app/app/ui/redux/modules/global.tsx index 98abde49d2..6d4c1cd1f6 100644 --- a/packages/insomnia-app/app/ui/redux/modules/global.tsx +++ b/packages/insomnia-app/app/ui/redux/modules/global.tsx @@ -43,6 +43,7 @@ import { Settings } from '../../../models/settings'; import { GrpcRequest } from '../../../models/grpc-request'; import { Request } from '../../../models/request'; import { Environment } from '../../../models/environment'; +import { unreachableCase } from 'ts-assert-unreachable'; export const LOCALSTORAGE_PREFIX = 'insomnia::meta'; const LOGIN_STATE_CHANGE = 'global/login-state-change'; @@ -489,24 +490,27 @@ export const importUri = ( }; function showSelectExportTypeModal(onCancel: () => void, onDone: (selectedFormat: SelectedFormat) => void) { + const options = [ + { + name: 'Insomnia v4 (JSON)', + value: VALUE_JSON, + }, + { + name: 'Insomnia v4 (YAML)', + value: VALUE_YAML, + }, + { + name: 'HAR – HTTP Archive Format', + value: VALUE_HAR, + }, + ]; const lastFormat = window.localStorage.getItem('insomnia.lastExportFormat'); + const defaultValue = options.map(({ value }) => value).includes(lastFormat) ? lastFormat : VALUE_JSON; + showModal(SelectModal, { title: 'Select Export Type', - value: lastFormat, - options: [ - { - name: 'Insomnia v4 (JSON)', - value: VALUE_JSON, - }, - { - name: 'Insomnia v4 (YAML)', - value: VALUE_YAML, - }, - { - name: 'HAR – HTTP Archive Format', - value: VALUE_HAR, - }, - ], + value: defaultValue, + options, message: 'Which format would you like to export as?', onCancel, onDone: (selectedFormat: SelectedFormat) => { @@ -599,6 +603,9 @@ export const exportWorkspacesToFile = (workspaceId: string | undefined = undefin 'json', ); break; + + default: + unreachableCase(`selected export format "${selectedFormat}" is invalid`); } } catch (err) { showError({ @@ -698,6 +705,9 @@ export const exportRequestsToFile = (requestIds: string[]) => async dispatch => 'json', ); break; + + default: + unreachableCase(`selected export format "${selectedFormat}" is invalid`); } } catch (err) { showError({ diff --git a/packages/insomnia-app/package-lock.json b/packages/insomnia-app/package-lock.json index 6dc750ecba..1ac94b2c77 100644 --- a/packages/insomnia-app/package-lock.json +++ b/packages/insomnia-app/package-lock.json @@ -24462,6 +24462,14 @@ "utf8-byte-length": "^1.0.1" } }, + "ts-assert-unreachable": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/ts-assert-unreachable/-/ts-assert-unreachable-0.0.9.tgz", + "integrity": "sha512-8tpQLahyZSNTSxKS8QPIO0AAxF8VB02tLPNqcMF638gNDOrhr8uGx9SFP1C/Vtbib2Xc/u12hiXnwmqD7pn+2A==", + "requires": { + "ts-tiny-invariant": "0.0.3" + } + }, "ts-dedent": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-1.1.1.tgz", @@ -24587,6 +24595,11 @@ "integrity": "sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==", "dev": true }, + "ts-tiny-invariant": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/ts-tiny-invariant/-/ts-tiny-invariant-0.0.3.tgz", + "integrity": "sha512-EiaBUsUta7PPzVKpvZurcSDgaSkymxwiUc2rhX6Wu30bws2maipT6ihbEY072dU9lz6/FoFWEc6psXdlo0xqtg==" + }, "tsconfig-paths": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", diff --git a/packages/insomnia-app/package.json b/packages/insomnia-app/package.json index ececd49eff..ce045a9866 100644 --- a/packages/insomnia-app/package.json +++ b/packages/insomnia-app/package.json @@ -154,6 +154,7 @@ "styled-components": "^4.4.1", "swagger-ui-react": "^3.24.3", "tough-cookie": "^2.3.1", + "ts-assert-unreachable": "^0.0.9", "url-join": "^4.0.1", "uuid": "^3.0.0", "vkbeautify": "^0.99.1", From 4233f1565cadcab8ba34dfd837c8ed36c8ba2244 Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Fri, 2 Jul 2021 08:06:39 +1200 Subject: [PATCH 2/7] Update packages/insomnia-app/app/ui/redux/modules/global.tsx --- packages/insomnia-app/app/ui/redux/modules/global.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/insomnia-app/app/ui/redux/modules/global.tsx b/packages/insomnia-app/app/ui/redux/modules/global.tsx index 6d4c1cd1f6..21be412909 100644 --- a/packages/insomnia-app/app/ui/redux/modules/global.tsx +++ b/packages/insomnia-app/app/ui/redux/modules/global.tsx @@ -707,7 +707,7 @@ export const exportRequestsToFile = (requestIds: string[]) => async dispatch => break; default: - unreachableCase(`selected export format "${selectedFormat}" is invalid`); + unreachableCase(selectedFormat, `selected export format "${selectedFormat}" is invalid`); } } catch (err) { showError({ From 9b14dc65461947796e1c61b0b25476574f0762bd Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Fri, 2 Jul 2021 08:08:26 +1200 Subject: [PATCH 3/7] bump version --- packages/insomnia-app/config/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/insomnia-app/config/config.json b/packages/insomnia-app/config/config.json index f2074e4a84..4ed72c5a37 100644 --- a/packages/insomnia-app/config/config.json +++ b/packages/insomnia-app/config/config.json @@ -1,5 +1,5 @@ { - "version": "2021.4.0", + "version": "2021.4.1-alpha.0", "name": "insomnia", "executableName": "insomnia", "appId": "com.insomnia.app", From b84bb5d6e7807a5e30ef075e096dce29ff75d083 Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Fri, 2 Jul 2021 08:20:30 +1200 Subject: [PATCH 4/7] Update packages/insomnia-app/app/ui/redux/modules/global.tsx Co-authored-by: Dimitri Mitropoulos --- packages/insomnia-app/app/ui/redux/modules/global.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/insomnia-app/app/ui/redux/modules/global.tsx b/packages/insomnia-app/app/ui/redux/modules/global.tsx index 21be412909..8f26c1b250 100644 --- a/packages/insomnia-app/app/ui/redux/modules/global.tsx +++ b/packages/insomnia-app/app/ui/redux/modules/global.tsx @@ -605,7 +605,7 @@ export const exportWorkspacesToFile = (workspaceId: string | undefined = undefin break; default: - unreachableCase(`selected export format "${selectedFormat}" is invalid`); + unreachableCase(selectedFormat, `selected export format "${selectedFormat}" is invalid`); } } catch (err) { showError({ From 17de9ef556b78f43e54b0f4ed656f8bb6af92fd4 Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Fri, 2 Jul 2021 09:04:06 +1200 Subject: [PATCH 5/7] convert from map to find --- packages/insomnia-app/app/ui/redux/modules/global.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/insomnia-app/app/ui/redux/modules/global.tsx b/packages/insomnia-app/app/ui/redux/modules/global.tsx index 8f26c1b250..f48d1b47f0 100644 --- a/packages/insomnia-app/app/ui/redux/modules/global.tsx +++ b/packages/insomnia-app/app/ui/redux/modules/global.tsx @@ -505,7 +505,7 @@ function showSelectExportTypeModal(onCancel: () => void, onDone: (selectedFormat }, ]; const lastFormat = window.localStorage.getItem('insomnia.lastExportFormat'); - const defaultValue = options.map(({ value }) => value).includes(lastFormat) ? lastFormat : VALUE_JSON; + const defaultValue = options.find(({ value }) => value === lastFormat ) ? lastFormat : VALUE_JSON; showModal(SelectModal, { title: 'Select Export Type', From ff49cb30937f4702e129cab4332bf750bcbd03ef Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Wed, 7 Jul 2021 11:47:54 +1200 Subject: [PATCH 6/7] don't call done callback unless it exists --- .../app/ui/components/modals/ask-modal.tsx | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx b/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx index 60ec29b5f7..4970a86a74 100644 --- a/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx +++ b/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx @@ -14,6 +14,14 @@ interface State { loading: boolean; } +interface AskModalOptions { + title?: string; + message?: string; + onDone?: (success: boolean) => Promise; + yesText?: string; + noText?: string; +} + @autoBindMethodsForReact(AUTOBIND_CFG) class AskModal extends PureComponent<{}, State> { state: State = { @@ -26,8 +34,9 @@ class AskModal extends PureComponent<{}, State> { modal: Modal | null = null; yesButton: HTMLButtonElement | null = null; - _doneCallback: Function = () => {}; - _promiseCallback: Function = () => {}; + + _doneCallback: AskModalOptions['onDone']; + _promiseCallback: (value: boolean | PromiseLike) => void = () => {}; _setModalRef(m: Modal) { this.modal = m; @@ -42,19 +51,17 @@ class AskModal extends PureComponent<{}, State> { loading: true, }); - if (this._doneCallback) { - // Wait for the callback to finish before closing - await this._doneCallback(true); - } + // Wait for the callback to finish before closing + await this._doneCallback?.(true); this._promiseCallback(true); this.hide(); } - _handleNo() { + async _handleNo() { this.hide(); - this?._doneCallback(false); + await this._doneCallback?.(false); this._promiseCallback(false); } @@ -63,8 +70,7 @@ class AskModal extends PureComponent<{}, State> { this.modal?.hide(); } - show(options: any = {}) { - const { title, message, onDone, yesText, noText } = options; + show({ title, message, onDone, yesText, noText }: AskModalOptions = {}) { this._doneCallback = onDone; this.setState({ title: title || 'Confirm', @@ -74,10 +80,12 @@ class AskModal extends PureComponent<{}, State> { loading: false, }); this.modal?.show(); + setTimeout(() => { this.yesButton && this.yesButton.focus(); }, 100); - return new Promise(resolve => { + + return new Promise(resolve => { this._promiseCallback = resolve; }); } From 72dd8f28d7ac7719e2140d982aa291f546312729 Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Wed, 7 Jul 2021 11:48:23 +1200 Subject: [PATCH 7/7] bump version --- packages/insomnia-app/config/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/insomnia-app/config/config.json b/packages/insomnia-app/config/config.json index 4ed72c5a37..5084e9625d 100644 --- a/packages/insomnia-app/config/config.json +++ b/packages/insomnia-app/config/config.json @@ -1,5 +1,5 @@ { - "version": "2021.4.1-alpha.0", + "version": "2021.4.1", "name": "insomnia", "executableName": "insomnia", "appId": "com.insomnia.app",