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

fix: Node imports paths #1141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 deletions __tests__/dav/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { readFile } from 'node:fs/promises'
// required as default URL will be the DOM URL class which will use the window.location
import { URL as FileURL } from 'node:url'
import * as auth from '@nextcloud/auth'

import {
defaultRemoteURL,
Expand All @@ -12,12 +15,11 @@ import {
getFavoriteNodes,
resultToNode,
} from '../../lib/dav/index'
import { File, Folder, NodeStatus } from '../../lib'
import { FileStat } from 'webdav'
import * as auth from '@nextcloud/auth'

// required as default URL will be the DOM URL class which will use the window.location
import { URL as FileURL } from 'node:url'
import { File } from '../../lib/files/file'
import { FileStat } from 'webdav'
import { Folder } from '../../lib/files/folder'
import { NodeStatus } from '../../lib/files/node'

vi.mock('@nextcloud/auth')
vi.mock('@nextcloud/router')
Expand Down
8 changes: 4 additions & 4 deletions __tests__/fileListAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { beforeEach, describe, expect, test, vi } from 'vitest'

import type { View } from '../lib/navigation/view.ts'
import type { View } from '../lib/navigation/view'

import { getFileListActions, registerFileListAction, FileListAction } from '../lib/fileListAction.ts'
import { Folder } from '../lib/files/folder.ts'
import logger from '../lib/utils/logger.ts'
import { getFileListActions, registerFileListAction, FileListAction } from '../lib/fileListAction'
import { Folder } from '../lib/files/folder'
import logger from '../lib/utils/logger'

const mockAction = (id: string) => new FileListAction({
id,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import { describe, expect, test } from 'vitest'

import { View } from '../lib/navigation/view.ts'
import { Folder } from '../lib/index.ts'
import { View } from '../lib/navigation/view'
import { Folder } from '../lib/files/folder'

describe('Invalid View creation', () => {
test('Invalid id', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/dav/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { NodeData } from '../files/nodeData'
import { parsePermissions } from './davPermissions'
import { getFavoritesReport } from './davProperties'

import { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth'
import { generateRemoteUrl } from '@nextcloud/router'
import { CancelablePromise } from 'cancelable-promise'
import { createClient, getPatcher } from 'webdav'
import { generateRemoteUrl } from '@nextcloud/router'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why sorting down? @... should be before c...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sort the lines, not the libraries, have been doing this everywhere here for... Years 😂
Funny you're only noticing this now 🤭

import { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth'
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'

/**
Expand Down Expand Up @@ -201,5 +201,5 @@ export const resultToNode = function(node: FileStat, filesRoot = defaultRootPath

delete nodeData.attributes?.props

return node.type === 'file' ? new File(nodeData) : new Folder(nodeData)
return (node.type === 'file' ? new File(nodeData) : new Folder(nodeData)) as Node
}
4 changes: 2 additions & 2 deletions lib/fileAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { Node } from './files/node'
import { View } from './navigation/view'
import type { Node } from './files/node'
import type { View } from './navigation/view'
import logger from './utils/logger'

export enum DefaultType {
Expand Down
8 changes: 4 additions & 4 deletions lib/fileListAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { Node } from './files/node.ts'
import { Folder } from './files/folder.ts'
import { View } from './navigation/view.ts'
import logger from './utils/logger.ts'
import type { Node } from './files/node'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing the extensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency

import type { Folder } from './files/folder'
import type { View } from './navigation/view'
import logger from './utils/logger'

interface ActionContext {
folder: Folder,
Expand Down
6 changes: 3 additions & 3 deletions lib/fileListFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { emit } from '@nextcloud/event-bus'
import { TypedEventTarget } from 'typescript-event-target'
import { INode } from './files/node'
import { Node } from './files/node'

/**
* Active filters can provide one or more "chips" to show the currently active state.
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface IFileListFilter extends TypedEventTarget<IFileListFilterEvents>
* @param nodes Nodes to filter
* @return Subset of the `nodes` parameter to show
*/
filter(nodes: INode[]): INode[]
filter(nodes: Node[]): Node[]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change and I do not see how it would help.
(I requires the exact implementation with privat methods instead of the only required interface)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall we use INode everywhere then? I find the multiple types confusing.
Which are we supposed to use now ?


/**
* If the filter needs a visual element for settings it can provide a function to mount it.
Expand Down Expand Up @@ -103,7 +103,7 @@ export class FileListFilter extends TypedEventTarget<IFileListFilterEvents> impl
this.order = order
}

public filter(nodes: INode[]): INode[] {
public filter(nodes: Node[]): Node[] {
throw new Error('Not implemented')
return nodes
}
Expand Down
3 changes: 2 additions & 1 deletion lib/newFileMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Folder, Node } from './index'
import type { Node } from './files/node'
import type { Folder } from './files/folder'
import logger from './utils/logger'

export enum NewMenuEntryCategory {
Expand Down
14 changes: 7 additions & 7 deletions lib/utils/fileSorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { INode } from '../files/node'
import type { Node } from '../files/node'
import type { SortingOrder } from './sorting'
import { orderBy } from './sorting'

Expand Down Expand Up @@ -42,7 +42,7 @@ export interface FilesSortingOptions {
* @param nodes Nodes to sort
* @param options Sorting options
*/
export function sortNodes(nodes: readonly INode[], options: FilesSortingOptions = {}): INode[] {
export function sortNodes(nodes: readonly Node[], options: FilesSortingOptions = {}): Node[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, breaking and not needed.
We only need the interface (public) not the private implementation.

const sortingOptions = {
// Default to sort by name
sortingMode: FilesSortingMode.Name,
Expand All @@ -59,15 +59,15 @@ export function sortNodes(nodes: readonly INode[], options: FilesSortingOptions

const identifiers = [
// 1: Sort favorites first if enabled
...(sortingOptions.sortFavoritesFirst ? [(v: INode) => v.attributes?.favorite !== 1] : []),
...(sortingOptions.sortFavoritesFirst ? [(v: Node) => v.attributes?.favorite !== 1] : []),
// 2: Sort folders first if sorting by name
...(sortingOptions.sortFoldersFirst ? [(v: INode) => v.type !== 'folder'] : []),
...(sortingOptions.sortFoldersFirst ? [(v: Node) => v.type !== 'folder'] : []),
// 3: Use sorting mode if NOT basename (to be able to use display name too)
...(sortingOptions.sortingMode !== FilesSortingMode.Name ? [(v: INode) => v[sortingOptions.sortingMode]] : []),
...(sortingOptions.sortingMode !== FilesSortingMode.Name ? [(v: Node) => v[sortingOptions.sortingMode]] : []),
// 4: Use display name if available, fallback to name
(v: INode) => basename(v.displayname || v.attributes?.displayname || v.basename),
(v: Node) => basename(v.displayname || v.attributes?.displayname || v.basename),
// 5: Finally, use basename if all previous sorting methods failed
(v: INode) => v.basename,
(v: Node) => v.basename,
]
const orders = [
// (for 1): always sort favorites before normal files
Expand Down
2 changes: 1 addition & 1 deletion window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { IFileListFilter, Navigation } from './lib'
import type { DavProperty } from './lib/dav/davProperties'
import type { FileAction } from './lib/fileAction'
import type { FileListAction } from './lib/fileListAction.ts'
import type { FileListAction } from './lib/fileListAction'
Copy link
Contributor

Choose a reason for hiding this comment

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

Extension?

import type { Header } from './lib/fileListHeaders'
import type { NewFileMenu } from './lib/newFileMenu'

Expand Down
Loading