Skip to content

Hide show more btn in file-tree list if no more data #24983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="ui list">
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item"/>
</div>
<div v-if="isIncomplete" id="diff-too-many-files-stats" class="gt-pt-2">
<div v-if="hasMore" id="diff-too-many-files-stats" class="gt-pt-2">
<span class="gt-mr-2">{{ tooManyFilesMessage }}</span><a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
</div>
</div>
Expand All @@ -34,6 +34,14 @@ export default {
};
},
computed: {
hasMore: {
get() {
return this.isIncomplete;
},
set(newValue) {
this.isIncomplete = newValue;
}
},
Copy link
Contributor

@wxiaoguang wxiaoguang May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you doing here .....

Why a "computed" property should be "set"?

Although Vue documents says writable-computed , but I do not think it is our case .....

Copy link
Contributor

@wxiaoguang wxiaoguang May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key point of the problem here, it's not about "updating isIncomplete in computed property by tricks", the root problem is:

When the pageData.diffFileInfo changes, it needs to "notify" the Vue component to update its data/properties.

The computed property doesn't need to update anything, it should just provide the computed (read-only) result (Vue says: "Getters should be side-effect free ​")

To make the Vue component could be notified by changed pageData.diffFileInfo, either:

  1. Send an event to the Vue component after pageData.diffFileInfo is re-loaded, then Vue component re-read the pageData.diffFileInfo to its internal reactive data/properties
  2. Use "store" for pageData.diffFileInfo, then any change on pageData.diffFileInfo will trigger the Vue's reactive system to sync the values.

I think "store" is the best practice here.

fileTree() {
const result = [];
for (const file of this.files) {
Expand Down Expand Up @@ -94,6 +102,7 @@ export default {
// Merge folders with just a folder as children in order to
// reduce the depth of our tree.
mergeChildIfOnlyOneDir(result);
this.isIncomplete = pageData.diffFileInfo.isIncomplete;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not change value in a computed function. It breaks the reactive system

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a use case for a store?

Copy link
Contributor

@wxiaoguang wxiaoguang May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup (not sure how to answer by yes or no, so see details)

For best practice: https://vuejs.org/guide/essentials/computed.html#best-practices

For "store": I think the page data should be passed by a store, this diff page has been broken for many times.

return result;
}
},
Expand Down