From f4b53f424c4c88c41e04c1511b3a3599802c482b Mon Sep 17 00:00:00 2001 From: lapardnemihk1099 Date: Wed, 9 Mar 2022 11:34:54 +0530 Subject: [PATCH 1/8] fix: theme switcher shortcut issue --- frappe/public/js/frappe/desk.js | 10 +++++++++- frappe/public/js/frappe/ui/dialog.js | 1 + frappe/public/js/frappe/ui/theme_switcher.js | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index 51ada70948..36df5f450e 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -55,12 +55,20 @@ frappe.Application = class Application { frappe.ui.keys.setup(); + let is_dialog_open = false; frappe.ui.keys.add_shortcut({ shortcut: 'shift+ctrl+g', description: __('Switch Theme'), action: () => { frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); - frappe.theme_switcher.show(); + if (!is_dialog_open) { + frappe.theme_switcher.show(); + is_dialog_open = true; + } + else { + frappe.theme_switcher.hide(); + is_dialog_open = false; + } } }); diff --git a/frappe/public/js/frappe/ui/dialog.js b/frappe/public/js/frappe/ui/dialog.js index 1618db9939..2c0ff0dcf4 100644 --- a/frappe/public/js/frappe/ui/dialog.js +++ b/frappe/public/js/frappe/ui/dialog.js @@ -216,6 +216,7 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup { hide() { this.$wrapper.modal("hide"); this.is_visible = false; + frappe.ui.hide_open_dialog(); } get_close_btn() { diff --git a/frappe/public/js/frappe/ui/theme_switcher.js b/frappe/public/js/frappe/ui/theme_switcher.js index 2c1d93a2ec..1725577079 100644 --- a/frappe/public/js/frappe/ui/theme_switcher.js +++ b/frappe/public/js/frappe/ui/theme_switcher.js @@ -25,6 +25,8 @@ frappe.ui.ThemeSwitcher = class ThemeSwitcher { increment_by = 1; } else if (key === "left") { increment_by = -1; + } else if (e.keyCode === 13) { // keycode 13 is for 'enter' + this.hide(); } else { return; } From 16d84c558576005f2565e54c83fdc5746faced8e Mon Sep 17 00:00:00 2001 From: lapardnemihk1099 Date: Fri, 11 Mar 2022 13:41:12 +0530 Subject: [PATCH 2/8] chore: formatting issue fixed --- frappe/public/js/frappe/desk.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index 36df5f450e..c0fcfeee92 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -64,8 +64,7 @@ frappe.Application = class Application { if (!is_dialog_open) { frappe.theme_switcher.show(); is_dialog_open = true; - } - else { + } else { frappe.theme_switcher.hide(); is_dialog_open = false; } From b0c813ec214af93fdb59e1477b8544d95d0e6d1f Mon Sep 17 00:00:00 2001 From: lapardnemihk1099 Date: Wed, 23 Mar 2022 17:13:34 +0530 Subject: [PATCH 3/8] chore: fixed bad programming --- frappe/public/js/frappe/desk.js | 15 +++++++-------- frappe/public/js/frappe/ui/dialog.js | 1 - frappe/public/js/frappe/ui/theme_switcher.js | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index c0fcfeee92..4f80218c14 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -54,19 +54,18 @@ frappe.Application = class Application { this.setup_copy_doc_listener(); frappe.ui.keys.setup(); - - let is_dialog_open = false; + frappe.ui.keys.add_shortcut({ shortcut: 'shift+ctrl+g', description: __('Switch Theme'), action: () => { - frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); - if (!is_dialog_open) { - frappe.theme_switcher.show(); - is_dialog_open = true; - } else { + if (cur_dialog) { frappe.theme_switcher.hide(); - is_dialog_open = false; + } else { + if (!frappe.theme_switcher) { + frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); + } + frappe.theme_switcher.show(); } } }); diff --git a/frappe/public/js/frappe/ui/dialog.js b/frappe/public/js/frappe/ui/dialog.js index 2c0ff0dcf4..1618db9939 100644 --- a/frappe/public/js/frappe/ui/dialog.js +++ b/frappe/public/js/frappe/ui/dialog.js @@ -216,7 +216,6 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup { hide() { this.$wrapper.modal("hide"); this.is_visible = false; - frappe.ui.hide_open_dialog(); } get_close_btn() { diff --git a/frappe/public/js/frappe/ui/theme_switcher.js b/frappe/public/js/frappe/ui/theme_switcher.js index 1725577079..c2e1094675 100644 --- a/frappe/public/js/frappe/ui/theme_switcher.js +++ b/frappe/public/js/frappe/ui/theme_switcher.js @@ -138,7 +138,7 @@ frappe.ui.ThemeSwitcher = class ThemeSwitcher { } hide() { - this.dialog.hide(); + frappe.ui.hide_open_dialog(); } }; From b8487cd6016248f0c36e9c512a4399eaca4b8857 Mon Sep 17 00:00:00 2001 From: Khimendrapal Solanki <84378369+lapardnemihk1099@users.noreply.github.com> Date: Mon, 28 Mar 2022 17:17:29 +0530 Subject: [PATCH 4/8] chore: properly closing theme-switcher dialog Co-authored-by: Shariq Ansari <30859809+shariquerik@users.noreply.github.com> --- frappe/public/js/frappe/ui/theme_switcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/ui/theme_switcher.js b/frappe/public/js/frappe/ui/theme_switcher.js index c2e1094675..1725577079 100644 --- a/frappe/public/js/frappe/ui/theme_switcher.js +++ b/frappe/public/js/frappe/ui/theme_switcher.js @@ -138,7 +138,7 @@ frappe.ui.ThemeSwitcher = class ThemeSwitcher { } hide() { - frappe.ui.hide_open_dialog(); + this.dialog.hide(); } }; From 34aa1f97b8e70f6761e124c424ed4f88ba41ac0a Mon Sep 17 00:00:00 2001 From: Khimendrapal Solanki <84378369+lapardnemihk1099@users.noreply.github.com> Date: Mon, 28 Mar 2022 17:20:41 +0530 Subject: [PATCH 5/8] chore: fix add_shortcut conditions Co-authored-by: Shariq Ansari <30859809+shariquerik@users.noreply.github.com> --- frappe/public/js/frappe/desk.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index 4f80218c14..c1fc21fe76 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -59,12 +59,10 @@ frappe.Application = class Application { shortcut: 'shift+ctrl+g', description: __('Switch Theme'), action: () => { - if (cur_dialog) { + if (frappe.theme_switcher && frappe.theme_switcher.dialog.is_visible) { frappe.theme_switcher.hide(); } else { - if (!frappe.theme_switcher) { - frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); - } + frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); frappe.theme_switcher.show(); } } From cf0728de725d33786d16a65b43100e339dd9b35c Mon Sep 17 00:00:00 2001 From: lapardnemihk1099 Date: Mon, 28 Mar 2022 17:41:56 +0530 Subject: [PATCH 6/8] chore: fixed linter issue --- frappe/public/js/frappe/desk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index c1fc21fe76..72e8010605 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -54,7 +54,7 @@ frappe.Application = class Application { this.setup_copy_doc_listener(); frappe.ui.keys.setup(); - + frappe.ui.keys.add_shortcut({ shortcut: 'shift+ctrl+g', description: __('Switch Theme'), From 27d226f29546cd91ac653c62ecb6d15860f3d713 Mon Sep 17 00:00:00 2001 From: lapardnemihk1099 Date: Mon, 11 Apr 2022 14:32:14 +0530 Subject: [PATCH 7/8] test: theme switcher dialog shortcut test --- cypress/integration/theme_switcher_dialog.js | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cypress/integration/theme_switcher_dialog.js diff --git a/cypress/integration/theme_switcher_dialog.js b/cypress/integration/theme_switcher_dialog.js new file mode 100644 index 0000000000..7d3c1305ba --- /dev/null +++ b/cypress/integration/theme_switcher_dialog.js @@ -0,0 +1,30 @@ +context('Theme Switcher Shortcut', () => { + before(() => { + cy.login(); + cy.visit('/app'); + }); + beforeEach(() => { + cy.reload(); + }); + it('Check Toggle', () => { + cy.open_theme_dialog('{ctrl+shift+g}'); + cy.get('.modal-backdrop').should('exist'); + cy.get('.theme-grid > div').first().click(); + cy.close_theme('{ctrl+shift+g}'); + cy.get('.modal-backdrop').should('not.exist'); + }); + it('Check Enter', () => { + cy.open_theme_dialog('{ctrl+shift+g}'); + cy.get('.theme-grid > div').first().click(); + cy.close_theme('{enter}'); + cy.get('.modal-backdrop').should('not.exist'); + }); + +}); + +Cypress.Commands.add('open_theme_dialog', (shortcut_keys) => { + cy.get('body').type(shortcut_keys); +}); +Cypress.Commands.add('close_theme', (shortcut_keys) => { + cy.get('.modal-header').type(shortcut_keys); +}); \ No newline at end of file From 5993a8ba57b6098dbb0d1e0c9dbad6d0bdaf3ee8 Mon Sep 17 00:00:00 2001 From: lapardnemihk1099 Date: Mon, 11 Apr 2022 14:45:13 +0530 Subject: [PATCH 8/8] chore: sider issues fixed --- cypress/integration/theme_switcher_dialog.js | 44 ++++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/cypress/integration/theme_switcher_dialog.js b/cypress/integration/theme_switcher_dialog.js index 7d3c1305ba..b4297e5674 100644 --- a/cypress/integration/theme_switcher_dialog.js +++ b/cypress/integration/theme_switcher_dialog.js @@ -1,30 +1,30 @@ context('Theme Switcher Shortcut', () => { - before(() => { - cy.login(); - cy.visit('/app'); - }); - beforeEach(() => { - cy.reload(); - }); - it('Check Toggle', () => { - cy.open_theme_dialog('{ctrl+shift+g}'); - cy.get('.modal-backdrop').should('exist'); - cy.get('.theme-grid > div').first().click(); - cy.close_theme('{ctrl+shift+g}'); - cy.get('.modal-backdrop').should('not.exist'); - }); - it('Check Enter', () => { - cy.open_theme_dialog('{ctrl+shift+g}'); - cy.get('.theme-grid > div').first().click(); - cy.close_theme('{enter}'); - cy.get('.modal-backdrop').should('not.exist'); - }); + before(() => { + cy.login(); + cy.visit('/app'); + }); + beforeEach(() => { + cy.reload(); + }); + it('Check Toggle', () => { + cy.open_theme_dialog('{ctrl+shift+g}'); + cy.get('.modal-backdrop').should('exist'); + cy.get('.theme-grid > div').first().click(); + cy.close_theme('{ctrl+shift+g}'); + cy.get('.modal-backdrop').should('not.exist'); + }); + it('Check Enter', () => { + cy.open_theme_dialog('{ctrl+shift+g}'); + cy.get('.theme-grid > div').first().click(); + cy.close_theme('{enter}'); + cy.get('.modal-backdrop').should('not.exist'); + }); }); Cypress.Commands.add('open_theme_dialog', (shortcut_keys) => { - cy.get('body').type(shortcut_keys); + cy.get('body').type(shortcut_keys); }); Cypress.Commands.add('close_theme', (shortcut_keys) => { - cy.get('.modal-header').type(shortcut_keys); + cy.get('.modal-header').type(shortcut_keys); }); \ No newline at end of file