Skip to content

Commit b616be4

Browse files
committed
Merge branch 'hotfix/INS-782-exportFormat' into develop
2 parents acee897 + 72dd8f2 commit b616be4

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

packages/insomnia-app/app/ui/components/modals/ask-modal.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ interface State {
1414
loading: boolean;
1515
}
1616

17+
interface AskModalOptions {
18+
title?: string;
19+
message?: string;
20+
onDone?: (success: boolean) => Promise<void>;
21+
yesText?: string;
22+
noText?: string;
23+
}
24+
1725
@autoBindMethodsForReact(AUTOBIND_CFG)
1826
class AskModal extends PureComponent<{}, State> {
1927
state: State = {
@@ -26,8 +34,9 @@ class AskModal extends PureComponent<{}, State> {
2634

2735
modal: Modal | null = null;
2836
yesButton: HTMLButtonElement | null = null;
29-
_doneCallback: Function = () => {};
30-
_promiseCallback: Function = () => {};
37+
38+
_doneCallback: AskModalOptions['onDone'];
39+
_promiseCallback: (value: boolean | PromiseLike<boolean>) => void = () => {};
3140

3241
_setModalRef(m: Modal) {
3342
this.modal = m;
@@ -42,19 +51,17 @@ class AskModal extends PureComponent<{}, State> {
4251
loading: true,
4352
});
4453

45-
if (this._doneCallback) {
46-
// Wait for the callback to finish before closing
47-
await this._doneCallback(true);
48-
}
54+
// Wait for the callback to finish before closing
55+
await this._doneCallback?.(true);
4956

5057
this._promiseCallback(true);
5158

5259
this.hide();
5360
}
5461

55-
_handleNo() {
62+
async _handleNo() {
5663
this.hide();
57-
this?._doneCallback(false);
64+
await this._doneCallback?.(false);
5865

5966
this._promiseCallback(false);
6067
}
@@ -63,8 +70,7 @@ class AskModal extends PureComponent<{}, State> {
6370
this.modal?.hide();
6471
}
6572

66-
show(options: any = {}) {
67-
const { title, message, onDone, yesText, noText } = options;
73+
show({ title, message, onDone, yesText, noText }: AskModalOptions = {}) {
6874
this._doneCallback = onDone;
6975
this.setState({
7076
title: title || 'Confirm',
@@ -74,10 +80,12 @@ class AskModal extends PureComponent<{}, State> {
7480
loading: false,
7581
});
7682
this.modal?.show();
83+
7784
setTimeout(() => {
7885
this.yesButton && this.yesButton.focus();
7986
}, 100);
80-
return new Promise(resolve => {
87+
88+
return new Promise<boolean>(resolve => {
8189
this._promiseCallback = resolve;
8290
});
8391
}

packages/insomnia-app/app/ui/redux/modules/global.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -396,24 +396,27 @@ const showSelectExportTypeModal = ({ onCancel, onDone }: {
396396
onCancel: () => void;
397397
onDone: (selectedFormat: SelectedFormat) => Promise<void>;
398398
}) => {
399+
const options = [
400+
{
401+
name: 'Insomnia v4 (JSON)',
402+
value: VALUE_JSON,
403+
},
404+
{
405+
name: 'Insomnia v4 (YAML)',
406+
value: VALUE_YAML,
407+
},
408+
{
409+
name: 'HAR – HTTP Archive Format',
410+
value: VALUE_HAR,
411+
},
412+
];
399413
const lastFormat = window.localStorage.getItem('insomnia.lastExportFormat');
414+
const defaultValue = options.find(({ value }) => value === lastFormat) ? lastFormat : VALUE_JSON;
415+
400416
showModal(SelectModal, {
401417
title: 'Select Export Type',
402-
value: lastFormat,
403-
options: [
404-
{
405-
name: 'Insomnia v4 (JSON)',
406-
value: VALUE_JSON,
407-
},
408-
{
409-
name: 'Insomnia v4 (YAML)',
410-
value: VALUE_YAML,
411-
},
412-
{
413-
name: 'HAR – HTTP Archive Format',
414-
value: VALUE_HAR,
415-
},
416-
],
418+
value: defaultValue,
419+
options,
417420
message: 'Which format would you like to export as?',
418421
onCancel,
419422
onDone: async (selectedFormat: SelectedFormat) => {

packages/insomnia-app/config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2021.4.0",
2+
"version": "2021.4.1",
33
"name": "insomnia",
44
"executableName": "insomnia",
55
"appId": "com.insomnia.app",

0 commit comments

Comments
 (0)