Skip to content
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

refactor(files): Adjust some Typescript code in virtual files list #45585

Merged
merged 5 commits into from
May 31, 2024

Conversation

susnux
Copy link
Contributor

@susnux susnux commented May 30, 2024

Summary

  • Correctly cast table ref to fix TypeScript errors (I think this also makes it a bit better readable :) )
  • Refactor the filesListWidth mixin
    Use defineComponent to properly inherit typings, also add the $resizeOberserver through the setup to the component instance.
    filesListWidth is now a number which defaults to 0, making compares like this.fileListWidth < 768 valid in Typescript (there are a lot of Type error in other places because of this).
  • Properly add type information to FilesListTableFooter
    • Add correct type for nodes prop.
    • Use defineComponent to properly infer Typescript information
    • Correct usage of nullish coalescing operator
  • Make currentView a prop of FilesListTableFooter
    We already have this as a required prop in FilesListVirtual, so passing it to the footer is straight forward and removed need of computed value.

Checklist

@susnux susnux added 3. to review Waiting for reviews feature: files labels May 30, 2024
@susnux susnux added this to the Nextcloud 30 milestone May 30, 2024
@susnux susnux requested review from artonge, Pytal and ShGKme May 30, 2024 16:33
@susnux susnux requested a review from skjnldsv as a code owner May 30, 2024 16:33
Copy link
Contributor Author

@susnux susnux left a comment

Choose a reason for hiding this comment

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

Added some hints about the problems I try to solve

props: {
currentView: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolving
Screenshot_20240530_173401

@@ -123,7 +123,7 @@ export default Vue.extend({
}

// Otherwise let's compute it
return formatFileSize(this.nodes.reduce((total, node) => total + node.size || 0, 0), true)
return formatFileSize(this.nodes.reduce((total, node) => total + (node.size ?? 0), 0), true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolving

Screenshot_20240530_173353

@@ -104,7 +104,7 @@ export default Vue.extend({
if (this.dir === '/') {
return this.filesStore.getRoot(this.currentView.id)
}
const fileId = this.pathsStore.getPath(this.currentView.id, this.dir)
const fileId = this.pathsStore.getPath(this.currentView.id, this.dir)!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can safe cast here, if the dir is not found we will get the empty content message instead of the table.
So we can always assume that fileid is not undefined.

So resolving
Screenshot_20240530_173324

@@ -280,18 +281,19 @@ export default defineComponent({
event.preventDefault()
event.stopPropagation()

const tableTop = this.$refs.table.$el.getBoundingClientRect().top
const tableBottom = tableTop + this.$refs.table.$el.getBoundingClientRect().height
const tableElement = (this.$refs.table as ComponentPublicInstance<typeof VirtualList>).$el
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolving

Screenshot_20240530_173216

and

Screenshot_20240530_173207

@@ -64,7 +68,7 @@ export default Vue.extend({
default: false,
},
nodes: {
type: Array,
type: Array as PropType<Node[]>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolving

Screenshot_20240530_173151

import type { UserConfig } from '../types'

import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was never used

data() {
return {
filesListWidth: null as number | null,
filesListWidth: 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolving

Screenshot_20240530_183947


// @ts-expect-error The resize observer is just now attached to the object
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can not use setup in mixins, so we can not attach it properly with type information.
Using data also feels wrong, it should not be made reactive.

Copy link
Contributor

Choose a reason for hiding this comment

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

This mixin is quite small and only defines one property. Maybe we can rewrite it to a composable then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I also was thinking about that.
Also a composable for dir and fileid makes sense as we use it in many places and just duplicate logic there.

@ShGKme
Copy link
Contributor

ShGKme commented May 31, 2024

Thanks for detailed description about all the changes!

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Use `defineComponent` to properly inherit typings.
Expect TS errors for the `$resizeOberserver` as we attach it directly on the component instance.
`filesListWidth` is now a number which defaults to 0,
making compares like `this.fileListWidth < 768` valid in Typescript.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Add correct type for `nodes` prop.
- Use `defineComponent` to properly infer Typescript information
- Correct usage of nullish coalescing operator

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
We already have this as a required prop in `FilesListVirtual`,
so passing it to the footer is straight forward and removed need of computed
value.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux merged commit 8ed3604 into master May 31, 2024
104 checks passed
@susnux susnux deleted the fix/files-filelist-table branch May 31, 2024 16:10
@blizzz blizzz mentioned this pull request Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants