Skip to content

Commit

Permalink
Merge pull request #4178 from nboisteault/fix-hideGroupCheckbox
Browse files Browse the repository at this point in the history
Fix hideGroupCheckbox
  • Loading branch information
nboisteault authored Feb 8, 2024
2 parents 09bb90a + 8dd86d2 commit dc74f2a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion assets/src/components/Treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export default class Treeview extends HTMLElement {
? html`<div class="loading ${item.loadStatus === MapLayerLoadStatus.Loading ? 'spinner' : ''}"></div>`
: ''
}
<input type="checkbox" class="${layerTreeGroupState.mutuallyExclusive ? 'rounded-checkbox' : ''}" id="node-${item.name}" .checked=${item.checked} @click=${() => item.checked = !item.checked} >
${item.type === 'group' && mainLizmap.initialConfig.options.hideGroupCheckbox
? ''
: html`<input type="checkbox" class="${layerTreeGroupState.mutuallyExclusive ? 'rounded-checkbox' : ''}" id="node-${item.name}" .checked=${item.checked} @click=${() => item.checked = !item.checked} >`
}
<div class="node ${item.isFiltered ? 'filtered' : ''}">
${item.type === 'layer'
? html`<img class="legend" src="${item.icon}">`
Expand Down
10 changes: 10 additions & 0 deletions assets/src/modules/config/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const optionalProperties = {
'fixed_scale_overview_map': {type: 'boolean', default: true},
'use_native_zoom_levels': {type: 'boolean', nullable: true, default: null},
'hide_numeric_scale_value': {type: 'boolean', default: false},
'hideGroupCheckbox': { type: 'boolean', nullable: true, default: null },
};

/**
Expand Down Expand Up @@ -58,6 +59,7 @@ export class OptionsConfig extends BaseObjectConfig {
* @param {Boolean} [cfg.fixed_scale_overview_map=true] - does the Overview map have fixed scale ?
* @param {Boolean} [cfg.use_native_zoom_levels=false] - does the map use native zoom levels ?
* @param {Boolean} [cfg.hide_numeric_scale_value=false] - does the scale line hide numeric scale value ?
* @param {Boolean} [cfg.hideGroupCheckbox=false] - are groups checkbox hidden ?
*/
constructor(cfg) {
if (!cfg || typeof cfg !== "object") {
Expand Down Expand Up @@ -222,4 +224,12 @@ export class OptionsConfig extends BaseObjectConfig {
get hide_numeric_scale_value() {
return this._hide_numeric_scale_value;
}

/**
* Hide groups checkbox
* @type {boolean}
*/
get hideGroupCheckbox() {
return this._hideGroupCheckbox;
}
}
16 changes: 16 additions & 0 deletions tests/end2end/playwright/treeview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ test.describe('Treeview', () => {
test('displays "title" defined in Lizmap plugin', async ({ page }) => {
await expect(page.getByTestId('tramway_lines').locator('label')).toHaveText('Tramway lines');
});
});

test.describe('Treeview mocked with "Hide checkboxes for groups" option', () => {
test('"Hide checkboxes for groups" option', async ({ page }) => {
await page.route('**/service/getProjectConfig*', async route => {
const response = await route.fetch();
const json = await response.json();
json.options['hideGroupCheckbox'] = 'True';
await route.fulfill({ response, json });
});

const url = '/index.php/view/map/?repository=testsrepository&project=treeview';
await page.goto(url, { waitUntil: 'networkidle' });

await expect(page.locator('lizmap-treeview div.group > input')).toHaveCount(0);
});
});

0 comments on commit dc74f2a

Please sign in to comment.