Skip to content

Commit c5f2ace

Browse files
authored
Add 'all' option and display labels if selected (#172)
Allows for the addition of an `all` option in the products dropdown. - handles URL.replace depending on whether or not `all` is selected - handles URL.replace depending on whether or not `localhost` is the url.host - displays labels when `all` is selected
1 parent 1642ea6 commit c5f2ace

File tree

7 files changed

+105
-44
lines changed

7 files changed

+105
-44
lines changed

preview-src/cheat-sheet.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ This example only applies to Neo4j Enterprise Edition and is marked with the `[.
116116
=== Read queries subsection
117117
118118
119+
[.neo4j-ce.neo4j-ee.aura-dbe.aura-dsp.aura-dbp.aura-dse]
120+
====
121+
[source, cypher, role=noheader]
122+
----
123+
<CYPHER EXAMPLE>
124+
----
125+
126+
[.description]
127+
This example only applies to Neo4j Enterprise Edition and is marked with the `[.neo4j-ee]` role.
128+
====
129+
130+
119131
====
120132
[source, cypher, role=noheader]
121133
----

preview-src/ui-model.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ page:
279279
# additional page attributes indexed by page-slug
280280
pages-data:
281281
cheatsheet-products: &cheatsheet-products
282+
- name: 'All'
283+
class: 'all'
284+
default: true
282285
- name: 'Neo4j Community Edition'
283286
class: 'neo4j-ce'
284287
- name: 'Neo4j Enterprise Edition'
@@ -289,7 +292,6 @@ page:
289292
class: 'aura-dbp'
290293
- name: 'AuraDB Enterprise'
291294
class: 'aura-dbe'
292-
default: true
293295
- name: 'AuraDS Professional'
294296
class: 'aura-dsp'
295297
- name: 'AuraDS Enterprise'

src/css/cheat-sheet.css

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ body.cheat-sheet .nav-panel-versions .dropdown .dropdown-label {
186186
body.cheat-sheet .nav-panel-versions .dropdown .dropdown-styles {
187187
width: 50%;
188188
display: inline-block;
189+
background-color: var(--colors-neutral-10);
189190
}
190191

191192
body.cheat-sheet .selectors > div {
@@ -200,7 +201,7 @@ body.cheat-sheet .selectors > div {
200201
body.cheat-sheet .selectors .dropdown .dropdown-styles {
201202
display: inline-block;
202203
width: 100%;
203-
/* background-color: var(--toolbar-background); */
204+
background-color: var(--colors-neutral-10);
204205
}
205206

206207
/* toc */
@@ -337,6 +338,10 @@ body.cheat-sheet .sect1 {
337338
flex-wrap: wrap;
338339
}
339340

341+
body.cheat-sheet .sect1 > .sectionbody {
342+
margin-top: 0.75rem;
343+
}
344+
340345
body.cheat-sheet .sect2 {
341346
display: flex;
342347
flex-direction: row;
@@ -401,7 +406,7 @@ body.cheat-sheet .exampleblock > .content > div {
401406

402407
body.cheat-sheet .exampleblock > .content > div.labels {
403408
flex: 0 0 100%;
404-
justify-content: flex-start;
409+
justify-content: flex-end;
405410
padding-bottom: 0;
406411
padding-top: 0;
407412
gap: 0.25rem;
@@ -411,11 +416,6 @@ body.cheat-sheet .exampleblock > .content > div.labels span.label {
411416
margin-top: 1rem;
412417
}
413418

414-
body.cheat-sheet div.labels span.group--products,
415-
body.cheat-sheet div.page-labels span.group--products {
416-
display: none;
417-
}
418-
419419
body.cheat-sheet .exampleblock > .content > div.extra {
420420
flex-grow: 2;
421421
border-top: none;
@@ -433,7 +433,7 @@ body.cheat-sheet .page-labels {
433433
/* flex-grow: 1; */
434434
/* flex-direction: row-reverse; */
435435
margin: 0;
436-
padding: 0;
436+
padding: 1rem 0.5rem;
437437
align-items: center;
438438
gap: 0.25rem;
439439
/* border-bottom: 1px solid rgba(var(--colors-neutral-20)); */
@@ -445,11 +445,12 @@ body.cheat-sheet .sect1 > h2 {
445445

446446
body.cheat-sheet .sect1 > .page-labels {
447447
padding-right: 0.5rem;
448+
margin: 0 0 0 auto;
448449
}
449450

450-
body.cheat-sheet .page-labels:first-of-type {
451+
/* body.cheat-sheet .page-labels:first-of-type {
451452
margin: 0 0 0 auto;
452-
}
453+
} */
453454

454455
body.cheat-sheet .page-labels p {
455456
flex-direction: row;
@@ -504,6 +505,10 @@ body.cheat-sheet span.label.hidden,
504505
padding: 0;
505506
}
506507

508+
body.cheat-sheet .article h3:not(.discrete) {
509+
flex: auto;
510+
}
511+
507512
body.cheat-sheet .toc-menu-placeholder ul {
508513
display: flex;
509514
flex-wrap: wrap;
@@ -540,26 +545,37 @@ body.cheat-sheet span.label.hidden,
540545
margin: 0 0.5rem;
541546
} */
542547

548+
body.cheat-sheet .sect1 > .page-labels {
549+
justify-content: flex-start;
550+
margin: 0;
551+
}
552+
543553
body.cheat-sheet .sect2 {
544-
background: none;
554+
/* background: none; */
545555
padding: 0;
556+
border: 1px solid rgba(var(--colors-neutral-30));
557+
}
558+
559+
body.cheat-sheet .sect2 > div.exampleblock:first-of-type {
560+
border: none;
546561
}
547562

548563
body.cheat-sheet h3:not(.discrete) {
549-
background: rgba(var(--colors-neutral-20));
550-
margin: 0 0.5rem 0 0.5rem;
564+
/* background: rgba(var(--colors-neutral-20)); */
565+
/* margin: 0 0.5rem 0 0.5rem; */
566+
padding: 1rem;
551567
flex-grow: 1;
552-
border: 1px solid rgba(var(--colors-neutral-30));
568+
/* border: 1px solid rgba(var(--colors-neutral-30)); */
553569
/* border-right: none; */
554570
}
555571

556572
body.cheat-sheet .sect2 > div {
557573
flex: 0 0 80%;
558574
flex-grow: 1;
559-
padding: 0.5rem;
575+
/* padding: 0.5rem; */
560576
margin: 0 0.5rem;
561-
background-color: rgba(var(--colors-neutral-20));
562-
border: 1px solid rgba(var(--colors-neutral-70));
577+
/* background-color: rgba(var(--colors-neutral-20)); */
578+
/* border: 1px solid rgba(var(--colors-neutral-70)); */
563579
border-radius: 0;
564580
}
565581

@@ -578,8 +594,11 @@ body.cheat-sheet span.label.hidden,
578594
}
579595

580596
body.cheat-sheet .sect2 > div.page-labels {
597+
/* background: rgba(var(--colors-neutral-20)); */
581598
border-left: none;
582-
margin-left: -0.5rem;
599+
margin-left: 0;
600+
padding: 1rem;
601+
/* flex-grow: 1; */
583602
}
584603

585604
body.cheat-sheet .sect2 > div.listingblock {

src/css/labels.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ span.label--beta {
174174

175175
span.label--na,
176176
span.label--no,
177+
span.label.not-available,
177178
span.label--removed {
178179
background: var(--warning-color);
179180
color: var(--warning-background-color);

src/js/50-cheat-sheet-toggle.js

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const optionMap = [...selectorOptions].map((o) => ({
77
text: o.dataset.label,
88
class: o.dataset.class,
99
labelType: o.dataset.labelType,
10+
default: o.dataset.defaultValue,
1011
labelOnly: o.hidden,
1112
selected: o.selected,
1213
inScope: true,
@@ -23,7 +24,9 @@ const prodMatrix = {
2324
'neo4j-enterprise': 'neo4j-ee',
2425
}
2526

26-
const defaultProd = 'auradb-enterprise'
27+
// get the default product from optionMap
28+
const defaultProdArray = optionMap.find((prod) => prod.default === 'true')
29+
const defaultProd = defaultProdArray ? defaultProdArray.value : optionMap[0].value
2730

2831
const defaultClasses = ['exampleblock', 'sect2', 'sect1']
2932

@@ -55,7 +58,7 @@ document.addEventListener('DOMContentLoaded', function () {
5558
if (labelShow) {
5659
labelShow.addEventListener('click', function (c) {
5760
c.stopPropagation()
58-
toggleLabels(c)
61+
toggleLabels(c.target.checked)
5962
})
6063
}
6164

@@ -79,7 +82,7 @@ document.addEventListener('DOMContentLoaded', function () {
7982
// console.log(`classes on the element: ${elClasses}`)
8083

8184
// get an array of classes that match the select options
82-
const labelsToAdd = optionNames.filter(function (obj) {
85+
let labelsToAdd = optionNames.filter(function (obj) {
8386
return elClasses.indexOf(obj) !== -1
8487
}).sort()
8588

@@ -100,17 +103,27 @@ document.addEventListener('DOMContentLoaded', function () {
100103
return
101104
}
102105

106+
const allLabels = Object.values(prodMatrix)
107+
let availableOn = true
108+
const difference = allLabels.filter((l) => !labelsToAdd.includes(l))
109+
if (difference && difference.length <= 2) {
110+
labelsToAdd = difference
111+
availableOn = false
112+
}
113+
103114
if (labelsToAdd && labelsToAdd.length > 0) {
104115
labelsToAdd.forEach((label) => {
105-
addLabel(el, label)
116+
if (label !== 'all') {
117+
addLabel(el, label, availableOn)
118+
}
106119
})
107120
}
108121
})
109122

110123
// if we've removed elements we need to clean the toc by removing entries for those elements
111124
cleanToc()
112125

113-
function addLabel (el, match) {
126+
function addLabel (el, match, availableOn) {
114127
const div = createElement('div', 'paragraph')
115128
let labelType = 'labels'
116129

@@ -133,8 +146,11 @@ document.addEventListener('DOMContentLoaded', function () {
133146
const p = createElement('p')
134147
const span = createElement('span', `label label--${match} group--${group}`)
135148

136-
const text = getProductFromOptionMap(match)
137-
149+
let text = getProductFromOptionMap(match)
150+
if (!availableOn) {
151+
text = 'Not available on ' + text
152+
span.classList.add('not-available')
153+
}
138154
span.textContent = text
139155
p.appendChild(span)
140156

@@ -174,17 +190,25 @@ document.addEventListener('DOMContentLoaded', function () {
174190
prodSelector.addEventListener('change', function (e) {
175191
e.stopPropagation()
176192

193+
// if localhost
194+
if (curURL.host.indexOf('localhost') !== -1) {
195+
setVisibility(hiddenOptionNames, e.target.value === 'all')
196+
return
197+
}
198+
199+
const currentProd = Object.keys(prodMatrix).find((key) => prodMatrix[key] === e.target.dataset.current)
200+
const newProd = Object.keys(prodMatrix).find((key) => prodMatrix[key] === e.target.value)
201+
const re = new RegExp(`/${currentProd}/`)
202+
let newURL
203+
177204
// if we're using a proxied path, just load the new url
178205
if (selectionFromPath) {
179-
// get the new url
180-
const currentProd = Object.keys(prodMatrix).find((key) => prodMatrix[key] === e.target.dataset.current)
181-
const newProd = Object.keys(prodMatrix).find((key) => prodMatrix[key] === e.target.value)
182-
const newURL = curURL.href.replace(currentProd, newProd)
183-
document.location.replace(newURL)
206+
newURL = newProd ? curURL.href.replace(re, `/${newProd}/`) : curURL.href.replace(re, '')
184207
} else {
185-
// reset everything
186-
setVisibility(hiddenOptionNames)
208+
newURL = curURL.href.split('#')[0].concat(newProd).concat(curURL.hash)
187209
}
210+
211+
if (newURL) document.location.replace(newURL)
188212
})
189213

190214
var versionSelector = document.querySelector('body.cheat-sheet .version-selector')
@@ -211,7 +235,7 @@ document.addEventListener('DOMContentLoaded', function () {
211235
})
212236
}
213237

214-
setVisibility(hiddenOptionNames)
238+
setVisibility(hiddenOptionNames, prodSelector.dataset.current === 'all')
215239

216240
const matchTo = parseFloat(document.querySelector('.nav-container .selectors').getBoundingClientRect().height)
217241
const firstSection = document.querySelector('article h2')
@@ -226,19 +250,22 @@ document.addEventListener('DOMContentLoaded', function () {
226250
})
227251
})
228252

229-
function setVisibility (hiddenOptionNames) {
253+
function setVisibility (hiddenOptionNames, showLabels = false) {
230254
// reset everything
231-
clearClass('hidden')
232-
clearClass('hide-this')
233-
clearClass('selectors-match')
255+
clearClasses(['hidden', 'hide-this', 'selectors-match'])
256+
// clearClass('hide-this')
257+
// clearClass('selectors-match')
234258
selectorMatch(hiddenOptionNames)
235259
hideTocEntries()
260+
toggleLabels(showLabels)
236261
document.querySelector('body.cheat-sheet').style.opacity = '1'
237262
}
238263

239-
function clearClass (cl) {
240-
document.querySelectorAll(`.toc-menu .${cl}, .content .sect1.${cl}, .content .sect2.${cl}, .content .exampleblock.${cl}`).forEach((el) => {
241-
el.classList.remove(cl)
264+
function clearClasses (cl) {
265+
cl.forEach((c) => {
266+
document.querySelectorAll(`.toc-menu .${c}, .content .sect1.${c}, .content .sect2.${c}, .content .exampleblock.${c}`).forEach((el) => {
267+
el.classList.remove(c)
268+
})
242269
})
243270
}
244271

@@ -459,7 +486,7 @@ function removeDefaultClasses (c) {
459486

460487
function toggleLabels (l) {
461488
document.querySelectorAll('span.group--products').forEach((div) => {
462-
if (l.target.checked) {
489+
if (l) {
463490
div.style.display = 'flex'
464491
} else {
465492
div.style.display = 'none'

src/partials/footer-scripts.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{#if (or (eq @root.page.layout 'training-certification') (eq @root.page.layout 'training-enrollment') (eq @root.page.layout 'training'))}}
99
<script src="//go.neo4j.com/js/forms2/js/forms2.min.js"></script>
1010
{{/if}}
11-
{{#if (and (eq @root.page.attributes.theme "cheat-sheet") (not (eq @root.site.url "http://localhost:5252")))}}
11+
{{#if (and (eq @root.page.attributes.theme "cheat-sheet") @root.page.attributes.publish)}}
1212
<script src="{{{@root.site.path}}}{{{@root.site.ui.url}}}/js/vendor/auth0.js"></script>
1313

1414
<script src="{{{@root.site.path}}}{{{@root.site.ui.url}}}/js/site.js"></script>

src/partials/nav-selectors.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{{!-- <option value="all" data-label="all" data-class="all" data-label-type="products">All</option> --}}
4545
{{#each page.attributes.cheatsheet-products}}
4646
{{#if this.default}}
47-
<option value="{{this.class}}" data-label="{{#with (or this.label this.name) }}{{{this}}}{{/with}}" data-class="{{this.class}}" data-label-type="products" selected>{{this.name}}</option>
47+
<option value="{{this.class}}" data-label="{{#with (or this.label this.name) }}{{{this}}}{{/with}}" data-class="{{this.class}}" data-label-type="products" data-default-value="true" selected>{{this.name}}</option>
4848
{{else}}
4949
<option value="{{this.class}}" data-label="{{#with (or this.label this.name) }}{{{this}}}{{/with}}" data-class="{{this.class}}" data-label-type="products" {{#if this.label-only }}hidden{{/if}}>{{this.name}}</option>
5050
{{/if}}

0 commit comments

Comments
 (0)