-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating Nuclia Widget #792
Draft
justdaksh
wants to merge
35
commits into
nuclia
Choose a base branch
from
nuclia_widget
base: nuclia
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
99a154c
Integrating Nuclia Widget
justdaksh 520b294
removing redundant searchtester script
justdaksh b4533ea
Merged with main
justdaksh 26ba768
Merged with main
justdaksh e752db2
Revert "Merged with main"
justdaksh 2f72d6b
Merging with main
justdaksh 642e5e0
Resolved conflicts of widget with nuclia
justdaksh a6aca93
Updated nuclia_sync.yml
justdaksh aa591bf
Updated Environment varibles
justdaksh ae4d412
Merge branch 'nuclia_widget' of https://github.com/plone/training int…
justdaksh c20299a
Updating env varibale to upload job
justdaksh 00dda20
Functioning breadcrumbs,Debugging CI
justdaksh cdb9d41
Removed breadmaker.py && heading_to_breadcrumb_mapping.json
justdaksh 95037a4
Updated nuclia workflow
justdaksh 69e1658
Nuclia Sync: Updated docs
invalid-email-address adf5cbd
remove print statements
justdaksh 8262dda
Merge branch 'nuclia_widget' of https://github.com/plone/training int…
justdaksh 09683d9
Rerunning jobs for debugging
justdaksh dfc5dfe
Updating Commit Changes Run
justdaksh 38cd562
Nuclia Sync: Updated docs
invalid-email-address 930ebfe
Reverting to using JSON for breadcrumbs insted of metadata
justdaksh 323e5de
Merge branch 'nuclia_widget' of https://github.com/plone/training int…
justdaksh dd68adf
Nuclia Sync: Updated docs
invalid-email-address c0d8c37
Updated searchhtml
justdaksh 0572655
Merge branch 'nuclia_widget' of https://github.com/plone/training int…
justdaksh 7d30969
Nuclia Sync: Updated docs
invalid-email-address 4e53835
Using metadata,style changes
justdaksh adb5743
Updating workflow
justdaksh b5c5647
Added field parameter to upload script
justdaksh 28b2a20
Style Changes on results
justdaksh 6dc5fdc
title font-size change
justdaksh 5823c65
Merge branch 'main' into nuclia_widget
justdaksh 731c4d9
Merge branch 'refs/heads/main' into nuclia_widget
stevepiercy 1257b91
Merge remote-tracking branch 'origin/nuclia_widget' into nuclia_widget
stevepiercy 3373a37
Merge branch 'nuclia' into nuclia_widget
stevepiercy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Nuclia Sync | ||
|
||
on: [push] | ||
jobs: | ||
sync: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install requirements | ||
run: | | ||
pip install -q -r requirements.txt | ||
|
||
- name: Run Nuclia Sync | ||
env: | ||
DEPLOY_NUCLIA_URL: ${{secrets.DEPLOY_NUCLIA_URL}} | ||
DEPLOY_NUCLIA_TOKEN: ${{secrets.DEPLOY_NUCLIA_TOKEN}} | ||
run: | | ||
python3 upload.py | ||
|
||
- name: Check for changes in nuclia_sync.json | ||
id: check_changes | ||
run: | | ||
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) | ||
echo "Changed files: $CHANGED_FILES" | ||
if echo "$CHANGED_FILES" | grep -q 'nuclia_sync.json'; then | ||
echo "::set-output name=changed::true" | ||
else | ||
echo "::set-output name=changed::false" | ||
fi | ||
|
||
- name: Commit changes | ||
if: steps.check_changes.outputs.changed == 'true' | ||
run: | | ||
git config --global user.name github-actions | ||
git config --global user.email [email protected] | ||
git add . | ||
git commit -m "Nuclia Sync: Updated docs" | ||
git push | ||
Large diffs are not rendered by default.
Oops, something went wrong.
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,206 @@ | ||
const { switchMap } = rxjs; | ||
const nucliaResult = document.querySelector("nuclia-search-results"); | ||
const shadowRoot = nucliaResult.shadowRoot; | ||
|
||
const nuclia = new window.NucliaSDK.Nuclia({ | ||
backend: "https://nuclia.cloud/api", | ||
zone: "europe-1", | ||
knowledgeBox: "62407006-2711-4631-9c03-761d156de289", | ||
}); | ||
justdaksh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function createBreadcrumbs(resultTitleContainer,ContainerHash) { | ||
|
||
let ContainerHeading = resultTitleContainer.querySelector("div:nth-child(2)"); | ||
|
||
try { | ||
nuclia.db | ||
.getKnowledgeBox() | ||
.pipe( | ||
switchMap((knowledgeBox) => | ||
knowledgeBox.getResource(ContainerHash, [ | ||
"extra", | ||
]) | ||
) | ||
) | ||
.subscribe( | ||
(resource) => { | ||
insertBreadcrumbDiv(resource, ContainerHeading); | ||
}, | ||
(error) => { | ||
console.error("Error fetching resource:", error); | ||
} | ||
); | ||
} catch (error) { | ||
console.error("Error in createBreadcrumbs:", error); | ||
} | ||
} | ||
|
||
function insertBreadcrumbDiv(resource, ContainerHeading) { | ||
let array = resource.extra.metadata["breadcrumbs"]; | ||
if (!ContainerHeading.querySelector("div.breadcrumbs")) { | ||
let breadcrumbContainer = document.createElement("div"); | ||
breadcrumbContainer.className = "breadcrumbs"; | ||
for (let i = 0; i < array.length; i++) { | ||
let dict = array[i]; | ||
|
||
// Create a span element for each breadcrumb | ||
let breadcrumbSpan = document.createElement("span"); | ||
|
||
// Create a breadcrumb link or span based on whether it's the last breadcrumb | ||
if (i < array.length - 1) { | ||
let breadcrumbLink = document.createElement("a"); | ||
breadcrumbLink.href = dict.url; | ||
breadcrumbLink.textContent = dict.label; | ||
breadcrumbLink.classList.add("breadcrumb-link"); | ||
breadcrumbSpan.appendChild(breadcrumbLink); | ||
|
||
// Add a separator between breadcrumb links | ||
let separator = document.createTextNode(" > "); | ||
breadcrumbSpan.appendChild(separator); | ||
} else { | ||
// If it's the last breadcrumb, create a non-clickable span | ||
breadcrumbSpan.textContent = dict.label; | ||
breadcrumbSpan.classList.add("breadcrumb-last"); | ||
} | ||
|
||
breadcrumbContainer.appendChild(breadcrumbSpan); | ||
} | ||
ContainerHeading.insertAdjacentElement( | ||
"afterbegin", | ||
breadcrumbContainer | ||
); | ||
} | ||
} | ||
|
||
function isMatch(element) { | ||
return ( | ||
element && | ||
element.nodeName === "DIV" && | ||
element.classList && | ||
element.classList.contains("sw-result-row") && | ||
element.classList.length === 2 | ||
); | ||
} | ||
|
||
// Function to process added nodes within the shadow DOM | ||
function processAddedNodes(addedNodes) { | ||
addedNodes.forEach((addedNode) => { | ||
if (isMatch(addedNode)) { | ||
let resultTitleContainer = addedNode.querySelector('.result-title-container') | ||
let ContainerHash = addedNode.getAttribute('data-nuclia-rid'); | ||
if (ContainerHash.length == 32) { // To be removed when Null result issue get solved | ||
createBreadcrumbs(resultTitleContainer,ContainerHash); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function addBreadcrumbsToResults() { | ||
if (!nucliaResult) { | ||
console.error("Nuclia-search-result tag not found"); | ||
return; | ||
} | ||
let observer = new MutationObserver(callback); | ||
|
||
observer.observe(shadowRoot, { | ||
childList: true, | ||
subtree: true, | ||
}); | ||
} | ||
|
||
const callback = function (mutationsList, observer) { | ||
for (const mutation of mutationsList) { | ||
if (mutation.type === "childList") { | ||
processAddedNodes(mutation.addedNodes); | ||
} | ||
} | ||
}; | ||
|
||
const style = document.createElement('style'); | ||
style.textContent = ` | ||
:host { | ||
--pst-color-primary: #579aca; | ||
--color-on-hover: #0056b3; | ||
--color-of-separator: #777; | ||
--color-of-lastbreadcrumb: #CECECE; | ||
--size-of-title-m: 22px; | ||
} | ||
|
||
/* Breadcrumb container */ | ||
.breadcrumbs { | ||
margin: 10px 0; | ||
} | ||
|
||
/* Breadcrumb links */ | ||
.breadcrumbs a { | ||
font-size: var(--font-size-small); | ||
text-decoration: none; | ||
color: var(--pst-color-primary); | ||
transition: color 0.2s; | ||
} | ||
|
||
/* Style for the last breadcrumb */ | ||
.breadcrumbs span:last-child { | ||
font-size: var(--font-size-small); | ||
color: var(--color-of-lastbreadcrumb); | ||
} | ||
|
||
/* Separator between breadcrumbs */ | ||
.breadcrumbs .separator { | ||
font-size: var(--font-size-small); | ||
margin: 0 5px; | ||
color: var(--color-of-separator); | ||
} | ||
|
||
/* Hover effect for breadcrumb links */ | ||
.breadcrumbs a:hover { | ||
color: var(--color-on-hover); | ||
} | ||
|
||
/*Heading of the results*/ | ||
h3.ellipsis.title-m{ | ||
color: var(--pst-color-primary); | ||
font-size: var(--size-of-title-m); | ||
} | ||
|
||
/*Subheading of the results*/ | ||
.sw-paragraph-result { | ||
color: var(--pst-color-primary); | ||
} | ||
/*Gap between results*/ | ||
.results, .search-results { | ||
gap: var(--rhythm-7); | ||
} | ||
/*Gap between widget and answer generation*/ | ||
.sw-initial-answer { | ||
margin-top: var(--rhythm-3); | ||
} | ||
`; | ||
// Append the style element to the shadow DOM | ||
shadowRoot.appendChild(style); | ||
|
||
function handleThemeChange(mutationsList) { | ||
mutationsList.forEach((mutation) => { | ||
if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') { | ||
const newMode = htmlSelector.getAttribute('data-theme'); | ||
const nucliaSearchResults = document.querySelector('nuclia-search-results'); | ||
const nucliaSearchBar = document.querySelector('nuclia-search-bar'); | ||
const currentMode = nucliaSearchResults.getAttribute('mode'); | ||
|
||
if (newMode === 'dark' && currentMode !== 'dark') { | ||
nucliaSearchResults.setAttribute('mode', 'dark'); | ||
nucliaSearchBar.setAttribute('mode', 'dark'); | ||
} else if (newMode === 'light' && currentMode !== 'light') { | ||
nucliaSearchResults.setAttribute('mode', 'light'); | ||
nucliaSearchBar.setAttribute('mode', 'light'); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// Select the HTML element and configure the observer | ||
const htmlSelector = document.querySelector('html'); | ||
const observer = new MutationObserver(handleThemeChange); | ||
|
||
// Start observing changes in the data-theme attribute | ||
observer.observe(htmlSelector, { attributes: true, attributeFilter: ['data-theme'] }); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So everytime there is a commit on main, we run the job, which makes a commit on main.
It looks like an infinite loop :)
Maybe the job should have a condition like if the last changes are only about our 2 generated json files, we stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebrehault I have put the check for
nuclia_sync.json
only. This should work, right?