Skip to content

Commit

Permalink
feat(#113): sort connections alphabetically with preconfigured connec…
Browse files Browse the repository at this point in the history
…tions showing first
  • Loading branch information
lukashornych committed Sep 28, 2024
1 parent 4e6cfb7 commit 36f4663
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/modules/connection/explorer/component/ConnectionEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ const observabilityUrlRules = [
async (value: any) => {
const result = await testObservabilityApiConnection()
if (result) {
modifiedConnection.value.gqlUrlTested = ApiTestResult.Success
modifiedConnection.value.observabilityUrlTested = ApiTestResult.Success
return true
}
modifiedConnection.value.gqlUrlTested = ApiTestResult.Failure
modifiedConnection.value.observabilityUrlTested = ApiTestResult.Failure
return t('explorer.connection.editor.form.observability.validations.unreachable')
}
]
Expand Down Expand Up @@ -220,7 +220,13 @@ async function testGqlApiConnection(): Promise<boolean> {
}
}
async function testObservabilityApiConnection():Promise<boolean>{
return (await ky.get(modifiedConnection.value.observabilityUrl + '/metrics')).ok
// will be deleted anyway
return true
// try {
// return (await ky.get(modifiedConnection.value.observabilityUrl + '/metrics')).ok
// } catch (e) {
// return false
// }
}
function reset(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Connection } from '@/modules/connection/model/Connection'
import ConnectionItem from '@/modules/connection/explorer/component/ConnectionItem.vue'
import { EvitaLabConfig, useEvitaLabConfig } from '@/modules/config/EvitaLabConfig'
import ConnectionEditor from '@/modules/connection/explorer/component/ConnectionEditor.vue'
import Immutable from 'immutable'
const evitaLabConfig: EvitaLabConfig = useEvitaLabConfig()
const connectionService: ConnectionService = useConnectionService()
Expand All @@ -20,7 +21,16 @@ const emit = defineEmits<{
}>()
const addConnectionDialogOpen = ref<boolean>(false)
const connections = computed<Connection[]>(() => connectionService.getConnections())
const connections = computed<Immutable.List<Connection>>(() => connectionService.getConnections()
.sort((a: Connection, b: Connection) => {
if (a.preconfigured && !b.preconfigured) {
return -1
}
if (b.preconfigured && !a.preconfigured) {
return 1
}
return a.name.localeCompare(b.name)
}))
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/connection/service/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export class ConnectionService {
/**
* Returns all connections: preconfigured and user ones.
*/
getConnections(): Connection[] {
return this.store.connections as Connection[]
getConnections(): Immutable.List<Connection> {
return this.store.connections
}

isConnectionExists(connectionName: string): boolean {
Expand Down
10 changes: 6 additions & 4 deletions src/modules/connection/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ConnectionId } from '@/modules/connection/model/ConnectionId'
import { Catalog } from '@/modules/connection/model/Catalog'
import { CatalogSchema } from '@/modules/connection/model/schema/CatalogSchema'
import { UnwrapNestedRefs } from '@vue/reactivity'
import Immutable from 'immutable'

/**
* Defines Pinia store for evitaDB connections
Expand All @@ -21,10 +22,11 @@ export const useConnectionStore = defineStore('connections', () => {
/**
* All connections
*/
const connections: ComputedRef<Connection[]> = computed<Connection[]>(() => [
...(preconfiguredConnections.value as Connection[]),
...(userConnections.value as Connection[]),
])
const connections: ComputedRef<Immutable.List<Connection>> = computed<Immutable.List<Connection>>(() =>
Immutable.List.of(
...(preconfiguredConnections.value as Connection[]),
...(userConnections.value as Connection[])
))

function replacePreconfiguredConnections(newConnections: Connection[]): void {
preconfiguredConnections.value.splice(0, preconfiguredConnections.value.length)
Expand Down

0 comments on commit 36f4663

Please sign in to comment.