Browse Source

fix: enforce validation if table name invalid

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/1283/head
Raju Udava 3 years ago
parent
commit
9f70a3d6f8
  1. 205
      packages/nc-gui/components/utils/dlgTableCreate.vue

205
packages/nc-gui/components/utils/dlgTableCreate.vue

@ -7,112 +7,114 @@
@keydown.enter="$emit('create', table)" @keydown.enter="$emit('create', table)"
> >
<v-card class="elevation-1 backgroundColor nc-create-table-card"> <v-card class="elevation-1 backgroundColor nc-create-table-card">
<v-card-title class="primary subheading white--text py-2"> <v-form ref="form" v-model="valid">
Create A New Table <v-card-title class="primary subheading white--text py-2">
</v-card-title> Create A New Table
</v-card-title>
<v-card-text class=" py-6 px-10 "> <v-card-text class=" py-6 px-10 ">
<v-text-field <v-text-field
ref="input" ref="input"
v-model="table.alias" v-model="table.alias"
solo solo
flat flat
persistent-hint persistent-hint
dense dense
hide-details1 hide-details1
:rules="[validateTableName]" :rules="[validateTableName]"
hint="Enter table name" hint="Enter table name"
class="mt-4 caption nc-table-name" class="mt-4 caption nc-table-name"
/> />
<v-text-field <v-text-field
v-if="!projectPrefix" v-if="!projectPrefix"
v-model="table.name" v-model="table.name"
solo solo
flat flat
dense dense
persistent-hint persistent-hint
hint="Table name as saved in database" hint="Table name as saved in database"
class="mt-4 caption nc-table-name-alias" class="mt-4 caption nc-table-name-alias"
/> />
<div class=" mt-5"> <div class=" mt-5">
<label class="add-default-title grey--text">Add Default Columns</label> <label class="add-default-title grey--text">Add Default Columns</label>
<div class=" d-flex caption justify-space-between"> <div class=" d-flex caption justify-space-between">
<v-checkbox <v-checkbox
v-model="table.columns" v-model="table.columns"
dense dense
class="mt-0 " class="mt-0 "
color="info" color="info"
hide-details hide-details
value="id" value="id"
@click.capture.prevent.stop="()=>{ @click.capture.prevent.stop="()=>{
$toast.info('ID column is required, you can rename this later if required.').goAway(3000); $toast.info('ID column is required, you can rename this later if required.').goAway(3000);
if(!table.columns.includes('id')){ if(!table.columns.includes('id')){
table.columns.push('id'); table.columns.push('id');
} }
}" }"
> >
<template #label> <template #label>
<span class="caption">id</span> <span class="caption">id</span>
</template> </template>
</v-checkbox> </v-checkbox>
<v-checkbox <v-checkbox
v-model="table.columns" v-model="table.columns"
dense dense
class="mt-0 " class="mt-0 "
color="info" color="info"
hide-details hide-details
value="title" value="title"
> >
<template #label> <template #label>
<span class="caption">title</span> <span class="caption">title</span>
</template> </template>
</v-checkbox> </v-checkbox>
<v-checkbox <v-checkbox
v-model="table.columns" v-model="table.columns"
dense dense
class="mt-0 " class="mt-0 "
color="info" color="info"
hide-details hide-details
value="created_at" value="created_at"
> >
<template #label> <template #label>
<span class="caption">created_at</span> <span class="caption">created_at</span>
</template> </template>
</v-checkbox> </v-checkbox>
<v-checkbox <v-checkbox
v-model="table.columns" v-model="table.columns"
dense dense
class="mt-0 " class="mt-0 "
color="info" color="info"
hide-details hide-details
value="updated_at" value="updated_at"
> >
<template #label> <template #label>
<span class="caption">updated_at</span> <span class="caption">updated_at</span>
</template> </template>
</v-checkbox> </v-checkbox>
</div>
</div> </div>
</div> </v-card-text>
</v-card-text> <v-divider />
<v-divider />
<v-card-actions class="py-4 px-10"> <v-card-actions class="py-4 px-10">
<v-spacer /> <v-spacer />
<v-btn class="" @click="dialogShow = false"> <v-btn class="" @click="dialogShow = false">
Cancel Cancel
</v-btn> </v-btn>
<v-btn <v-btn
:disabled="!(table.name && table.name.length) || !(table.alias && table.alias.length)" :disabled="!(table.name && table.name.length) || !(table.alias && table.alias.length) || !valid"
color="primary" color="primary"
class="nc-create-table-submit" class="nc-create-table-submit"
@click="$emit('create',table)" @click="$emit('create',table)"
> >
Submit Submit
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
</v-form>
</v-card> </v-card>
</v-dialog> </v-dialog>
</template> </template>
@ -134,7 +136,8 @@ export default {
'created_at', 'created_at',
'updated_at'] 'updated_at']
}, },
validateTableName validateTableName,
valid: false
} }
}, },
computed: { computed: {

Loading…
Cancel
Save