Skip to content
Merged
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
57 changes: 57 additions & 0 deletions .github/workflows/lint-typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud-libraries/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Type checking

on:
pull_request:
push:
branches:
- main
- master
- stable*

permissions:
contents: read

concurrency:
group: lint-typescript-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
name: Lint Typescript

steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false

- name: Read package.json
uses: nextcloud-libraries/parse-package-engines-action@122ae05d4257008180a514e1ddeb0c1b9d094bdd # v0.1.0
id: versions

- name: Set up node
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version: ${{ steps.versions.outputs.node-version }}

- name: Set up npm
run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}'

- name: Install dependencies
env:
CYPRESS_INSTALL_BINARY: 0
run: npm ci

- name: Check types
run: |
npm run --if-present check-types
npm run --if-present ts:check
4 changes: 2 additions & 2 deletions lib/components/FilePicker/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ const fileContainer = ref<HTMLDivElement>()
const nodes = fileContainer.value?.parentElement?.children || []
let height = fileContainer.value?.parentElement?.clientHeight || 450
for (let index = 0; index < nodes.length; index++) {
if (!fileContainer.value?.isSameNode(nodes[index])) {
height -= nodes[index].clientHeight
if (!fileContainer.value?.isSameNode(nodes[index]!)) {
height -= nodes[index]!.clientHeight
}
}
// container height - 50px table header / row height of 50px
Expand Down
2 changes: 1 addition & 1 deletion lib/components/FilePicker/FilePickerNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const currentViewObject = computed(() => availableViews.filter((v) => v.id === p
*
* @param value The new filter value
*/
const updateFilterValue = (value: string) => emit('update:filterString', value)
const updateFilterValue = (value: string | number) => emit('update:filterString', value.toString())
</script>

<style scoped lang="scss">
Expand Down
35 changes: 21 additions & 14 deletions lib/components/PublicAuthPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ watch(() => props.nickname, () => {
watch(name, (newName) => {
// Check validity of the new name
const validity = getGuestNameValidity(newName)
if (!validity) {
if (!validity && inputElement.value) {
// If the nickname is not valid, show an error
inputElement.value.setCustomValidity(validity)
inputElement.value.reportValidity()
inputElement.value.focus()
setCustomValidity(validity)
return
}
})
Expand Down Expand Up @@ -127,25 +125,19 @@ function onSubmit() {
const validity = getGuestNameValidity(nickname)
if (validity) {
// If the nickname is not valid, show an error
inputElement.value.setCustomValidity(validity)
inputElement.value.reportValidity()
inputElement.value.focus()
setCustomValidity(validity)
return
}

if (nickname === '') {
// Show error if the nickname is empty
inputElement.value.setCustomValidity(t('You cannot leave the name empty.'))
inputElement.value.reportValidity()
inputElement.value.focus()
setCustomValidity(t('You cannot leave the name empty.'))
return
}

if (nickname.length < 2) {
// Show error if the nickname is too short
inputElement.value.setCustomValidity(t('Please enter a name with at least 2 characters.'))
inputElement.value.reportValidity()
inputElement.value.focus()
setCustomValidity(t('Please enter a name with at least 2 characters.'))
return
}

Expand All @@ -155,7 +147,7 @@ function onSubmit() {
} catch (error) {
logger.error('Failed to set nickname', { error })
showError(t('Failed to set nickname.'))
inputElement.value.focus()
inputElement.value!.focus()
return
}

Expand All @@ -165,6 +157,21 @@ function onSubmit() {
// Close the dialog
emit('close', name.value)
}

/**
* Set custom validity message on the input
*
* @param message - The validity message
*/
function setCustomValidity(message: string) {
if (inputElement.value) {
// @ts-expect-error -- not exposed by the library but exists (todo: fix in vue library)
inputElement.value.setCustomValidity(message)
// @ts-expect-error -- not exposed by the library but exists (todo: fix in vue library)
inputElement.value.reportValidity()
inputElement.value.focus()
}
}
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion lib/composables/views.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ describe('views composable', () => {
const { availableViews, allViews } = useViews(ref(true))
expect(allViews.length).toBe(3)
expect(availableViews.length).toBe(1)
expect(availableViews[0].id).toBe('files')
expect(availableViews[0]!.id).toBe('files')
})
})
14 changes: 14 additions & 0 deletions lib/css-modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare module '*.module.css' {
const content: Record<string, string>
export default content
}

declare module '*.module.scss' {
const content: Record<string, string>
export default content
}
4 changes: 0 additions & 4 deletions lib/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ declare global {
translations: GettextTranslation[]
}[]
}

// Allow css modules
declare module '*.module.css';
declare module '*.module.scss';
8 changes: 0 additions & 8 deletions lib/vue-shims.d.ts

This file was deleted.

73 changes: 61 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"stylelint:fix": "stylelint lib/**/*.vue --fix",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"ts:check": "vue-tsc --noEmit",
"watch": "vite --mode development build --watch"
},
"browserslist": [
Expand Down Expand Up @@ -91,7 +92,8 @@
"typescript-plugin-css-modules": "^5.2.0",
"vite": "^7.2.7",
"vitest": "^4.0.10",
"vue-material-design-icons": "^5.3.1"
"vue-material-design-icons": "^5.3.1",
"vue-tsc": "^3.1.8"
},
"engines": {
"node": "^20 || ^22 || ^24"
Expand Down