Skip to content

Commit aaa247b

Browse files
committed
feat: datasource table
1 parent 8dbac2a commit aaa247b

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

backend/apps/datasource/crud/datasource.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ def sync_table(session: SessionDep, ds: CoreDatasource, tables: List[CoreTable])
183183
session.query(CoreField).filter(and_(CoreField.ds_id == ds.id, CoreField.table_id.not_in(id_list))).delete(
184184
synchronize_session=False)
185185
session.commit()
186+
else: # delete all tables and fields in this ds
187+
session.query(CoreTable).filter(CoreTable.ds_id == ds.id).delete(synchronize_session=False)
188+
session.query(CoreField).filter(CoreField.ds_id == ds.id).delete(synchronize_session=False)
189+
session.commit()
186190

187191

188192
def sync_fields(session: SessionDep, ds: CoreDatasource, table: CoreTable, fields: List[ColumnSchema]):

frontend/src/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@
227227
"cannot_be_deleted": "The chart of the dashboard uses this data source and cannot be deleted.",
228228
"got_it": "Got it",
229229
"field_original_notes": "Field original notes",
230-
"field_notes_1": "Field notes"
230+
"field_notes_1": "Field notes",
231+
"no_table":"No Table",
232+
"go_add":"Add"
231233
},
232234
"model": {
233235
"default_model": "Default model",

frontend/src/i18n/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@
230230
"cannot_be_deleted": "仪表板的图表使用了该数据源,不可删除。",
231231
"got_it": "知道了",
232232
"field_original_notes": "字段原始备注",
233-
"field_notes_1": "字段备注"
233+
"field_notes_1": "字段备注",
234+
"no_table":"暂无数据表",
235+
"go_add":"去添加"
234236
},
235237
"model": {
236238
"default_model": "默认模型",

frontend/src/views/ds/DataTable.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import EmptyBackground from '@/views/dashboard/common/EmptyBackground.vue'
88
import edit from '@/assets/svg/icon_edit_outlined.svg'
99
import { useI18n } from 'vue-i18n'
1010
import ParamsForm from './ParamsForm.vue'
11+
import icon_add_outlined from '@/assets/svg/icon_add_outlined.svg'
1112
1213
interface Table {
1314
name: string
@@ -53,6 +54,7 @@ const { t } = useI18n()
5354
const paramsFormRef = ref()
5455
const tableList = ref([] as any[])
5556
const loading = ref(false)
57+
const initLoading = ref(false)
5658
const keywords = ref('')
5759
const tableListWithSearch = computed(() => {
5860
if (!keywords.value) return tableList.value
@@ -67,11 +69,13 @@ const ds = ref<any>({})
6769
const btnSelect = ref('d')
6870
6971
const init = () => {
72+
initLoading.value = true
7073
datasourceApi.getDs(props.info.id).then((res) => {
7174
ds.value = res
7275
fieldList.value = []
7376
datasourceApi.tableList(props.info.id).then((res) => {
7477
tableList.value = res
78+
initLoading.value = false
7579
})
7680
})
7781
}
@@ -213,7 +217,7 @@ const back = () => {
213217
</template>
214218
</el-input>
215219

216-
<div class="list-content">
220+
<div v-loading="initLoading" class="list-content">
217221
<div
218222
v-for="ele in tableListWithSearch"
219223
:key="ele.table_name"
@@ -233,6 +237,16 @@ const back = () => {
233237
img-type="tree"
234238
style="width: 100%; margin-top: 100px"
235239
/>
240+
<div v-else-if="!initLoading && !tableListWithSearch.length" class="no-data">
241+
<div class="no-data-msg">
242+
<div>
243+
{{ $t('datasource.no_table') }}
244+
</div>
245+
<el-button type="primary" link @click="handleSelectTableList">
246+
{{ $t('datasource.go_add') }}
247+
</el-button>
248+
</div>
249+
</div>
236250
</div>
237251
</div>
238252

@@ -447,6 +461,20 @@ const back = () => {
447461
}
448462
}
449463
}
464+
465+
.no-data {
466+
height: 100%;
467+
text-align: center;
468+
display: flex;
469+
align-items: center;
470+
width: 100%;
471+
.no-data-msg {
472+
display: inline;
473+
width: 100%;
474+
color: var(--ed-text-color-secondary);
475+
font-size: var(--ed-font-size-base);
476+
}
477+
}
450478
}
451479
.info-table {
452480
position: absolute;

0 commit comments

Comments
 (0)