-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Conversation
There was a problem hiding this 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: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -64,7 +68,7 @@ export default Vue.extend({ | |||
default: false, | |||
}, | |||
nodes: { | |||
type: Array, | |||
type: Array as PropType<Node[]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9629adf
to
ed71a9d
Compare
|
||
// @ts-expect-error The resize observer is just now attached to the object |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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>
ed71a9d
to
8e296a5
Compare
Summary
filesListWidth
mixinUse
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 likethis.fileListWidth < 768
valid in Typescript (there are a lot of Type error in other places because of this).FilesListTableFooter
nodes
prop.defineComponent
to properly infer Typescript informationcurrentView
a prop ofFilesListTableFooter
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