Skip to content

Commit ffcd615

Browse files
#1143: Fix translations causing nav bug
1 parent 03d9287 commit ffcd615

File tree

5 files changed

+46
-38
lines changed

5 files changed

+46
-38
lines changed

packages/core/patternlab-config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@
7676
"patternExportPreserveDirectoryStructure": true,
7777
"patternExportRaw": false,
7878
"patternTranslations": {
79-
"view-all": "View all {groupName}",
80-
"root-name": "Root"
79+
"ViewAllSubGroup": "View all {sgName}",
80+
"viewAllGroup": "View All",
81+
"viewAllRoot": "All",
82+
"rootName": "Root"
8183
},
8284
"serverOptions": {
8385
"wait": 1000

packages/core/src/lib/object_factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ Pattern.prototype = {
239239
// TODO: verify
240240
return pInfo.patternlab &&
241241
pInfo.patternlab.config.patternTranslations &&
242-
pInfo.patternlab.config.patternTranslations['root-name']
243-
? _.kebabCase(pInfo.patternlab.config.patternTranslations['root-name'])
242+
pInfo.patternlab.config.patternTranslations.rootName
243+
? _.kebabCase(pInfo.patternlab.config.patternTranslations.rootName)
244244
: 'root';
245245
}
246246
},

packages/core/src/lib/ui_builder.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ const ui_builder = function() {
262262
patternState: pattern.patternState,
263263
patternPath: pattern.patternLink,
264264
name: pattern.name,
265+
isDocPattern: false,
265266
order: Number(pattern.order) || 0, // Failsave is someone entered a string
266267
};
267268
}
@@ -284,11 +285,16 @@ const ui_builder = function() {
284285
newSubTypeItem = {
285286
patternPartial:
286287
'viewall-' + pattern.patternGroup + '-' + pattern.patternSubGroup,
287-
patternName: 'View All',
288+
patternName:
289+
patternlab.config.patternTranslations &&
290+
patternlab.config.patternTranslations.viewAllGroup
291+
? patternlab.config.patternTranslations.viewAllGroup
292+
: `View all`,
288293
patternPath: encodeURI(pattern.flatPatternPath + '/index.html'),
289294
patternType: pattern.patternType,
290295
patternSubtype: pattern.patternSubtype,
291296
name: pattern.flatPatternPath,
297+
isDocPattern: true,
292298
order: Number.MAX_SAFE_INTEGER,
293299
};
294300
} else {
@@ -322,14 +328,15 @@ const ui_builder = function() {
322328
patternPartial: `viewall-${pattern.patternGroup}-all`,
323329
patternName:
324330
patternlab.config.patternTranslations &&
325-
patternlab.config.patternTranslations['view-all']
326-
? patternlab.config.patternTranslations['view-all'].replace(
327-
'{groupName}',
331+
patternlab.config.patternTranslations.ViewAllSubGroup
332+
? patternlab.config.patternTranslations.ViewAllSubGroup.replace(
333+
'{sgName}',
328334
_.startCase(pattern.patternGroup)
329335
)
330336
: `View all ${_.startCase(pattern.patternGroup)}`,
331337
patternPath: encodeURI(pattern.patternGroup + '/index.html'),
332338
name: pattern.patternGroup,
339+
isDocPattern: true,
333340
order: Number.MAX_SAFE_INTEGER,
334341
});
335342
} else {

packages/edition-node/patternlab-config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@
7676
"patternExportPreserveDirectoryStructure": true,
7777
"patternExportRaw": false,
7878
"patternTranslations": {
79-
"view-all": "View all {groupName}",
80-
"root-name": "Root"
79+
"ViewAllSubGroup": "View all {sgName}",
80+
"viewAllGroup": "View All",
81+
"viewAllRoot": "All",
82+
"rootName": "Root"
8183
},
8284
"serverOptions": {
8385
"wait": 1000

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ const SubSubList = props => {
1414
const { children, category, elem } = props;
1515
const reorderedChildren = [];
1616

17-
const nonViewAllItems = elem.noViewAll
18-
? children.filter(item => item.patternName !== 'View All')
19-
: children.filter(
20-
item =>
21-
item.patternName !== 'View All' && !item.patternName.includes(' Docs')
22-
);
17+
const nonViewAllItems = children.filter(item => !item.isDocPattern);
2318
const viewAllItems = elem.noViewAll
2419
? []
25-
: children.filter(item => item.patternName === 'View All');
20+
: children.filter(item => item.isDocPattern);
2621

2722
reorderedChildren.push(...viewAllItems, ...nonViewAllItems);
2823

@@ -35,7 +30,7 @@ const SubSubList = props => {
3530
href={`patterns/${patternSubtypeItem.patternPath}`}
3631
className={`pl-c-nav__link pl-c-nav__link--sublink
3732
${
38-
patternSubtypeItem.patternName === 'View All'
33+
patternSubtypeItem.isDocPattern
3934
? 'pl-c-nav__link--overview pl-js-link-overview'
4035
: 'pl-c-nav__link--subsublink'
4136
}
@@ -45,7 +40,7 @@ const SubSubList = props => {
4540
}
4641
data-patternpartial={patternSubtypeItem.patternPartial}
4742
>
48-
{patternSubtypeItem.patternName === 'View All'
43+
{patternSubtypeItem.isDocPattern
4944
? `${category}`
5045
: patternSubtypeItem.patternName}
5146
{patternSubtypeItem.patternState && (
@@ -84,7 +79,7 @@ const SubSubList = props => {
8479
href={`patterns/${patternSubtypeItem.patternPath}`}
8580
className={`pl-c-nav__link pl-c-nav__link--sublink
8681
${
87-
patternSubtypeItem.patternName === 'View All'
82+
patternSubtypeItem.isDocPattern
8883
? 'pl-c-nav__link--overview'
8984
: 'pl-c-nav__link--subsublink'
9085
}
@@ -94,7 +89,7 @@ const SubSubList = props => {
9489
}
9590
data-patternpartial={patternSubtypeItem.patternPartial}
9691
>
97-
{patternSubtypeItem.patternName === 'View All'
92+
{patternSubtypeItem.isDocPattern
9893
? `${category} Overview`
9994
: patternSubtypeItem.patternName}
10095
{patternSubtypeItem.patternState && (
@@ -438,9 +433,7 @@ class Nav extends BaseComponent {
438433
data-patternpartial={patternItem.patternPartial}
439434
tabindex="0"
440435
>
441-
{patternItem.patternName === 'View All'
442-
? patternItem.patternName + ' ' + item.patternTypeUC
443-
: patternItem.patternName}
436+
{patternItem.patternName}
444437
{patternItem.patternState && (
445438
<span
446439
class={`pl-c-pattern-state pl-c-pattern-state--${patternItem.patternState}`}
@@ -459,20 +452,24 @@ class Nav extends BaseComponent {
459452
{/* display the All link if window.ishControlsHide is undefined (for some reason) OR window.ishControls.ishControlsHide doesn't have `views-all` and/or `all` set to true */}
460453
{(window.ishControls === undefined ||
461454
window.ishControls.ishControlsHide === undefined ||
462-
(window.ishControls.ishControlsHide['views-all'] !== true &&
463-
window.ishControls.ishControlsHide.all !== true)) && (
464-
<li class="pl-c-nav__item">
465-
<a
466-
onClick={e => this.handleClick(e, 'all')}
467-
href="styleguide/html/styleguide.html"
468-
class="pl-c-nav__link pl-c-nav__link--pattern"
469-
data-patternpartial="all"
470-
tabindex="0"
471-
>
472-
All
473-
</a>
474-
</li>
475-
)}
455+
(!window.ishControls.ishControlsHide['views-all'] &&
456+
!window.ishControls.ishControlsHide.all)) &&
457+
!this.noViewAll && (
458+
<li class="pl-c-nav__item">
459+
<a
460+
onClick={e => this.handleClick(e, 'all')}
461+
href="styleguide/html/styleguide.html"
462+
class="pl-c-nav__link pl-c-nav__link--pattern"
463+
data-patternpartial="all"
464+
tabindex="0"
465+
>
466+
{window.config.patternTranslations &&
467+
window.config.patternTranslations.viewAllRoot
468+
? window.config.patternTranslations.viewAllRoot
469+
: 'All'}
470+
</a>
471+
</li>
472+
)}
476473
</ol>
477474
);
478475
}

0 commit comments

Comments
 (0)