Skip to content

Commit

Permalink
fix(bulk): gdrive selection broken due to recent dom change (#725)
Browse files Browse the repository at this point in the history
* fix(bulk): gdrive selection broken due to recent dom change
* fix: Allow local sourcing of urls during dev. (#717)
* chore: localisation fix for Help steps and topics (#718)

---------

Co-authored-by: Bryan Stopp <[email protected]>
Co-authored-by: Astha Bhargava <[email protected]>
  • Loading branch information
3 people authored May 2, 2024
1 parent dc5266a commit ea4d54b
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function toggle(id) {
function getHelpLanguage() {
const uLang = chrome.i18n.getUILanguage();
const lang = LANGS.find((l) => uLang.replace('-', '_') === l
|| l.startsWith(uLang.split('_')[0])) || LANGS[0];
|| l.startsWith(uLang.split(/[-_]/)[0])) || LANGS[0];
return lang.replace('_', '-').toLowerCase();
}

Expand Down
43 changes: 34 additions & 9 deletions src/extension/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ import sampleRUM from './rum.js';
// omit docx extension on sharepoint
ext = '';
}
if (type === 'xlsx' || type.includes('vnd.google-apps.spreadsheet')) {
if (type === 'xlsx' || type === 'spreadsheet') {
// use json extension for spreadsheets
ext = '.json';
}
Expand Down Expand Up @@ -1666,12 +1666,33 @@ import sampleRUM from './rum.js';
} else {
// gdrive
return [...document.querySelectorAll('#drive_main_page [role="row"][aria-selected="true"]')]
.filter((row) => row.querySelector(':scope img'))
.map((row) => ({
type: new URL(row.querySelector('div > img').getAttribute('src'), sk.location.href).pathname.split('/').slice(-2).join('/'),
path: row.querySelector(':scope > div > div:nth-of-type(2)').textContent.trim() // list layout
|| row.querySelector(':scope > div > div > div:nth-of-type(4)').textContent.trim(), // grid layout
}));
// extract file name and type
.map((row) => {
const typeHint = (row.querySelector(':scope div[role="gridcell"] > div:nth-child(2) > div > div[data-tooltip]') // list layout
|| row.querySelector(':scope div[role="gridcell"]'))?.getAttribute('aria-label'); // grid layout
let type = 'unknown';
if (typeHint) {
if (typeHint.includes('Google Drive')) {
type = 'folder';
} else if (typeHint.includes('Google Docs')) {
type = 'document';
} else if (typeHint.includes('Google Sheets')) {
type = 'spreadsheet';
} else if (['Image', 'Video', 'PDF']
.find((hint) => typeHint.includes(hint))) {
type = 'media';
}
}
const path = row.querySelector(':scope > div > div:nth-of-type(2)')?.textContent.trim() // list layout
|| (row.querySelector(':scope > div > div > div:nth-of-type(4)') // grid layout (file)
|| row.querySelector(':scope div[role="gridcell"] > div > div:nth-child(4) > div'))?.textContent.trim(); // grid layout (folder)
return {
type,
path,
};
})
// exclude folders and emtpy paths
.filter(({ type, path }) => type !== 'folder' && path);
}
};

Expand Down Expand Up @@ -2125,7 +2146,11 @@ import sampleRUM from './rum.js';
* @param {Sidekick} sk The sidekick
*/
function addCustomPlugins(sk) {
const { location, config: { lang, plugins, innerHost } = {} } = sk;
const {
location, config: {
lang, plugins, innerHost, devMode, devUrl,
} = {},
} = sk;
if (plugins && Array.isArray(plugins)) {
plugins.forEach((cfg, i) => {
if (typeof (cfg.button && cfg.button.action) === 'function'
Expand Down Expand Up @@ -2185,7 +2210,7 @@ import sampleRUM from './rum.js';
text: (titleI18n && titleI18n[lang]) || title || '',
action: () => {
if (url) {
const target = url.startsWith('/') ? new URL(url, `https://${innerHost}/`) : new URL(url);
const target = devMode ? new URL(url, devUrl) : new URL(url, `https://${innerHost}/`);
if (passConfig) {
target.searchParams.append('ref', sk.config.ref);
target.searchParams.append('repo', sk.config.repo);
Expand Down
25 changes: 12 additions & 13 deletions test/fixtures/admin-gdrive-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<body>
<div id="drive_main_page">
<div id="folder" role="row" aria-selected="true">
<div>
<div role="gridcell" aria-label="folder Google Drive Folder">
<div>
<div></div>
<div></div>
<div></div>
<div>folder</div>
<div>
<div>folder</div>
</div>
</div>
<div></div>
</div>
</div>
<div id="file-pdf" role="row" aria-selected="true">
<img src="./icons/icon.svg">
<div>
<div role="gridcell" aria-label="file.pdf PDF More info (Option + →)">
<div>
<div></div>
<div></div>
Expand All @@ -28,8 +28,7 @@
</div>
</div>
<div id="file-gdoc" role="row" aria-selected="true">
<img src="./icons/application/vnd.google-apps.document.svg">
<div>
<div role="gridcell" aria-label="document Google Docs More info (Option + →)">
<div>
<div></div>
<div></div>
Expand All @@ -40,8 +39,8 @@
</div>
</div>
<div id="file-gsheet" role="row" aria-selected="false">
<img src="./icons/application/vnd.google-apps.spreadsheet.svg">
<div>
<div role="gridcell" aria-label="spreadsheet Google Sheets More info (Option + →)">
<div>
<div></div>
<div></div>
<div></div>
Expand All @@ -51,8 +50,8 @@
</div>
</div>
<div id="file-word" role="row" aria-selected="false">
<img src="./icons/icon.svg">
<div>
<div role="gridcell" aria-label="document.docx Word More info (Option + →)">
<div>
<div></div>
<div></div>
<div></div>
Expand All @@ -61,9 +60,9 @@
<div></div>
</div>
</div>
</div>
<div id="file-excel" role="row" aria-selected="false">
<img src="./icons/icon.svg">
<div>
<div role="gridcell" aria-label="spreadsheet.xlsx. Excel More info (Option + →)">
<div>
<div></div>
<div></div>
Expand Down
83 changes: 56 additions & 27 deletions test/fixtures/admin-gdrive.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,80 @@
<body>
<div id="drive_main_page">
<div class="folder" id="folder" role="row" aria-selected="true">
<div>
<div></div>
<div>folder</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="Google Drive Folder: folder" aria-label="Google Drive Folder: folder">folder</div>
</div>
</div>
</div>
</div>
<div class="file" id="file-pdf" role="row" aria-selected="true">
<img src="./icons/icon.svg">
<div>
<div></div>
<div>file.pdf</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="PDF: file.pdf" aria-label="PDF: file.pdf">file.pdf</div>
</div>
</div>
</div>
</div>
<div class="file" id="file-gdoc" role="row" aria-selected="true">
<img src="./icons/application/vnd.google-apps.document.svg">
<div>
<div></div>
<div>document</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="Google Docs: document" aria-label="Google Docs: document">document</div>
</div>
</div>
</div>
</div>
<div class="file" id="file-gsheet" role="row" aria-selected="false">
<img src="./icons/application/vnd.google-apps.spreadsheet.svg">
<div>
<div></div>
<div>spreadsheet</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="Google Sheets: spreadsheet" aria-label="Google Sheets: spreadsheet">spreadsheet</div>
</div>
</div>
</div>
</div>
<div id="file-word" role="row" aria-selected="false">
<img src="./icons/icon.svg">
<div>
<div></div>
<div>document.docx</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="Word: document.docx" aria-label="Word: document.docx">document.docx</div>
</div>
</div>
</div>
</div>
<div id="file-excel" role="row" aria-selected="false">
<img src="./icons/icon.svg">
<div>
<div></div>
<div>spreadsheet.xlsx</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="Excel: spreadsheet.xlsx" aria-label="Excel: spreadsheet.xlsx">spreadsheet.xlsx</div>
</div>
</div>
</div>
</div>
<div id="file-illegal" role="row" aria-selected="false">
<img src="./icons/icon.svg">
<div>
<div></div>
<div>foo/../bar</div>
<div role="gridcell">
<div>
</div>
<div>
<div>
<div data-tooltip="Google Docs: foo/../bar" aria-label="Google Docs: foo/../bar">foo/../bar</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
33 changes: 33 additions & 0 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,39 @@ describe('Test sidekick', () => {
assert.ok(configLoaded.startsWith('http://localhost:3000/'), 'Did not load project config from development environment');
}).timeout(IT_DEFAULT_TIMEOUT);

it('Loads relative path from devUrl when in devMode', async () => {
const setup = new Setup('blog');
nock.sidekick(setup);
nock.admin(setup);
nock('http://localhost:3000')
.get(/.*/)
.optionally()
.reply(200, 'some content...');

const test = new SidekickTest({
browser,
page,
loadModule,
plugin: 'bar',
pluginSleep: 1000,
sidekickConfig: {
owner: 'adobe',
repo: 'blog',
ref: 'main',
devMode: true,
plugins: [{
id: 'bar',
title: 'Bar',
url: '/path/to/relative/plugin',
}],
},
});
const {
popupOpened,
} = await test.run();
assert.ok(popupOpened === 'http://localhost:3000/path/to/relative/plugin', 'Did not open plugin URL');
}).timeout(IT_DEFAULT_TIMEOUT);

it('Replaces plugin', async () => {
const setup = new Setup('blog');
nock.sidekick(setup);
Expand Down

0 comments on commit ea4d54b

Please sign in to comment.