Skip to content

Commit

Permalink
Merge pull request #1439 from nextcloud/backport/1438/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(sidebar): Refactor code to also load plugin entries when Activity API returns 304
  • Loading branch information
artonge authored Nov 30, 2023
2 parents 76513c0 + 245518e commit dd21e5a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion js/Activity-a6d3494c.mjs → js/Activity-0cba84d9.mjs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions js/ActivityTab-95839d17.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("[data-v-928a04fc] .empty-content__icon span{background-size:64px;width:64px;height:64px}.activity__actions[data-v-928a04fc]{display:flex;flex-direction:column;width:100%}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
/*! third party licenses: js/vendor.LICENSE.txt */
import{n as s,d as o,c as r}from"./index-76a58945-70e0d28e.mjs";import{d as c,r as l,o as u,e as f,f as v,t as n,g as p}from"./index-720d65ba.mjs";import{A as d,h as g,v as y,i as m}from"./Activity-0cba84d9.mjs";import{l as h}from"./logger-2ebf21a4.mjs";import{g as _,a as A,b as I}from"./api-57a0fd84.mjs";import{l as b}from"./activity-sidebar.mjs";import"./index-65a5f423.mjs";const S=c({__name:"ActivitySidebarPlugin",props:{plugin:null,fileInfo:null},emits:["reload-activities"],setup(t,{emit:i}){const e=t,a=l();return u(()=>e.plugin.mount(a.value,{context:f()?.proxy,fileInfo:e.fileInfo,reload:()=>i("reload-activities")})),v(()=>e.plugin.unmount()),{__sfc:!0,props:e,emit:i,attachTarget:a}}});var w=function(){var t=this,i=t._self._c;return t._self._setupProxy,i("div",{ref:"attachTarget"})},x=[],N=s(S,w,x,!1,null,null,null,null);const P=N.exports;const C={name:"ActivityTab",components:{Activity:d,NcEmptyContent:g,NcIconSvgWrapper:y,NcLoadingIcon:o,ActivitySidebarPlugin:P},data(){return{error:"",loading:!0,fileInfo:null,activities:[],lightningBoltSVG:b,sidebarPlugins:[]}},mounted(){this.sidebarPlugins=_()},methods:{async update(t){this.fileInfo=t,this.resetState(),await this.getActivities()},async getActivities(){try{this.loading=!0;const t=await this.processActivities(await this.loadRealActivities()),i=await A({fileInfo:this.fileInfo});this.activities=[...t,...i].sort((e,a)=>a.timestamp-e.timestamp)}catch(t){this.error=n("activity","Unable to load the activity list"),console.error("Error loading the activity list",t)}finally{this.loading=!1}},resetState(){this.loading=!0,this.error="",this.activities=[]},async loadRealActivities(){try{const{data:t}=await r.get(p("apps/activity/api/v2/activity/filter"),{params:{format:"json",object_type:"files",object_id:this.fileInfo.id}});return t.ocs.data}catch(t){if(error.response!==void 0&&error.response.status===304)return[];throw t}},processActivities(t){t=t.map(e=>new m(e)),h.debug(`Processed ${t.length} activity(ies)`,{activities:t,fileInfo:this.fileInfo});const i=I();return t.filter(e=>!i||i.every(a=>a(e)))},t:n}};var k=function(){var t=this,i=t._self._c;return i("div",{class:{"icon-loading":t.loading}},[t.error?i("NcEmptyContent",{attrs:{name:t.error},scopedSlots:t._u([{key:"icon",fn:function(){return[i("NcIconSvgWrapper",{attrs:{svg:t.lightningBoltSVG}})]},proxy:!0}],null,!1,63559581)}):[t.sidebarPlugins.length>0?i("div",{staticClass:"activity__actions"},t._l(t.sidebarPlugins,function(e,a){return i("ActivitySidebarPlugin",{key:a,attrs:{plugin:e,"file-info":t.fileInfo},on:{"reload-activities":function(T){return t.getActivities()}}})}),1):t._e(),t.loading?i("NcEmptyContent",{attrs:{name:t.t("activity","Loading activities")},scopedSlots:t._u([{key:"icon",fn:function(){return[i("NcLoadingIcon")]},proxy:!0}],null,!1,3085876643)}):t.activities.length===0?i("NcEmptyContent",{attrs:{name:t.t("activity","No activity yet")},scopedSlots:t._u([{key:"icon",fn:function(){return[i("span",{staticClass:"icon-activity"})]},proxy:!0}])}):i("ul",t._l(t.activities,function(e){return i("Activity",{key:e.id,attrs:{activity:e,"show-previews":!1},on:{reload:function(a){return t.getActivities()}}})}),1)]],2)},E=[],j=s(C,k,E,!1,null,"928a04fc",null,null);const F=j.exports;export{F as default};

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions js/ActivityTab-a8d0de48.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion js/activity-app.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/activity-sidebar.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*! third party licenses: js/vendor.LICENSE.txt */
import{V as u,t as m,b as v}from"./index-720d65ba.mjs";import"./index-65a5f423.mjs";const w="modulepreload",y=function(e,i){return e[0]==="."?new URL(e,i).href:e},p={},f=function(e,i,s){if(!i||i.length===0)return e();const d=document.getElementsByTagName("link");return Promise.all(i.map(t=>{if(t=y(t,s),t in p)return;p[t]=!0;const n=t.endsWith(".css"),h=n?'[rel="stylesheet"]':"";if(s)for(let l=d.length-1;l>=0;l--){const c=d[l];if(c.href===t&&(!n||c.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${t}"]${h}`))return;const o=document.createElement("link");if(o.rel=n?"stylesheet":w,n||(o.as="script",o.crossOrigin=""),o.href=t,document.head.appendChild(o),n)return new Promise((l,c)=>{o.addEventListener("load",l),o.addEventListener("error",()=>c(new Error(`Unable to preload CSS for ${t}`)))})})).then(()=>e()).catch(t=>{const n=new Event("vite:preloadError",{cancelable:!0});if(n.payload=t,window.dispatchEvent(n),!n.defaultPrevented)throw t})},g='<svg xmlns="http://www.w3.org/2000/svg" id="mdi-lightning-bolt" viewBox="0 0 24 24"><path d="M11 15H6L13 1V9H18L11 23V15Z" /></svg>';u.prototype.t=m,u.prototype.n=v;let a=null,r=null;const E=new OCA.Files.Sidebar.Tab({id:"activity",name:m("activity","Activity"),iconSvg:g,async mount(e,i,s){if(a===null){const{default:d}=await f(()=>import("./ActivityTab-a8d0de48.mjs"),[OC.filePath('activity', '', 'js/ActivityTab-a8d0de48.mjs'),OC.filePath('activity', '', 'js/index-76a58945-70e0d28e.mjs'),OC.filePath('activity', '', 'js/index-65a5f423.mjs'),OC.filePath('activity', '', 'js/logger-2ebf21a4.mjs'),OC.filePath('activity', '', 'js/index-720d65ba.mjs'),OC.filePath('activity', '', 'js/Activity-a6d3494c.mjs'),OC.filePath('activity', '', 'js/api-57a0fd84.mjs')],import.meta.url);a=a??u.extend(d)}r&&r.$destroy(),r=new a({parent:s}),r.update(i),r.$mount(e)},update(e){r.update(e)},destroy(){r.$destroy(),r=null}});window.addEventListener("DOMContentLoaded",async function(){if(OCA.Files&&OCA.Files.Sidebar){OCA.Files.Sidebar.registerTab(E);const{default:e}=await f(()=>import("./ActivityTab-a8d0de48.mjs"),[OC.filePath('activity', '', 'js/ActivityTab-a8d0de48.mjs'),OC.filePath('activity', '', 'js/index-76a58945-70e0d28e.mjs'),OC.filePath('activity', '', 'js/index-65a5f423.mjs'),OC.filePath('activity', '', 'js/logger-2ebf21a4.mjs'),OC.filePath('activity', '', 'js/index-720d65ba.mjs'),OC.filePath('activity', '', 'js/Activity-a6d3494c.mjs'),OC.filePath('activity', '', 'js/api-57a0fd84.mjs')],import.meta.url);a=a??u.extend(e)}});export{g as l};
import{V as u,t as m,b as v}from"./index-720d65ba.mjs";import"./index-65a5f423.mjs";const w="modulepreload",y=function(e,i){return e[0]==="."?new URL(e,i).href:e},p={},f=function(e,i,s){if(!i||i.length===0)return e();const d=document.getElementsByTagName("link");return Promise.all(i.map(t=>{if(t=y(t,s),t in p)return;p[t]=!0;const n=t.endsWith(".css"),h=n?'[rel="stylesheet"]':"";if(s)for(let l=d.length-1;l>=0;l--){const c=d[l];if(c.href===t&&(!n||c.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${t}"]${h}`))return;const o=document.createElement("link");if(o.rel=n?"stylesheet":w,n||(o.as="script",o.crossOrigin=""),o.href=t,document.head.appendChild(o),n)return new Promise((l,c)=>{o.addEventListener("load",l),o.addEventListener("error",()=>c(new Error(`Unable to preload CSS for ${t}`)))})})).then(()=>e()).catch(t=>{const n=new Event("vite:preloadError",{cancelable:!0});if(n.payload=t,window.dispatchEvent(n),!n.defaultPrevented)throw t})},g='<svg xmlns="http://www.w3.org/2000/svg" id="mdi-lightning-bolt" viewBox="0 0 24 24"><path d="M11 15H6L13 1V9H18L11 23V15Z" /></svg>';u.prototype.t=m,u.prototype.n=v;let a=null,r=null;const E=new OCA.Files.Sidebar.Tab({id:"activity",name:m("activity","Activity"),iconSvg:g,async mount(e,i,s){if(a===null){const{default:d}=await f(()=>import("./ActivityTab-95839d17.mjs"),[OC.filePath('activity', '', 'js/ActivityTab-95839d17.mjs'),OC.filePath('activity', '', 'js/index-76a58945-70e0d28e.mjs'),OC.filePath('activity', '', 'js/index-65a5f423.mjs'),OC.filePath('activity', '', 'js/logger-2ebf21a4.mjs'),OC.filePath('activity', '', 'js/index-720d65ba.mjs'),OC.filePath('activity', '', 'js/Activity-0cba84d9.mjs'),OC.filePath('activity', '', 'js/api-57a0fd84.mjs')],import.meta.url);a=a??u.extend(d)}r&&r.$destroy(),r=new a({parent:s}),r.update(i),r.$mount(e)},update(e){r.update(e)},destroy(){r.$destroy(),r=null}});window.addEventListener("DOMContentLoaded",async function(){if(OCA.Files&&OCA.Files.Sidebar){OCA.Files.Sidebar.registerTab(E);const{default:e}=await f(()=>import("./ActivityTab-95839d17.mjs"),[OC.filePath('activity', '', 'js/ActivityTab-95839d17.mjs'),OC.filePath('activity', '', 'js/index-76a58945-70e0d28e.mjs'),OC.filePath('activity', '', 'js/index-65a5f423.mjs'),OC.filePath('activity', '', 'js/logger-2ebf21a4.mjs'),OC.filePath('activity', '', 'js/index-720d65ba.mjs'),OC.filePath('activity', '', 'js/Activity-0cba84d9.mjs'),OC.filePath('activity', '', 'js/api-57a0fd84.mjs')],import.meta.url);a=a??u.extend(e)}});export{g as l};
64 changes: 36 additions & 28 deletions src/views/ActivityTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,10 @@ export default {
try {
this.loading = true

const activities = this.processActivities(await axios.get(
generateOcsUrl('apps/activity/api/v2/activity/filter'),
{
params: {
format: 'json',
object_type: 'files',
object_id: this.fileInfo.id,
},
},
))
const other = await getAdditionalEntries({ fileInfo: this.fileInfo })
this.activities = [...activities, ...other].sort((a, b) => b.timestamp - a.timestamp)
const activities = await this.processActivities(await this.loadRealActivities())
const otherEntries = await getAdditionalEntries({ fileInfo: this.fileInfo })
this.activities = [...activities, ...otherEntries].sort((a, b) => b.timestamp - a.timestamp)
} catch (error) {
// Status 304 is not an error.
if (error.response !== undefined && error.response.status === 304) {
return
}
this.error = t('activity', 'Unable to load the activity list')
console.error('Error loading the activity list', error)
} finally {
Expand All @@ -148,23 +135,44 @@ export default {
this.error = ''
this.activities = []
},

/**
* Load activites from API
*/
async loadRealActivities() {
try {
const { data } = await axios.get(
generateOcsUrl('apps/activity/api/v2/activity/filter'),
{
params: {
format: 'json',
object_type: 'files',
object_id: this.fileInfo.id,
},
},
)
return data.ocs.data
} catch (e) {
// Status 304 is not an error.
if (error.response !== undefined && error.response.status === 304) {
return []
}
throw e
}
},

/**
* Process the current activity data
* Process the API response activities and apply filter
*
* @param {object} activity the activity ocs api request data
* @param {object} activity.data the request data
* @param {any[]} activities the activites
*/
processActivities({ data }) {
if (data.ocs && data.ocs.data && data.ocs.data.length > 0) {
// create Activity objects and sort by newest
const activities = data.ocs.data
.map(activity => new ActivityModel(activity))
processActivities(activities) {
activities = activities.map(activity => new ActivityModel(activity))

logger.debug(`Processed ${activities.length} activity(ies)`, { activities, fileInfo: this.fileInfo })
logger.debug(`Processed ${activities.length} activity(ies)`, { activities, fileInfo: this.fileInfo })

const filters = getActivityFilters()
return activities.filter((activity) => !filters || filters.every((filter) => filter(activity)))
}
const filters = getActivityFilters()
return activities.filter((activity) => !filters || filters.every((filter) => filter(activity)))
},

t,
Expand Down

0 comments on commit dd21e5a

Please sign in to comment.