-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webpack implementation fix for hints not showing (#197)
* initial commit * initial commit * not fixed * hot not fix * basic webpack implementation * implement webpack * implement webpack * added fixes and mobile support * deleated package-lock.json * Delete yarn.lock * adding new lines and deleated public build * Change input to symfony form row * GHA fix * GHA fix * Gha fix build->encore * Fix spec ImageTransformer * Gha fix node version changed to 14.x * scrutinizer node fix * scrutinizer node fix * scrutinizer node fix Co-authored-by: kuba-end <[email protected]> Co-authored-by: Tomasz Grochowski <[email protected]>
- Loading branch information
1 parent
7feed4c
commit 056c771
Showing
44 changed files
with
2,750 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@bitbag/elasticsearch-plugin", | ||
"description": "Elasticsearch plugin for Sylius.", | ||
"repository": "https://github.com/BitBagCommerce/[...].git", | ||
"license": "MIT", | ||
"scripts": { | ||
"dist": "yarn encore production --config-name bitbag-plugin-dist" | ||
}, | ||
"dependencies": { | ||
"node-sass": "7.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import './scss/main.scss' | ||
import './js/' |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import './scss/main.scss' | ||
import './js/' |
133 changes: 133 additions & 0 deletions
133
src/Resources/assets/shop/js/elasticSearchAutocomplete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
export default class ElasticSearchAutocomplete { | ||
constructor( | ||
config = {}, | ||
) { | ||
this.config = config; | ||
this.defaultConfig = { | ||
searchFields: '.searchdiv', | ||
baseAutocompleteVariantUrl: '[data-bb-elastic-url]', | ||
searchInput: '.app-quick-add-code-input', | ||
resultsTarget: '.results', | ||
resultContainerClassesArray: ['result'], | ||
resultImageClass: 'image', | ||
resultContentClass: 'result__content', | ||
resultPriceClass: 'result__price', | ||
resultTitleClass: 'js-title', | ||
resultDescriptionClass: 'result__description', | ||
resultLinkClass: 'result__link', | ||
resultCategoryClass: 'result__category', | ||
resultImageClass: 'result__image', | ||
resultContainerClass: 'result__container', | ||
}; | ||
this.finalConfig = {...this.defaultConfig, ...config}; | ||
this.searchFieldsSelector = document.querySelector(this.finalConfig.searchFields); | ||
} | ||
|
||
init() { | ||
if (this.config && typeof this.config !== 'object') { | ||
throw new Error('BitBag - CreateConfirmationModal - given config is not valid - expected object'); | ||
} | ||
|
||
this._debounce(); | ||
} | ||
|
||
_toggleModalVisibility(elements) { | ||
document.addEventListener('variantsVisible', () => { | ||
document.addEventListener('click', () => { | ||
elements.forEach((element) => { | ||
element.innerHTML = ''; | ||
element.style.display = 'none'; | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
_modalTemplate(item, categoryStyle) { | ||
const result = document.createElement('a'); | ||
result.classList.add(...this.finalConfig.resultContainerClassesArray, 'js-result'); | ||
result.innerHTML = ` | ||
<h3 class=${this.finalConfig.resultCategoryClass} style=${categoryStyle}>${item.taxon_name}</h3> | ||
<a href=${item.slug} class=${this.finalConfig.resultLinkClass}> | ||
<div class=${this.finalConfig.resultContainerClass}> | ||
<img class=${this.finalConfig.resultImageClass} src=${item.image}> | ||
<div class=${this.finalConfig.resultContentClass}> | ||
<div class=${this.finalConfig.resultTitleClass}>${item.name}</div> | ||
<div class=${this.finalConfig.resultPriceClass}>${item.price}</div> | ||
</div> | ||
</div> | ||
</a> | ||
`; | ||
|
||
return result; | ||
} | ||
|
||
_assignElements(entry, data) { | ||
const currentResults = this.searchFieldsSelector.querySelector(this.finalConfig.resultsTarget); | ||
|
||
currentResults.innerHTML = '' | ||
currentResults.style = 'visibility: visible'; | ||
|
||
const allResults = document.querySelectorAll(this.finalConfig.resultsTarget); | ||
|
||
if (data.items.length === 0) { | ||
currentResults.innerHTML = '<center class="result">no matching results</center>'; | ||
} | ||
|
||
data.items = data.items.sort((a,b) => { | ||
if (b.taxon_name < a.taxon_name) return 1; | ||
if (b.taxon_name > a.taxon_name) return -1; | ||
return 0; | ||
}); | ||
|
||
let tempTaxonName; | ||
data.items.forEach((item) => { | ||
|
||
let categoryStyle = "visibility: visible" | ||
if (tempTaxonName == item.taxon_name) { | ||
categoryStyle = "visibility: hidden"; | ||
} | ||
|
||
tempTaxonName = item.taxon_name; | ||
currentResults.appendChild(this._modalTemplate(item, categoryStyle)); | ||
}); | ||
|
||
currentResults.style.display = 'block'; | ||
this._toggleModalVisibility(allResults); | ||
|
||
const customEvent = new CustomEvent('variantsVisible'); | ||
document.dispatchEvent(customEvent); | ||
} | ||
|
||
async _getProducts(entry) { | ||
const variantUrl = document.querySelector(this.finalConfig.baseAutocompleteVariantUrl).dataset.bbElasticUrl; | ||
const url = `${variantUrl}?query=${entry.value}`; | ||
|
||
entry.parentNode.classList.add('loading'); | ||
|
||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
|
||
this._assignElements(entry, data); | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
entry.parentNode.classList.remove('loading'); | ||
} | ||
} | ||
|
||
_debounce() { | ||
const codeInputs = document.querySelectorAll(this.finalConfig.searchInput); | ||
let timeout; | ||
|
||
codeInputs.forEach((input) => { | ||
input.addEventListener('input', () => { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => { | ||
this._getProducts(input); | ||
}, 400); | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './initAutocomleate'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ElasticSearchAutocomplete from './elasticSearchAutocomplete'; | ||
|
||
new ElasticSearchAutocomplete().init(); |
92 changes: 92 additions & 0 deletions
92
src/Resources/assets/shop/scss/elasticSearchAutocomplete.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
.results { | ||
margin-top: 0.5rem; | ||
position: absolute; | ||
left: 50%; | ||
-webkit-transform: translateX(-50%); | ||
transform: translateX(-50%); | ||
min-width: 100%; | ||
width: 600px; | ||
padding: 0 1rem 0 1rem; | ||
background-color: white; | ||
backdrop-filter: blur(1px); | ||
z-index: 16; | ||
box-shadow: 0px 1px 2px 0px #d4d4d5, 0px 0px 0px 1px #d4d4d5; | ||
visibility: hidden; | ||
color: #050428; | ||
max-height: 50vh; | ||
overflow-x: auto; | ||
|
||
@media (max-width: 767px) { | ||
width: 300px; | ||
} | ||
|
||
.result { | ||
padding: 1px; | ||
|
||
&__category { | ||
padding-top: 1rem; | ||
color: #050428; | ||
} | ||
|
||
&__link { | ||
padding-top: 1rem; | ||
|
||
.result__container { | ||
max-height: 400px; | ||
box-shadow: 0px 1px 1px 0px #d4d4d5, 0px 0px 0px 1px #d4d4d5; | ||
color: #050428; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
|
||
.result__image { | ||
max-width: 7rem; | ||
max-height: 7rem; | ||
width: 100%; | ||
padding: 0.5rem; | ||
object-fit: cover; | ||
|
||
@media (max-width: 767px){ | ||
max-width: 6rem; | ||
max-height: 6rem; | ||
} | ||
} | ||
|
||
.result__content { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
font-weight: bold; | ||
padding: 0.5rem 3.7rem 0 0; | ||
|
||
|
||
@media (max-width: 767px) { | ||
flex-direction: column; | ||
justify-content: space-evenly; | ||
text-align: left; | ||
width: 100%; | ||
padding: 1rem; | ||
} | ||
|
||
.result__price { | ||
position: absolute; | ||
right: 1.5rem; | ||
|
||
@media (max-width: 767px) { | ||
position: relative; | ||
right: 0; | ||
} | ||
} | ||
} | ||
|
||
.result__description { | ||
padding: 10px; | ||
} | ||
} | ||
|
||
.result__container:hover { | ||
background-color: rgba(250, 250, 250, 0.952); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import './elasticSearchAutocomplete.scss'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Oops, something went wrong.