Skip to content

Commit

Permalink
preferences: improve category headers and leaf
Browse files Browse the repository at this point in the history
Signed-off-by: Lior Frenkel <[email protected]>
  • Loading branch information
Liorlior1 authored and vince-fugnitto committed Sep 22, 2020
1 parent 4739e26 commit 2d86390
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
12 changes: 8 additions & 4 deletions packages/preferences/src/browser/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,17 @@
text-decoration: underline;
}



.theia-settings-container .settings-section-title {
.theia-settings-container .settings-section-category-title {
font-weight: bold;
font-size: var(--theia-ui-font-size3);
padding-left: calc(2 * var(--theia-ui-padding));
}
}

.theia-settings-container .settings-section-subcategory-title {
font-weight: bold;
font-size: var(--theia-ui-font-size2);
padding-left: calc(2 * var(--theia-ui-padding));
}

.theia-settings-container .settings-section>li {
list-style-type: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Container } from 'inversify';
import { PreferenceTreeGenerator } from './preference-tree-generator';
import { PreferenceSchemaProvider } from '@theia/core/lib/browser';
import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
import { Preference } from './preference-types';

disableJSDOM();

Expand All @@ -51,4 +52,38 @@ describe('preference-tree-generator', () => {
expect(preferenceTreeGenerator['split'](testString)).deep.eq(testString.split(splitter));
});

it('PreferenceTreeGenerator.format', () => {
const testString = 'aaaBbbCcc Dddd eee';
expect(preferenceTreeGenerator['formatString'](testString)).eq('Aaa Bbb Ccc Dddd Eee');
});

describe('PreferenceTreeGenerator.createLeafNode', () => {
it('when property constructs of three parts the third part is the leaf', () => {
const property = 'category-name.subcategory.leaf';
const expectedName = 'Leaf';
testLeafName(property, expectedName);
});

it('when property constructs of two parts the second part is the leaf', () => {
const property = 'category-name.leaf';
const expectedName = 'Leaf';
testLeafName(property, expectedName);
});

function testLeafName(property: string, expectedName: string): void {
const preferencesGroups: Preference.Branch[] = [];
const root = preferenceTreeGenerator['createRootNode'](preferencesGroups);
const preferencesGroup = preferenceTreeGenerator['createPreferencesGroup']('group', root);

const expectedSelectableTreeNode = {
id: property,
name: expectedName,
parent: preferencesGroup,
visible: true,
selected: false,
};
expect(preferenceTreeGenerator['createLeafNode'](property, preferencesGroup)).deep.eq(expectedSelectableTreeNode);
}

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export class PreferenceTreeGenerator {
});

protected createLeafNode = (property: string, preferencesGroup: Preference.Branch): SelectableTreeNode => {
const propertySpecifier = this.split(property).slice(1);
const name = propertySpecifier.map(word => word.slice(0, 1).toLocaleUpperCase() + word.slice(1)).join(' ').trim();
const rawLeaf = property.split('.').pop();
const name = this.formatString(rawLeaf!);
return {
id: property,
name,
Expand Down Expand Up @@ -119,4 +119,8 @@ export class PreferenceTreeGenerator {
return split;
}

private formatString(string: string): string {
const specifier = this.split(string);
return specifier.map(word => word.slice(0, 1).toLocaleUpperCase() + word.slice(1)).join(' ').trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ export class PreferencesEditorWidget extends ReactWidget {

protected renderCategory(category: Preference.Branch): React.ReactNode {
const children = category.children.concat(category.leaves).sort((a, b) => this.sort(a.id, b.id));
const isCategory = category.parent?.parent === undefined;
const categoryLevelClass = isCategory ? 'settings-section-category-title' : 'settings-section-subcategory-title';
return category.visible && (
<ul
className="settings-section"
key={`${category.id}-editor`}
id={`${category.id}-editor`}
>
<li className="settings-section-title" data-id={category.id}>{category.name}</li>
<li className={categoryLevelClass} data-id={category.id}>{category.name}</li>
{children.map((preferenceNode: SelectableTreeNode | Preference.Branch) => {
if (Preference.Branch.is(preferenceNode)) {
return this.renderCategory(preferenceNode);
Expand Down

0 comments on commit 2d86390

Please sign in to comment.