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
87 changes: 87 additions & 0 deletions src/composables/UseFileSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { useDropZone, useFileDialog } from '@vueuse/core'
import { ref, computed } from 'vue'

/**
* File selection composable
* @param {Array} options
*
* Special thanks to Github user adamreisnz for creating most of this file
* https://github.com/adamreisnz
* https://github.com/vueuse/vueuse/issues/4085
*
*/
export function useFileSelection(options) {

// Extract options
const {
dropzone,
allowMultiple,
allowedFileTypes,
onFileDrop,
onFileSelect,
} = options

// Data types computed ref
const dataTypes = computed(() => {
if (allowedFileTypes?.value) {
if (!Array.isArray(allowedFileTypes.value)) {
return [allowedFileTypes.value]
}
return allowedFileTypes.value
}
return null
})

// Accept string computed ref
const accept = computed(() => {
if (Array.isArray(dataTypes.value)) {
return dataTypes.value.join(',')
}
return '*'
})

// Handling of files drop
const onDrop = files => {
if (!files || files.length === 0) {
return
}
if (files instanceof FileList) {
files = Array.from(files)
}
if (files.length > 1 && !allowMultiple.value) {
files = [files[0]]
}
filesList.value = files
onFileDrop && onFileDrop()
onFileSelect && onFileSelect()
}

const reset = () => {
filesList.value = null
}

const setFiles = (files) => {
filesList.value = files
}

// Setup dropzone and file dialog composables
const { isOverDropZone } = useDropZone(dropzone, { dataTypes, onDrop })
const { onChange, open } = useFileDialog({
accept: accept.value,
multiple: allowMultiple?.value,
})

const filesList = ref(null)

// Use onChange handler
onChange(fileList => onDrop(fileList))

// Expose interface
return {
isOverDropZone,
openFileUpload: open,
files: filesList,
reset,
setFiles,
}
}
2 changes: 2 additions & 0 deletions src/entities/job/job.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const mockJobData = (): TJob[] => [
nextRun: '',
created: '',
updated: '',
version: '1.0.0',
},
{
id: '4c3edd34-a90d-4d2a-8894-adb5836ecde8',
Expand All @@ -45,6 +46,7 @@ export const mockJobData = (): TJob[] => [
nextRun: '',
created: '',
updated: '',
version: '1.0.0',
},
]

Expand Down
4 changes: 3 additions & 1 deletion src/entities/job/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Job extends ReadonlyBaseClass implements TJob {
public readonly nextRun: string
public readonly created: string
public readonly updated: string

public readonly version: string
constructor(job: TJob) {
const processedJob: TJob = {
id: job.id || '',
Expand All @@ -48,6 +48,7 @@ export class Job extends ReadonlyBaseClass implements TJob {
nextRun: job.nextRun || '',
created: getValidISOstring(job.created) ?? '',
updated: getValidISOstring(job.updated) ?? '',
version: job.version || '',
}

super(processedJob)
Expand All @@ -73,6 +74,7 @@ export class Job extends ReadonlyBaseClass implements TJob {
errorRetention: z.number().int().positive(),
lastRun: z.string().nullable(),
nextRun: z.string().nullable(),
version: z.string(),
})

return schema.safeParse({ ...this })
Expand Down
1 change: 1 addition & 0 deletions src/entities/job/job.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export type TJob = {
nextRun: string
created: string
updated: string
version: string
}
2 changes: 2 additions & 0 deletions src/entities/synchronization/synchronization.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const mockSynchronizationData = (): TSynchronization[] => [
targetLastSynced: '2023-05-01T13:45:00Z',
created: '2023-05-01T11:00:00Z',
updated: '2023-05-01T14:00:00Z',
version: '1.0.0',
},
{
id: 2,
Expand All @@ -51,6 +52,7 @@ export const mockSynchronizationData = (): TSynchronization[] => [
targetLastSynced: '2023-05-02T13:45:00Z',
created: '2023-05-02T11:00:00Z',
updated: '2023-05-02T14:00:00Z',
version: '1.0.0',
},
]

Expand Down
3 changes: 3 additions & 0 deletions src/entities/synchronization/synchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Synchronization extends ReadonlyBaseClass implements TSynchronizati
public targetLastSynced: string
public created: string
public updated: string
public version: string

constructor(synchronization: TSynchronization) {
const processedSynchronization: TSynchronization = {
Expand All @@ -54,6 +55,7 @@ export class Synchronization extends ReadonlyBaseClass implements TSynchronizati
targetLastSynced: synchronization.targetLastSynced || '',
created: getValidISOstring(synchronization.created) ?? '',
updated: getValidISOstring(synchronization.updated) ?? '',
version: synchronization.version || '',
}

super(processedSynchronization)
Expand Down Expand Up @@ -84,6 +86,7 @@ export class Synchronization extends ReadonlyBaseClass implements TSynchronizati
targetLastSynced: z.string(),
created: z.string(),
updated: z.string(),
version: z.string(),
})

return schema.safeParse({ ...this })
Expand Down
1 change: 1 addition & 0 deletions src/entities/synchronization/synchronization.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type TSynchronization = {
targetLastSynced: string
created: string
updated: string
version: string
}
14 changes: 0 additions & 14 deletions src/modals/Endpoint/EditEndpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ import { endpointStore, navigationStore } from '../../store/store.js'
label="Description"
:value.sync="endpointItem.description" />

<NcTextField
label="Reference"
:value.sync="endpointItem.reference" />

<NcTextField
label="Version"
:value.sync="endpointItem.version" />

<NcTextField
label="Endpoint"
:value.sync="endpointItem.endpoint" />
Expand Down Expand Up @@ -105,8 +97,6 @@ export default {
endpointItem: {
name: '',
description: '',
reference: '',
version: '',
endpoint: '',
endpointArray: '',
endpointRegex: '',
Expand Down Expand Up @@ -150,8 +140,6 @@ export default {
...endpointStore.endpointItem,
name: endpointStore.endpointItem.name,
description: endpointStore.endpointItem.description,
reference: endpointStore.endpointItem.reference,
version: endpointStore.endpointItem.version,
endpoint: endpointStore.endpointItem.endpoint,
endpointArray: endpointStore.endpointItem.endpointArray.join(', '),
endpointRegex: endpointStore.endpointItem.endpointRegex,
Expand All @@ -177,8 +165,6 @@ export default {
this.endpointItem = {
name: '',
description: '',
reference: '',
version: '',
endpoint: '',
endpointArray: '',
endpointRegex: '',
Expand Down
Loading