Skip to content

Commit

Permalink
In-app link
Browse files Browse the repository at this point in the history
  • Loading branch information
pbochynski committed Dec 5, 2024
1 parent 0e42bd2 commit 14b0210
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions examples/web-component-ext/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,27 @@ function proxyFetch(url, options = {}) {
let proxyUrl = baseUrl + `?url=${url}`;
return fetch(proxyUrl, options);
}

function createLink(text, href) {
const a = document.createElement('a');
const handler = (e) => {
e.preventDefault();
window.history.pushState({}, '', href);
window.dispatchEvent(new PopStateEvent('popstate'));
}
a.addEventListener('click', handler);
a.href = href;
a.innerHTML = text;
return a;
}

function instancesList(instances) {
let list = document.createElement('ul');
for (let instance of instances) {
// li contains instance name and namespace and button to delete instance
let li = document.createElement('li');
li.innerHTML = `${instance.metadata.name} (${instance.metadata.namespace})`;
let link = createLink(`${instance.metadata.name} (${instance.metadata.namespace})`,
`namespaces/${instance.metadata.namespace}/serviceinstances/${instance.metadata.name}`);
li.appendChild(link);
let deleteBtn = document.createElement('ui5-button');
deleteBtn.setAttribute('icon', 'delete');
deleteBtn.onclick = async () => {
Expand Down

0 comments on commit 14b0210

Please sign in to comment.