Skip to content

Commit 8b5161f

Browse files
committed
feat
1 parent f83a975 commit 8b5161f

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ Each class in `columnPreference` can have an array of column configurations:
224224
| `cloudCodeFunction` | String | no | - | `"getUserDetails"` | Cloud Function receiving selected object. |
225225
| `prefetchObjects` | Number | yes | `0` | `2` | Number of next rows to prefetch. |
226226
| `prefetchStale` | Number | yes | `0` | `10` | Seconds after which prefetched data is stale. |
227+
| `prefetchImage` | Boolean | yes | `true` | `false` | Whether to prefetch image content. |
228+
| `prefetchVideo` | Boolean | yes | `true` | `false` | Whether to prefetch video content. |
229+
| `prefetchAudio` | Boolean | yes | `true` | `false` | Whether to prefetch audio content. |
227230

228231

229232
##### User Configuration (`users[]`)
@@ -1020,7 +1023,10 @@ The following example dashboard configuration shows an info panel for the `_User
10201023
"classes": ["_User"],
10211024
"cloudCodeFunction": "getUserDetails",
10221025
"prefetchObjects": 2,
1023-
"prefetchStale": 10
1026+
"prefetchStale": 10,
1027+
"prefetchImage": true,
1028+
"prefetchVideo": true,
1029+
"prefetchAudio": true
10241030
}
10251031
]
10261032
}
@@ -1321,13 +1327,18 @@ Example:
13211327

13221328
To reduce the time for info panel data to appear, data can be prefetched.
13231329

1324-
| Parameter | Type | Optional | Default | Example | Description |
1325-
|--------------------------------|--------|----------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------|
1326-
| `infoPanel[*].prefetchObjects` | Number | yes | `0` | `2` | Number of next rows to prefetch when browsing sequential rows. For example, `2` means the next 2 rows will be fetched in advance. |
1327-
| `infoPanel[*].prefetchStale` | Number | yes | `0` | `10` | Duration in seconds after which prefetched data is discarded as stale. |
1330+
| Parameter | Type | Optional | Default | Example | Description |
1331+
|--------------------------------|---------|----------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------|
1332+
| `infoPanel[*].prefetchObjects` | Number | yes | `0` | `2` | Number of next rows to prefetch when browsing sequential rows. For example, `2` means the next 2 rows will be fetched in advance. |
1333+
| `infoPanel[*].prefetchStale` | Number | yes | `0` | `10` | Duration in seconds after which prefetched data is discarded as stale. |
1334+
| `infoPanel[*].prefetchImage` | Boolean | yes | `true` | `false` | Whether to prefetch image content when prefetching objects. Only applies when `prefetchObjects` is enabled. |
1335+
| `infoPanel[*].prefetchVideo` | Boolean | yes | `true` | `false` | Whether to prefetch video content when prefetching objects. Only applies when `prefetchObjects` is enabled. |
1336+
| `infoPanel[*].prefetchAudio` | Boolean | yes | `true` | `false` | Whether to prefetch audio content when prefetching objects. Only applies when `prefetchObjects` is enabled. |
13281337

13291338
Prefetching is particularly useful when navigating through lists of objects. To optimize performance and avoid unnecessary data loading, prefetching is triggered only after the user has moved through 3 consecutive rows using the keyboard down-arrow key or by mouse click.
13301339

1340+
When `prefetchObjects` is enabled, media content (images, videos, and audio) in the info panel can also be prefetched to improve loading performance. By default, all media types are prefetched, but you can selectively disable prefetching for specific media types using the `prefetchImage`, `prefetchVideo`, and `prefetchAudio` options.
1341+
13311342
### Freeze Columns
13321343

13331344
▶️ *Core > Browser > Freeze column*

src/dashboard/Data/Browser/Browser.react.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ class Browser extends DashboardView {
465465
classes: panel.classes,
466466
prefetchObjects: panel.prefetchObjects || 0,
467467
prefetchStale: panel.prefetchStale || 0,
468+
prefetchImage: panel.prefetchImage ?? true,
469+
prefetchVideo: panel.prefetchVideo ?? true,
470+
prefetchAudio: panel.prefetchAudio ?? true,
468471
});
469472
});
470473
});

src/dashboard/Data/Browser/DataBrowser.react.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ export default class DataBrowser extends React.Component {
768768
return {
769769
prefetchObjects: config?.prefetchObjects || 0,
770770
prefetchStale: config?.prefetchStale || 0,
771+
prefetchImage: config?.prefetchImage ?? true,
772+
prefetchVideo: config?.prefetchVideo ?? true,
773+
prefetchAudio: config?.prefetchAudio ?? true,
771774
};
772775
}
773776

@@ -809,6 +812,52 @@ export default class DataBrowser extends React.Component {
809812
}
810813
}
811814

815+
extractMediaUrls(data) {
816+
const urls = { images: [], videos: [], audios: [] };
817+
818+
if (!data?.panel?.segments) {
819+
return urls;
820+
}
821+
822+
data.panel.segments.forEach(segment => {
823+
if (segment.items) {
824+
segment.items.forEach(item => {
825+
if (item.type === 'image' && item.url) {
826+
urls.images.push(item.url);
827+
} else if (item.type === 'video' && item.url) {
828+
urls.videos.push(item.url);
829+
} else if (item.type === 'audio' && item.url) {
830+
urls.audios.push(item.url);
831+
}
832+
});
833+
}
834+
});
835+
836+
return urls;
837+
}
838+
839+
prefetchMedia(urls, mediaType) {
840+
if (!urls || urls.length === 0) {
841+
return;
842+
}
843+
844+
urls.forEach(url => {
845+
try {
846+
if (mediaType === 'image') {
847+
const img = new Image();
848+
img.src = url;
849+
} else if (mediaType === 'video' || mediaType === 'audio') {
850+
// For video and audio, we can use fetch to cache the content
851+
fetch(url, { mode: 'no-cors' }).catch(() => {
852+
// Silently fail - the media will load normally if prefetch fails
853+
});
854+
}
855+
} catch (error) {
856+
// Silently fail - the media will load normally if prefetch fails
857+
}
858+
});
859+
}
860+
812861
prefetchObject(objectId) {
813862
const { className, app } = this.props;
814863
const cloudCodeFunction =
@@ -831,6 +880,20 @@ export default class DataBrowser extends React.Component {
831880
[objectId]: { data: result, timestamp: Date.now() },
832881
},
833882
}));
883+
884+
// Prefetch media if enabled
885+
const { prefetchImage, prefetchVideo, prefetchAudio } = this.getPrefetchSettings();
886+
const mediaUrls = this.extractMediaUrls(result);
887+
888+
if (prefetchImage && mediaUrls.images.length > 0) {
889+
this.prefetchMedia(mediaUrls.images, 'image');
890+
}
891+
if (prefetchVideo && mediaUrls.videos.length > 0) {
892+
this.prefetchMedia(mediaUrls.videos, 'video');
893+
}
894+
if (prefetchAudio && mediaUrls.audios.length > 0) {
895+
this.prefetchMedia(mediaUrls.audios, 'audio');
896+
}
834897
}).catch(error => {
835898
console.error(`Failed to prefetch object ${objectId}:`, error);
836899
});

0 commit comments

Comments
 (0)