fix: overload reactive store workaround
This commit is contained in:
parent
78833a2694
commit
b1dbe8a63d
@ -3,7 +3,7 @@ function refreshSibDisplays(resourceId, clearCache = true) {
|
||||
let cacheCleared = false;
|
||||
|
||||
Array.from(document.querySelectorAll("sib-display"))
|
||||
.filter(sibDisplay => sibDisplay.component.resourceId == resourceId) // keep only elements with resource == edited resource
|
||||
.filter(sibDisplay => sibDisplay.component?sibDisplay.component.resourceId == resourceId:false) // keep only elements with resource == edited resource
|
||||
.forEach(async (e) => {
|
||||
//clear cache if we were unable to before
|
||||
if ((clearCache && !cacheCleared) && e.component.resource != null) {
|
||||
@ -25,6 +25,13 @@ async function updateSources(resource) {
|
||||
refreshSibDisplays(res.join('/'),cacheCleared);
|
||||
}
|
||||
|
||||
async function resToChildrens(resource) {
|
||||
resource = resource.getResourceData();
|
||||
refreshSibDisplays(resource["http://happy-dev.fr/owl/#user"]["@id"]);
|
||||
refreshSibDisplays(resource["http://happy-dev.fr/owl/#project"]["@id"] + "members/");
|
||||
refreshSibDisplays(resource["http://happy-dev.fr/owl/#circle"]["@id"] + "members/");
|
||||
}
|
||||
|
||||
//auxiliary function updates displays using a given resource
|
||||
//NOTE: this is a temporary workaround and should be replaced by a reactive storage
|
||||
//https://git.startinblox.com/framework/sib-core/issues/524
|
||||
@ -33,42 +40,9 @@ async function refreshResource(event) {
|
||||
// if of the edited resource || id of the container of the created resource
|
||||
const resourceId = event.detail.resource["@id"] || event.target.dataset.src;
|
||||
updateSources(resourceId, event);
|
||||
let resource;
|
||||
try {
|
||||
resource = document
|
||||
.querySelector('[data-src="' + resourceId + '"]')
|
||||
.component.resource.getResourceData();
|
||||
} catch (e) {
|
||||
try {
|
||||
resource = document
|
||||
.querySelector('[data-src="' + resourceId.replace('circle-members','circles').split('/').slice(0, 4).join('/') + '/"]')
|
||||
.component.resource.getResourceData();
|
||||
} catch (e) {
|
||||
try {
|
||||
resource = document
|
||||
.querySelector('[nested-field="' + resourceId.split('/').slice(3, 4).join('').replace('circle-members','circles') + '"]')
|
||||
.component.resource.getResourceData();
|
||||
} catch (e) {
|
||||
resource = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(resource) {
|
||||
//special case: refresh circles/X/ from circle-members/Y/
|
||||
let partnerId = null;
|
||||
if (resourceId.includes("circle-members")) {
|
||||
partnerId = resource["http://happy-dev.fr/owl/#circle"]["@id"];
|
||||
} else if (resourceId.includes("project-members")) {
|
||||
partnerId = resource["http://happy-dev.fr/owl/#project"]["@id"];
|
||||
}
|
||||
//refresh all resources using the partner ID
|
||||
if (partnerId != null) {
|
||||
refreshSibDisplays(partnerId);
|
||||
refreshSibDisplays(partnerId + "members/");
|
||||
}
|
||||
}
|
||||
|
||||
[...new Set(Array.from(document.querySelectorAll('[data-src="' + resourceId + '"]')).map(e=>e.component?e.component.resource:null).filter(e=>e!=null))].forEach(resToChildrens);
|
||||
[...new Set(Array.from(document.querySelectorAll('[data-src="' + resourceId.replace('circle-members','circles').split('/').slice(0, 4).join('/') + '/"]')).map(e=>e.component?e.component.resource:null).filter(e=>e!=null))].forEach(resToChildrens);
|
||||
[...new Set(Array.from(document.querySelectorAll('[nested-field="' + resourceId.split('/').slice(3, 4).join('').replace('circle-members','circles') + '"]')).map(e=>e.component?e.component.resource:null).filter(e=>e!=null))].forEach(resToChildrens);
|
||||
|
||||
//special cases updating users/X/circles for the left-side-menu (leaving or joining circle)
|
||||
let user = await document.querySelector('sib-auth').getUser();
|
||||
@ -82,6 +56,11 @@ async function refreshResource(event) {
|
||||
if(resourceId.includes('users')) {
|
||||
refreshSibDisplays(resourceId.split('/').slice(0, 3).join('/') + '/users/');
|
||||
refreshSibDisplays(resourceId.split('/').slice(0, 3).join('/') + '/sources/users/');
|
||||
refreshSibDisplays(resourceId + 'profile/');
|
||||
refreshSibDisplays(resourceId + 'account/');
|
||||
refreshSibDisplays(resourceId + 'chatProfile/');
|
||||
refreshSibDisplays(resourceId + 'skills/');
|
||||
refreshSibDisplays(resourceId + 'account/');
|
||||
}
|
||||
|
||||
//clear cache on this resource
|
||||
|
Loading…
Reference in New Issue
Block a user