mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-24 11:35:54 +08:00
fix(core-connections): CB-601 add isConnectionNew type guard
This commit is contained in:
-7
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import { observer } from 'mobx-react';
|
||||
import { useEffect } from 'react';
|
||||
import styled, { css, use } from 'reshadow';
|
||||
|
||||
import { AdministrationTools, AdministrationItemContentProps, ADMINISTRATION_TOOLS_STYLES } from '@cloudbeaver/core-administration';
|
||||
@@ -16,7 +15,6 @@ import { useController, useService } from '@cloudbeaver/core-di';
|
||||
import { Translate } from '@cloudbeaver/core-localization';
|
||||
import { useStyles, composes } from '@cloudbeaver/core-theming';
|
||||
|
||||
import { ConnectionsResource } from '../ConnectionsResource';
|
||||
import { ConnectionsAdministrationController } from './ConnectionsAdministrationController';
|
||||
import { ConnectionsTable } from './ConnectionsTable/ConnectionsTable';
|
||||
import { CreateConnection } from './CreateConnection/CreateConnection';
|
||||
@@ -75,11 +73,6 @@ export const ConnectionsAdministration: React.FC<AdministrationItemContentProps>
|
||||
}) {
|
||||
const service = useService(CreateConnectionService);
|
||||
const controller = useController(ConnectionsAdministrationController);
|
||||
const connectionsResource = useService(ConnectionsResource);
|
||||
|
||||
useEffect(() => () => {
|
||||
connectionsResource.cleanNewFlags();
|
||||
}, [connectionsResource]);
|
||||
|
||||
return styled(useStyles(styles, ADMINISTRATION_TOOLS_STYLES))(
|
||||
<layout-grid as="div">
|
||||
|
||||
+1
-19
@@ -22,25 +22,7 @@ export class ConnectionsAdministrationController {
|
||||
readonly expandedItems = observable<string, boolean>(new Map());
|
||||
@computed
|
||||
get connections(): AdminConnection[] {
|
||||
return Array.from(this.connectionsResource.data.values())
|
||||
.sort((a, b) => {
|
||||
const isANew = this.connectionsResource.isNew(a.id);
|
||||
const isBNew = this.connectionsResource.isNew(b.id);
|
||||
|
||||
if (isANew && isBNew) {
|
||||
return this.connectionsResource.getNewer(a.id, b.id);
|
||||
}
|
||||
|
||||
if (isBNew) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isANew) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
return Array.from(this.connectionsResource.data.values()).sort(this.connectionsResource.compareConnections);
|
||||
}
|
||||
|
||||
@computed
|
||||
|
||||
+1
@@ -56,6 +56,7 @@ export class ConnectionsAdministrationService extends Bootstrap {
|
||||
onActivate: this.loadConnections.bind(this),
|
||||
onDeActivate: async (configuration: boolean, outside: boolean) => {
|
||||
if (outside) {
|
||||
this.connectionsResource.cleanNewFlags();
|
||||
await this.connectionInfoResource.refreshSession();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -54,21 +54,20 @@ export class ConnectionsResource extends CachedMapResource<string, AdminConnecti
|
||||
return this.data.has(id);
|
||||
}
|
||||
|
||||
isNew(id: string): boolean {
|
||||
const connection = this.get(id);
|
||||
if (!connection) {
|
||||
return false;
|
||||
}
|
||||
return (connection as ConnectionNew)[NEW_CONNECTION_SYMBOL];
|
||||
}
|
||||
|
||||
getNewer(aId: string, bId: string): number {
|
||||
const [a, b] = [this.get(aId), this.get(bId)] as ConnectionNew[];
|
||||
if (!a || !b) {
|
||||
return 0;
|
||||
compareConnections(a: AdminConnection, b: AdminConnection): number {
|
||||
if (isConnectionNew(a) && isConnectionNew(b)) {
|
||||
return b.timestamp - a.timestamp;
|
||||
}
|
||||
|
||||
return b.timestamp - a.timestamp;
|
||||
if (isConnectionNew(b)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isConnectionNew(a)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
|
||||
getEmptyConnection(): AdminConnection {
|
||||
@@ -209,3 +208,7 @@ export function isLocalConnection(connection: AdminConnection): boolean {
|
||||
export function isCloudConnection(connection: AdminConnection): boolean {
|
||||
return connection.origin.type === 'cloud';
|
||||
}
|
||||
|
||||
export function isConnectionNew(connection: AdminConnection | ConnectionNew): connection is ConnectionNew {
|
||||
return (connection as ConnectionNew)[NEW_CONNECTION_SYMBOL];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user