Skip to content

Commit

Permalink
feat: update typo
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenChunShenG19 committed Dec 14, 2024
1 parent 4b535db commit 195603c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
5 changes: 5 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ declare module 'vue' {
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDataTable: typeof import('naive-ui')['NDataTable']
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
NDivider: typeof import('naive-ui')['NDivider']
NDropdown: typeof import('naive-ui')['NDropdown']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NFormItemRow: typeof import('naive-ui')['NFormItemRow']
NGi: typeof import('naive-ui')['NGi']
NGrid: typeof import('naive-ui')['NGrid']
NGridItem: typeof import('naive-ui')['NGridItem']
NIcon: typeof import('naive-ui')['NIcon']
Expand All @@ -39,6 +42,8 @@ declare module 'vue' {
NP: typeof import('naive-ui')['NP']
NPopover: typeof import('naive-ui')['NPopover']
NProgress: typeof import('naive-ui')['NProgress']
NRadio: typeof import('naive-ui')['NRadio']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
Expand Down
54 changes: 43 additions & 11 deletions src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,39 @@ import { defineStore } from 'pinia';
import { buildAuthHeader, buildURL, pureObject } from '../common';
import { loadHttpClient, storeApi } from '../datasources';
import { SearchAction, transformToCurl } from '../common/monaco';
import { DynamoDBConnection } from '../common/constants';
import { DynamoDBClient, ListTablesCommand } from '@aws-sdk/client-dynamodb';

export type ElasticsearchConnection = {
export enum DatabaseType {
ELASTICSEARCH = 'elasticsearch',
DYNAMODB = 'dynamodb'
}

export interface BaseConnection {
id?: number;
name: string;
type: DatabaseType;
}


export interface DynamoDBConnection extends BaseConnection {
type: DatabaseType.DYNAMODB;
region: string;
accessKeyId: string;
secretAccessKey: string;
}

export type Connection = ElasticsearchConnection | DynamoDBConnection;

export interface ElasticsearchConnection extends BaseConnection {
type: DatabaseType.ELASTICSEARCH;
host: string;
port: number;
username?: string;
sslCertVerification: boolean;
password?: string;
indexName?: string;
queryParameters?: string;
};
}

export type ConnectionIndex = {
health: string;
Expand All @@ -38,7 +57,7 @@ export type ConnectionIndex = {
};

type Established =
| (ElasticsearchConnection & { indices: Array<ConnectionIndex>; activeIndex?: ConnectionIndex })
| (Connection & { indices: Array<ConnectionIndex>; activeIndex?: ConnectionIndex })
| null;

const buildPath = (
Expand All @@ -60,9 +79,9 @@ const buildPath = (

export const useConnectionStore = defineStore('connectionStore', {
state: (): {
connections: (ElasticsearchConnection | DynamoDBConnection)[];
connections: Connection[];
established: Established;
currentConnection: ElasticsearchConnection | null;
currentConnection: Connection | null;
} => {
return {
connections: [],
Expand All @@ -83,14 +102,27 @@ export const useConnectionStore = defineStore('connectionStore', {
},
actions: {
async fetchConnections() {
this.connections = (await storeApi.get('connections', [])) as ElasticsearchConnection[];
try {
const connections = await storeApi.get('connections', []) as Connection[];
this.connections = connections.map(conn => {
if ('host' in conn && 'port' in conn) {
return { ...conn, type: DatabaseType.ELASTICSEARCH };
} else if ('region' in conn && 'accessKeyId' in conn) {
return { ...conn, type: DatabaseType.DYNAMODB };
}
return conn;
});
} catch (error) {
console.error('Error fetching connections:', error);
this.connections = [];
}
},
async testConnection(con: ElasticsearchConnection) {
const client = loadHttpClient(con);

return await client.get(con.indexName ?? undefined, 'format=json');
},
async saveConnection(connection: ElasticsearchConnection | DynamoDBConnection) {
async saveConnection(connection:Connection) {
try {
if (connection.id) {
const index = this.connections.findIndex(c => c.id === connection.id);
Expand All @@ -114,7 +146,7 @@ export const useConnectionStore = defineStore('connectionStore', {
throw error;
}
},
async removeConnection(connection: ElasticsearchConnection | DynamoDBConnection) {
async removeConnection(connection: Connection) {
try {
this.connections = this.connections.filter(c => c.id !== connection.id);

Expand All @@ -128,9 +160,9 @@ export const useConnectionStore = defineStore('connectionStore', {
throw error;
}
},
async establishConnection(connection: ElasticsearchConnection) {
async establishConnection(connection: Connection) {
try {
await this.testConnection(connection);
await this.testElasticsearchConnection(connection);
} catch (err) {
this.established = null;
throw err;
Expand Down
11 changes: 9 additions & 2 deletions src/views/connect/components/connect-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
>
<div class="left-box" @click="establishConnect(con)">
<div class="icon">
<img v-if="con.type === DatabaseType.ELASTICSEARCH" src="../../../assets/svg/elasticsearch.svg" />
<img v-else-if="con.type === DatabaseType.DYNAMODB" src="../../../assets/svg/dynamodb.svg" />
<img
:src="con.type === DatabaseType.ELASTICSEARCH
? '../../../assets/svg/elasticsearch.svg'
: '../../../assets/svg/dynamodb.svg'"
/>
</div>
<div class="name">{{ con.name }}</div>
</div>
Expand Down Expand Up @@ -86,6 +89,10 @@ const establishConnect = async (connection: Connection) => {
// edit connect info
const editConnect = (connection: Connection) => {
if (!connection.type) {
console.error('Connection type is missing');
return;
}
emits('edit-connect', connection);
};
const removeConnect = (connection: Connection) => {
Expand Down
15 changes: 10 additions & 5 deletions src/views/connect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<script setup lang="ts">
import { ref } from 'vue';
import { storeToRefs } from 'pinia';
import { useConnectionStore } from '../../store/connectionStore';
import { Connection, useConnectionStore } from '../../store/connectionStore';
import { DatabaseType } from '../../common/constants';
import ConnectDialog from './components/connect-dialog.vue';
import DynamodbConnectDialog from './components/dynamodb-connect-dialog.vue';
Expand Down Expand Up @@ -110,15 +110,20 @@ const getDatabaseTypeLabel = (type: DatabaseType) => {
return type === DatabaseType.ELASTICSEARCH ? 'Elasticsearch' : 'DynamoDB';
};
const editConnection = (connection: ElasticsearchConnection | DynamoDBConnection) => {
const editConnection = (connection: Connection) => {
if (!connection.type) {
console.error('Connection type is missing');
return;
}
if (connection.type === DatabaseType.ELASTICSEARCH) {
esConnectDialog.value.showMedal(connection);
esConnectDialog.value?.showMedal(connection);
} else if (connection.type === DatabaseType.DYNAMODB) {
dynamodbConnectDialog.value.showMedal(connection);
dynamodbConnectDialog.value?.showMedal(connection);
}
};
const deleteConnection = async (connection: ElasticsearchConnection | DynamoDBConnection) => {
const deleteConnection = async (connection: Connection) => {
try {
await connectionStore.removeConnection(connection);
message.success(lang.t('connection.deleteSuccess'));
Expand Down

0 comments on commit 195603c

Please sign in to comment.