Skip to content

Commit

Permalink
feat: refactor database sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Sep 16, 2024
1 parent 58b4027 commit 6cdb95d
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 342 deletions.
29 changes: 0 additions & 29 deletions qodana.yaml

This file was deleted.

157 changes: 157 additions & 0 deletions src/components/core/database/DatabaseSidebar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<script setup lang="tsx">
import { ref, computed, watch } from 'vue';
import { ElTree, ElInput } from 'element-plus';
import { debounce } from 'lodash';
import { translate } from '@/utils';
import type { FilterNodeMethodFunction } from 'element-plus/es/components/tree/src/tree.type';
const t = translate;
const props = defineProps<{
treeItems: DatabaseNavItem[];
defaultExpandedKeys: string[];
}>();
const emit = defineEmits<{
(e: 'nodeClick', data: DatabaseNavItem): void;
(e: 'contextMenuClick', event: MouseEvent, data: DatabaseNavItem): void;
(e: 'refresh'): void;
(e: 'createDatabase'): void;
(e: 'createTable'): void;
}>();
const treeRef = ref<InstanceType<typeof ElTree>>();
const searchKeyword = ref('');
const showSearch = ref(false);
const onSearchFilter: FilterNodeMethodFunction = (value, data) => {
if (!value) return true;
return data.label.toLowerCase().includes(value.toLowerCase());
};
const debouncedFilter = debounce(() => {
treeRef.value?.filter(searchKeyword.value);
}, 300);
watch(searchKeyword, debouncedFilter);
const toggleSearch = () => {
showSearch.value = !showSearch.value;
if (!showSearch.value) {
searchKeyword.value = '';
treeRef.value?.filter('');
}
};
const onRefresh = () => {
emit('refresh');
};
const onCreateDatabase = () => {
emit('createDatabase');
};
const onCreateTable = () => {
emit('createTable');
};
defineExpose({ treeRef });
defineOptions({ name: 'ClDatabaseSidebar' });
</script>

<template>
<div class="sidebar">
<div class="sidebar-actions">
<el-button @click="toggleSearch">
<i class="fa fa-search"></i>
</el-button>
<el-button @click="onRefresh">
<i class="fa fa-sync"></i>
</el-button>
<el-button @click="onCreateDatabase">
<i class="fa fa-database"></i>
</el-button>
<el-button @click="onCreateTable">
<i class="fa fa-table"></i>
</el-button>
</div>
<div v-if="showSearch" class="sidebar-search">
<el-input
v-model="searchKeyword"
:placeholder="t('views.database.databases.sidebar.search.placeholder')"
clearable
@clear="
() => {
searchKeyword = '';
showSearch = false;
}
"
/>
</div>
<el-scrollbar>
<el-tree
ref="treeRef"
node-key="id"
:data="treeItems"
:props="{
class: _data => {
if (_data.new) return 'new';
return '';
},
}"
:filter-node-method="onSearchFilter"
:expand-on-click-node="false"
:default-expanded-keys="defaultExpandedKeys"
highlight-current
@node-click="data => emit('nodeClick', data)"
@node-contextmenu="
(event, _, node) => emit('contextMenuClick', event, node.data)
"
>
<template #default="{ node, data }">
<span class="custom-tree-node">
<span>
<i :class="data.icon"></i>
{{ node.label }}
</span>
</span>
</template>
</el-tree>
</el-scrollbar>
</div>
</template>

<style scoped>
.sidebar {
width: 250px;
border-right: 1px solid var(--el-border-color);
display: flex;
flex-direction: column;
}
.sidebar-actions {
display: flex;
justify-content: space-around;
padding: 10px;
border-bottom: 1px solid var(--el-border-color);
}
.sidebar-search {
padding: 10px;
border-bottom: 1px solid var(--el-border-color);
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
.custom-tree-node i {
margin-right: 8px;
}
</style>
54 changes: 28 additions & 26 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import CreateEditDatabaseDialog from './core/database/CreateEditDatabaseDialog.vue';
import CreateEditDatabaseTableDialog from './core/database/CreateEditDatabaseTableDialog.vue';
import DatabaseDatabaseDetail from './core/database/DatabaseDatabaseDetail.vue';
import DatabaseDataSource from './core/database/DatabaseDataSource.vue';
import DatabaseDatabaseDetail from './core/database/DatabaseDatabaseDetail.vue';
import DatabaseForm from './core/database/DatabaseForm.vue';
import DatabaseSidebar from './core/database/DatabaseSidebar.vue';
import DatabaseStatus from './core/database/DatabaseStatus.vue';
import DatabaseTableDetail from './core/database/DatabaseTableDetail.vue';
import DatabaseTableDetailColumns from './core/database/tables/DatabaseTableDetailColumns.vue';
Expand Down Expand Up @@ -84,10 +85,10 @@ import Chart from './ui/chart/Chart.vue';
import Metric from './ui/chart/Metric.vue';
import ContextMenu from './ui/context-menu/ContextMenu.vue';
import ContextMenuList from './ui/context-menu/ContextMenuList.vue';
import * as date from './ui/date/date';
import DateRangePicker from './ui/date/DateRangePicker.vue';
import DateTimeRangePicker from './ui/date/DateTimeRangePicker.vue';
import RangePicker from './ui/date/RangePicker.vue';
import * as date from './ui/date/date';
import ConfirmDialog from './ui/dialog/ConfirmDialog.vue';
import CreateEditDialog from './ui/dialog/CreateEditDialog.vue';
import Dialog from './ui/dialog/Dialog.vue';
Expand All @@ -101,7 +102,6 @@ import FileActions from './ui/file/FileActions.vue';
import FileDiff from './ui/file/FileDiff.vue';
import FileEditor from './ui/file/FileEditor.vue';
import FileEditorCreateWithAiDialog from './ui/file/FileEditorCreateWithAiDialog.vue';
import * as fileEditorDropZone from './ui/file/fileEditorDropZone';
import FileEditorNavMenu from './ui/file/FileEditorNavMenu.vue';
import FileEditorNavMenuContextMenu from './ui/file/FileEditorNavMenuContextMenu.vue';
import FileEditorNavTabs from './ui/file/FileEditorNavTabs.vue';
Expand All @@ -111,21 +111,23 @@ import FileEditorSettingsDialog from './ui/file/FileEditorSettingsDialog.vue';
import FileTab from './ui/file/FileTab.vue';
import FileUpload from './ui/file/FileUpload.vue';
import UploadFilesDialog from './ui/file/UploadFilesDialog.vue';
import * as filter from './ui/filter/filter';
import * as fileEditorDropZone from './ui/file/fileEditorDropZone';
import FilterCondition from './ui/filter/FilterCondition.vue';
import FilterConditionList from './ui/filter/FilterConditionList.vue';
import FilterInput from './ui/filter/FilterInput.vue';
import FilterSelect from './ui/filter/FilterSelect.vue';
import * as filter from './ui/filter/filter';
import Form from './ui/form/Form.vue';
import FormItem from './ui/form/FormItem.vue';
import * as formTable from './ui/form/formTable';
import FormTableField from './ui/form/FormTableField.vue';
import * as formTable from './ui/form/formTable';
import useForm from './ui/form/useForm';
import AtomMaterialIcon from './ui/icon/AtomMaterialIcon.vue';
import * as icon from './ui/icon/icon';
import Icon from './ui/icon/Icon.vue';
import MenuItemIcon from './ui/icon/MenuItemIcon.vue';
import * as icon from './ui/icon/icon';
import InputList from './ui/input/InputList.vue';
import LexicalEditor from './ui/lexical/LexicalEditor.vue';
import BlockOptionsDropdownList from './ui/lexical/components/BlockOptionsDropdownList.vue';
import DropdownButton from './ui/lexical/components/DropdownButton.vue';
import FloatLinkEditor from './ui/lexical/components/FloatLinkEditor.vue';
Expand All @@ -141,7 +143,6 @@ import useLexicalList from './ui/lexical/composables/useLexicalList';
import useLexicalMounted from './ui/lexical/composables/useLexicalMounted';
import useRichTextSetup from './ui/lexical/composables/useRichTextSetup';
import useVariableSetup from './ui/lexical/composables/useVariableSetup';
import LexicalEditor from './ui/lexical/LexicalEditor.vue';
import * as ImageNode from './ui/lexical/nodes/ImageNode';
import * as VariableNode from './ui/lexical/nodes/VariableNode';
import LexicalAutoFocusPlugin from './ui/lexical/plugins/LexicalAutoFocusPlugin.vue';
Expand Down Expand Up @@ -179,14 +180,8 @@ import NavTabs from './ui/nav/NavTabs.vue';
import InputSelect from './ui/select/InputSelect.vue';
import Switch from './ui/switch/Switch.vue';
import ActionTab from './ui/tab/ActionTab.vue';
import * as action from './ui/table/action';
import * as column from './ui/table/column';
import * as data from './ui/table/data';
import EditTable from './ui/table/EditTable.vue';
import EditTableActionCell from './ui/table/EditTableActionCell.vue';
import * as header from './ui/table/header';
import * as pagination from './ui/table/pagination';
import * as store from './ui/table/store';
import Table from './ui/table/Table.vue';
import TableActions from './ui/table/TableActions.vue';
import TableCell from './ui/table/TableCell.vue';
Expand All @@ -197,6 +192,12 @@ import TableHeaderAction from './ui/table/TableHeaderAction.vue';
import TableHeaderDialog from './ui/table/TableHeaderDialog.vue';
import TableHeaderDialogFilter from './ui/table/TableHeaderDialogFilter.vue';
import TableHeaderDialogSort from './ui/table/TableHeaderDialogSort.vue';
import * as action from './ui/table/action';
import * as column from './ui/table/column';
import * as data from './ui/table/data';
import * as header from './ui/table/header';
import * as pagination from './ui/table/pagination';
import * as store from './ui/table/store';
import CheckTag from './ui/tag/CheckTag.vue';
import CheckTagGroup from './ui/tag/CheckTagGroup.vue';
import LinkTag from './ui/tag/LinkTag.vue';
Expand All @@ -210,9 +211,10 @@ import TransferPanel from './ui/transfer/TransferPanel.vue';
export {
CreateEditDatabaseDialog as ClCreateEditDatabaseDialog,
CreateEditDatabaseTableDialog as ClCreateEditDatabaseTableDialog,
DatabaseDatabaseDetail as ClDatabaseDatabaseDetail,
DatabaseDataSource as ClDatabaseDataSource,
DatabaseDatabaseDetail as ClDatabaseDatabaseDetail,
DatabaseForm as ClDatabaseForm,
DatabaseSidebar as ClDatabaseSidebar,
DatabaseStatus as ClDatabaseStatus,
DatabaseTableDetail as ClDatabaseTableDetail,
DatabaseTableDetailColumns as ClDatabaseTableDetailColumns,
Expand Down Expand Up @@ -294,10 +296,10 @@ export {
Metric as ClMetric,
ContextMenu as ClContextMenu,
ContextMenuList as ClContextMenuList,
date as date,
DateRangePicker as ClDateRangePicker,
DateTimeRangePicker as ClDateTimeRangePicker,
RangePicker as ClRangePicker,
date as date,
ConfirmDialog as ClConfirmDialog,
CreateEditDialog as ClCreateEditDialog,
Dialog as ClDialog,
Expand All @@ -311,7 +313,6 @@ export {
FileDiff as ClFileDiff,
FileEditor as ClFileEditor,
FileEditorCreateWithAiDialog as ClFileEditorCreateWithAiDialog,
fileEditorDropZone as fileEditorDropZone,
FileEditorNavMenu as ClFileEditorNavMenu,
FileEditorNavMenuContextMenu as ClFileEditorNavMenuContextMenu,
FileEditorNavTabs as ClFileEditorNavTabs,
Expand All @@ -321,21 +322,23 @@ export {
FileTab as ClFileTab,
FileUpload as ClFileUpload,
UploadFilesDialog as ClUploadFilesDialog,
filter as filter,
fileEditorDropZone as fileEditorDropZone,
FilterCondition as ClFilterCondition,
FilterConditionList as ClFilterConditionList,
FilterInput as ClFilterInput,
FilterSelect as ClFilterSelect,
filter as filter,
Form as ClForm,
FormItem as ClFormItem,
formTable as formTable,
FormTableField as ClFormTableField,
formTable as formTable,
useForm as useForm,
AtomMaterialIcon as ClAtomMaterialIcon,
icon as icon,
Icon as ClIcon,
MenuItemIcon as ClMenuItemIcon,
icon as icon,
InputList as ClInputList,
LexicalEditor as ClLexicalEditor,
BlockOptionsDropdownList as ClBlockOptionsDropdownList,
DropdownButton as ClDropdownButton,
FloatLinkEditor as ClFloatLinkEditor,
Expand All @@ -351,7 +354,6 @@ export {
useLexicalMounted as useLexicalMounted,
useRichTextSetup as useRichTextSetup,
useVariableSetup as useVariableSetup,
LexicalEditor as ClLexicalEditor,
ImageNode as ImageNode,
VariableNode as VariableNode,
LexicalAutoFocusPlugin as ClLexicalAutoFocusPlugin,
Expand Down Expand Up @@ -389,14 +391,8 @@ export {
InputSelect as ClInputSelect,
Switch as ClSwitch,
ActionTab as ClActionTab,
action as action,
column as column,
data as data,
EditTable as ClEditTable,
EditTableActionCell as ClEditTableActionCell,
header as header,
pagination as pagination,
store as store,
Table as ClTable,
TableActions as ClTableActions,
TableCell as ClTableCell,
Expand All @@ -407,6 +403,12 @@ export {
TableHeaderDialog as ClTableHeaderDialog,
TableHeaderDialogFilter as ClTableHeaderDialogFilter,
TableHeaderDialogSort as ClTableHeaderDialogSort,
action as action,
column as column,
data as data,
header as header,
pagination as pagination,
store as store,
CheckTag as ClCheckTag,
CheckTagGroup as ClCheckTagGroup,
LinkTag as ClLinkTag,
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/lang/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ const common: LCommon = {
asc: 'Ascending',
desc: 'Descending',
},
validate: {
cannotBeEmpty: 'Cannot be empty',
},
};

export default common;
3 changes: 3 additions & 0 deletions src/i18n/lang/zh/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ const common: LCommon = {
asc: '升序',
desc: '降序',
},
validate: {
cannotBeEmpty: '不能为空',
},
};

export default common;
Loading

0 comments on commit 6cdb95d

Please sign in to comment.