-
Notifications
You must be signed in to change notification settings - Fork 1.1k
(WIP) Adds support to allow Htmx compatibility #1569
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2e310bf
adding abort signal to turn off the js
gone 3cb6f71
moving decision to insert into function to allow overriding
gone 97330ee
adding slot to dynamically configure toolbar
gone 4068382
Optionally render js/css
gone b6a377b
Dynamic values for root_tag_extra_attrs
gone 7e61c10
allowing history refresh and switch to be scripted
gone a931fed
Work in preperation of an autorefresh
gone 32806b8
Adding initial autorefresh mode
gone a47ae06
removing some features we don't need
gone 7468906
removing render_base since we're using json not html
gone 359bb0d
Adds a setting value to toggle observing ajax requests
gone dfc6aa6
Fix bug with switching inside the history panel
gone 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,51 +1,82 @@ | ||
import { $$, ajaxForm } from "./utils.js"; | ||
import { $$, ajaxForm, pluckData, replaceToolbarState } from "./utils.js"; | ||
|
||
const djDebug = document.getElementById("djDebug"); | ||
|
||
$$.on(djDebug, "click", ".switchHistory", function (event) { | ||
event.preventDefault(); | ||
const newStoreId = this.dataset.storeId; | ||
const tbody = this.closest("tbody"); | ||
function difference(setA, setB) { | ||
const _difference = new Set(setA); | ||
for (const elem of setB) { | ||
_difference.delete(elem); | ||
} | ||
return _difference; | ||
} | ||
|
||
function switchHistory(newStoreId) { | ||
const formTarget = djDebug.querySelector( | ||
".switchHistory[data-store-id='" + newStoreId + "']" | ||
); | ||
const tbody = formTarget.closest("tbody"); | ||
|
||
const highlighted = tbody.querySelector(".djdt-highlighted"); | ||
if (highlighted) { | ||
highlighted.classList.remove("djdt-highlighted"); | ||
} | ||
this.closest("tr").classList.add("djdt-highlighted"); | ||
formTarget.closest("tr").classList.add("djdt-highlighted"); | ||
|
||
ajaxForm(this).then(function (data) { | ||
djDebug.setAttribute("data-store-id", newStoreId); | ||
// Check if response is empty, it could be due to an expired store_id. | ||
ajaxForm(formTarget).then(function (data) { | ||
if (Object.keys(data).length === 0) { | ||
const container = document.getElementById("djdtHistoryRequests"); | ||
container.querySelector( | ||
'button[data-store-id="' + newStoreId + '"]' | ||
).innerHTML = "Switch [EXPIRED]"; | ||
} else { | ||
Object.keys(data).forEach(function (panelId) { | ||
const panel = document.getElementById(panelId); | ||
if (panel) { | ||
panel.outerHTML = data[panelId].content; | ||
document.getElementById("djdt-" + panelId).outerHTML = | ||
data[panelId].button; | ||
} | ||
}); | ||
} | ||
//we're already in history panel, so handle locally vs replacing active html | ||
delete data.HistoryPanel; | ||
replaceToolbarState(newStoreId, data); | ||
}); | ||
}); | ||
} | ||
|
||
$$.on(djDebug, "click", ".refreshHistory", function (event) { | ||
event.preventDefault(); | ||
function refreshHistory() { | ||
const formTarget = djDebug.querySelector(".refreshHistory"); | ||
const container = document.getElementById("djdtHistoryRequests"); | ||
ajaxForm(this).then(function (data) { | ||
// Remove existing rows first then re-populate with new data | ||
container | ||
.querySelectorAll("tr[data-store-id]") | ||
.forEach(function (node) { | ||
node.remove(); | ||
const oldIds = new Set( | ||
pluckData(container.querySelectorAll("tr[data-store-id]"), "storeId") | ||
); | ||
|
||
return ajaxForm(formTarget) | ||
.then(function (data) { | ||
// Remove existing rows first then re-populate with new data | ||
container | ||
.querySelectorAll("tr[data-store-id]") | ||
.forEach(function (node) { | ||
node.remove(); | ||
}); | ||
data.requests.forEach(function (request) { | ||
container.innerHTML = request.content + container.innerHTML; | ||
}); | ||
data.requests.forEach(function (request) { | ||
container.innerHTML = request.content + container.innerHTML; | ||
}) | ||
.then(function () { | ||
const allIds = new Set( | ||
pluckData( | ||
container.querySelectorAll("tr[data-store-id]"), | ||
"storeId" | ||
) | ||
); | ||
const newIds = difference(allIds, oldIds); | ||
const lastRequestId = newIds.values().next().value; | ||
return { | ||
allIds, | ||
newIds, | ||
lastRequestId, | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
$$.on(djDebug, "click", ".switchHistory", function (event) { | ||
event.preventDefault(); | ||
switchHistory(this.dataset.storeId); | ||
}); | ||
|
||
$$.on(djDebug, "click", ".refreshHistory", function (event) { | ||
event.preventDefault(); | ||
refreshHistory(); | ||
}); |
This file contains hidden or 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.
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.
This looks like the only part of the code that uses the controller and the signal. Outside of allowing another third party panel to abort a request, what purpose does this serve?
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.
Calling abort will unregister the click handlers - the intent here is that init will configure the JS click handlers and this will undo it to put us back in the state we were immediately before init.
The Purpose of that is that for boosted requests / Turbolinks the new page will contain it's own toolbar html, and I was finding conflicts with multiple click handlers registered.