Skip to content

Commit

Permalink
Merge pull request #11777 from rak-phillip/bugfix/11486-virtual-scroll
Browse files Browse the repository at this point in the history
Update follow behavior in `ContainerLogs.vue`
  • Loading branch information
rak-phillip committed Aug 30, 2024
2 parents c171255 + 1846eb8 commit dd71125
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions shell/components/nav/WindowManager/ContainerLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import AsyncButton from '@shell/components/AsyncButton';
import Select from '@shell/components/form/Select';
import VirtualList from 'vue3-virtual-scroll-list';
import LogItem from '@shell/components/LogItem';
import { shallowRef } from 'vue';
import { debounce } from 'lodash';
import { escapeRegex } from '@shell/utils/string';
import { HARVESTER_NAME as VIRTUAL } from '@shell/config/features';
Expand Down Expand Up @@ -130,18 +132,19 @@ export default {
data() {
return {
container: this.initialContainer || this.pod?.defaultContainerName,
socket: null,
isOpen: false,
isFollowing: true,
timestamps: this.$store.getters['prefs/get'](LOGS_TIME),
wrap: this.$store.getters['prefs/get'](LOGS_WRAP),
previous: false,
search: '',
backlog: [],
lines: [],
now: new Date(),
logItem: LogItem
container: this.initialContainer || this.pod?.defaultContainerName,
socket: null,
isOpen: false,
isFollowing: true,
scrollThreshold: 80,
timestamps: this.$store.getters['prefs/get'](LOGS_TIME),
wrap: this.$store.getters['prefs/get'](LOGS_WRAP),
previous: false,
search: '',
backlog: [],
lines: [],
now: new Date(),
logItem: shallowRef(LogItem),
};
},
Expand Down Expand Up @@ -275,6 +278,17 @@ export default {
this.connect();
},
lines: {
handler() {
if (this.isFollowing) {
this.$nextTick(() => {
this.follow();
});
}
},
deep: true
}
},
beforeUnmount() {
Expand All @@ -284,7 +298,7 @@ export default {
async mounted() {
await this.connect();
this.boundFlush = this.flush.bind(this);
this.timerFlush = setInterval(this.boundFlush, 100);
this.timerFlush = setInterval(this.boundFlush, 200);
},
methods: {
Expand Down Expand Up @@ -417,21 +431,21 @@ export default {
this.lines = this.lines.slice(-maxLines);
}
}
if ( this.isFollowing ) {
this.$nextTick(() => {
this.follow();
});
}
},
updateFollowing() {
updateFollowing: debounce(function() {
const virtualList = this.$refs.virtualList;
if (virtualList) {
this.isFollowing = virtualList.getScrollSize() - virtualList.getClientSize() === virtualList.getOffset();
const scrollSize = virtualList.getScrollSize();
const clientSize = virtualList.getClientSize();
const offset = virtualList.getOffset();
const distanceFromBottom = scrollSize - clientSize - offset;
this.isFollowing = distanceFromBottom <= this.scrollThreshold;
}
},
}, 100),
parseRange(range) {
range = `${ range }`.trim().toLowerCase();
Expand Down Expand Up @@ -503,7 +517,8 @@ export default {
const virtualList = this.$refs.virtualList;
if (virtualList) {
virtualList.$el.scrollTop = virtualList.getScrollSize();
virtualList.scrollToBottom();
this.isFollowing = true;
}
},
Expand Down Expand Up @@ -669,11 +684,11 @@ export default {
<VirtualList
v-show="filtered.length"
ref="virtualList"
class="virtual-list"
data-key="id"
:data-sources="filtered"
:data-component="logItem"
direction="vertical"
class="virtual-list"
:keeps="200"
@scroll="updateFollowing"
/>
Expand Down

0 comments on commit dd71125

Please sign in to comment.