Skip to content

Commit

Permalink
feat(core,frontend): add alias logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdeman committed Jan 28, 2025
1 parent 3f6fcab commit f67f843
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 19 deletions.
63 changes: 58 additions & 5 deletions core/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion core/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum DatabaseType {
Redis,
ElasticSearch,
MariaDB,
ClickHouse,
}

type Column {
Expand Down Expand Up @@ -78,6 +79,7 @@ input LoginProfileInput {
}

type LoginProfile {
Alias: String
Id: String!
Type: DatabaseType!
Database: String
Expand Down
12 changes: 9 additions & 3 deletions core/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/src/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func GetClideyQuickContainerImage() string {
}

type DatabaseCredentials struct {
Alias string `json:"alias"`
Hostname string `json:"host"`
Username string `json:"user"`
Password string `json:"password"`
Expand Down
10 changes: 4 additions & 6 deletions core/src/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,22 @@ func InitializeEngine() *engine.Engine {
return MainEngine
}

var profiles []env.DatabaseCredentials

func GetLoginProfiles() []env.DatabaseCredentials {
if profiles != nil {
return profiles
}
profiles := []env.DatabaseCredentials{}
for _, plugin := range MainEngine.Plugins {
databaseProfiles := env.GetDefaultDatabaseCredentials(string(plugin.Type))
for _, databaseProfile := range databaseProfiles {
databaseProfile.Type = string(plugin.Type)
profiles = append(profiles, databaseProfile)
}
}

return profiles
}

func GetLoginProfileId(index int, profile env.DatabaseCredentials) string {
if len(profile.Alias) > 0 {
return profile.Alias
}
return fmt.Sprintf("#%v - %v@%v [%v]", index+1, profile.Username, profile.Hostname, profile.Database)
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/sidebar/get-login-profiles.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query GetProfiles {
Profiles {
Alias
Id
Type
Database
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export type Column = {
};

export enum DatabaseType {
ClickHouse = 'ClickHouse',
ElasticSearch = 'ElasticSearch',
MariaDb = 'MariaDB',
MongoDb = 'MongoDB',
MySql = 'MySQL',
Postgres = 'Postgres',
Redis = 'Redis',
Sqlite3 = 'Sqlite3',
ClickHouse = 'ClickHouse'
Sqlite3 = 'Sqlite3'
}

export type GraphUnit = {
Expand Down Expand Up @@ -80,6 +80,7 @@ export type LoginCredentials = {

export type LoginProfile = {
__typename?: 'LoginProfile';
Alias?: Maybe<Scalars['String']['output']>;
Database?: Maybe<Scalars['String']['output']>;
Id: Scalars['String']['output'];
Type: DatabaseType;
Expand Down Expand Up @@ -246,7 +247,7 @@ export type StorageUnit = {
export type GetProfilesQueryVariables = Exact<{ [key: string]: never; }>;


export type GetProfilesQuery = { __typename?: 'Query', Profiles: Array<{ __typename?: 'LoginProfile', Id: string, Type: DatabaseType, Database?: string | null }> };
export type GetProfilesQuery = { __typename?: 'Query', Profiles: Array<{ __typename?: 'LoginProfile', Alias?: string | null, Id: string, Type: DatabaseType, Database?: string | null }> };

export type GetSchemaQueryVariables = Exact<{ [key: string]: never; }>;

Expand Down Expand Up @@ -388,6 +389,7 @@ export type UpdateStorageUnitMutation = { __typename?: 'Mutation', UpdateStorage
export const GetProfilesDocument = gql`
query GetProfiles {
Profiles {
Alias
Id
Type
Database
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export const LoginPage: FC = () => {
}, [database, databaseType.id, databasesLoading, foundDatabases?.Database, handleHostNameChange, hostName, password, username]);

const availableProfiles = useMemo(() => {
return profiles?.Profiles.map(profile => createDropdownItem(profile.Id, (Icons.Logos as Record<string, ReactElement>)[profile.Type])) ?? [];
return profiles?.Profiles.map(profile => createDropdownItem(profile.Alias ?? profile.Id, (Icons.Logos as Record<string, ReactElement>)[profile.Type])) ?? [];
}, [profiles?.Profiles])

if (loading || profilesLoading) {
Expand Down

0 comments on commit f67f843

Please sign in to comment.