Skip to content

Commit

Permalink
Merge pull request #19 from ConductionNL/feature/REGISTERS-34/source-…
Browse files Browse the repository at this point in the history
…type-dropdown

source type dropdown
  • Loading branch information
RalkeyOfficial authored Oct 16, 2024
2 parents 948b786 + 430553d commit a12eabc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/entities/schema/schema.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const mockSchemaData = (): TSchema[] => [
description: { type: 'string' },
},
version: '1.0.0',
source: 'https://example.com/schemas/character.json',
archive: [],
updated: new Date().toISOString(),
created: new Date().toISOString(),
Expand All @@ -29,7 +28,6 @@ export const mockSchemaData = (): TSchema[] => [
value: { type: 'number' },
},
version: '1.1.0',
source: 'https://example.com/schemas/item.json',
archive: [],
updated: new Date().toISOString(),
created: new Date().toISOString(),
Expand Down
6 changes: 3 additions & 3 deletions src/entities/source/source.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { TSource } from './source.types'
export const mockSourceData = (): TSource[] => [
{
id: 1,
title: 'Main PostgreSQL Database',
title: 'Main MongoDB Database',
description: 'Primary database for user data',
databaseUrl: 'postgresql://user:password@localhost:5432/maindb',
type: 'postgresql',
databaseUrl: 'mongodb://user:password@localhost:27017/maindb',
type: 'mongodb',
updated: new Date().toISOString(),
created: new Date().toISOString(),
},
Expand Down
6 changes: 3 additions & 3 deletions src/entities/source/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class Source implements TSource {
public title: string
public description: string
public databaseUrl: string
public type: string
public type: 'internal' | 'mongodb'
public updated: string
public created: string

Expand All @@ -16,7 +16,7 @@ export class Source implements TSource {
this.title = source.title || ''
this.description = source.description || ''
this.databaseUrl = source.databaseUrl || ''
this.type = source.type || ''
this.type = source.type || 'internal'
this.updated = source.updated || ''
this.created = source.created || ''
}
Expand All @@ -27,7 +27,7 @@ export class Source implements TSource {
title: z.string().min(1),
description: z.string(),
databaseUrl: z.string().url(),
type: z.string(),
type: z.enum(['internal', 'mongodb']),
})

return schema.safeParse(this)
Expand Down
2 changes: 1 addition & 1 deletion src/entities/source/source.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type TSource = {
title: string;
description: string;
databaseUrl: string;
type: string;
type: 'internal' | 'mongodb';
updated: string;
created: string;
}
29 changes: 20 additions & 9 deletions src/modals/source/EditSource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import { sourceStore, navigationStore } from '../../store/store.js'
<NcTextField :disabled="loading"
label="Database URL"
:value.sync="sourceItem.databaseUrl" />
<NcTextField :disabled="loading"
label="Type"
:value.sync="sourceItem.type" />
<NcSelect v-bind="typeOptions"
v-model="typeOptions.value"
input-label="Type"
:disabled="loading" />
</div>

<template #actions>
Expand Down Expand Up @@ -57,6 +58,7 @@ import {
NcDialog,
NcTextField,
NcTextArea,
NcSelect,
NcLoadingIcon,
NcNoteCard,
} from '@nextcloud/vue'
Expand All @@ -71,6 +73,7 @@ export default {
NcDialog,
NcTextField,
NcTextArea,
NcSelect,
NcButton,
NcLoadingIcon,
NcNoteCard,
Expand All @@ -85,9 +88,14 @@ export default {
title: '',
description: '',
databaseUrl: '',
type: '',
created: '',
updated: '',
},
typeOptions: {
clearable: false,
options: [
{ label: 'Internal', id: 'internal' },
{ label: 'MongoDB', id: 'mongodb' },
],
value: { label: 'Internal', id: 'internal' },
},
success: false,
loading: false,
Expand All @@ -110,6 +118,9 @@ export default {
this.sourceItem = {
...sourceStore.sourceItem,
}
// set typeOptions to the sourceItem type
this.typeOptions.value = this.typeOptions.options.find(option => option.id === this.sourceItem.type)
}
},
closeModal() {
Expand All @@ -123,16 +134,16 @@ export default {
title: '',
description: '',
databaseUrl: '',
type: '',
created: '',
updated: '',
}
// reset typeOptions to the internal option
this.typeOptions.value = this.typeOptions.options.find(option => option.id === 'internal')
},
async editSource() {
this.loading = true
sourceStore.saveSource({
...this.sourceItem,
type: this.typeOptions.value.id,
}).then(({ response }) => {
this.success = response.ok
this.error = false
Expand Down

0 comments on commit a12eabc

Please sign in to comment.