Skip to content

Commit

Permalink
CB-4461 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Sep 16, 2024
1 parent 5df3f4c commit ee4b614
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { injectable } from '@cloudbeaver/core-di';
import { CachedMapAllKey, CachedMapResource, isResourceAlias, ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource';
import { GraphQLService } from '@cloudbeaver/core-sdk';

import { TeamMetaParameter } from './TeamMetaParametersResource';
import type { TeamMetaParameter } from './TeamMetaParametersResource';
import { TeamsResource } from './TeamsResource';

@injectable()
Expand Down Expand Up @@ -56,6 +56,10 @@ export class TeamInfoMetaParametersResource extends CachedMapResource<string, Te
return this.data;
}

async setMetaParameters(teamId: string, parameters: Record<string, any>): Promise<void> {
await this.graphQLService.sdk.saveTeamMetaParameters({ teamId, parameters });
}

protected validateKey(key: string): boolean {
return typeof key === 'string';
}
Expand Down
18 changes: 3 additions & 15 deletions webapp/packages/core-authentication/src/TeamsResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '@cloudbeaver/core-sdk';
import { isArraysEqual, UndefinedToNull } from '@cloudbeaver/core-utils';

import { TeamMetaParameter } from './TeamMetaParametersResource';
import type { TeamMetaParameter } from './TeamMetaParametersResource';

const NEW_TEAM_SYMBOL = Symbol('new-team');

Expand All @@ -40,10 +40,7 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou
super();
}

async createTeam(
{ teamId, teamPermissions, teamName, description }: TeamInfo,
metaParameters: Record<string, TeamMetaParameter>,
): Promise<TeamInfo> {
async createTeam({ teamId, teamPermissions, teamName, description }: TeamInfo): Promise<TeamInfo> {
const response = await this.graphQLService.sdk.createTeam({
teamId,
teamName,
Expand All @@ -59,16 +56,12 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou

this.set(newTeam.teamId, newTeam);

await this.setMetaParameters(newTeam.teamId, metaParameters);
await this.setSubjectPermissions(newTeam.teamId, teamPermissions);

return this.get(teamId)!;
}

async updateTeam(
{ teamId, teamPermissions, teamName, description }: TeamInfo,
metaParameters: Record<string, TeamMetaParameter>,
): Promise<TeamInfo> {
async updateTeam({ teamId, teamPermissions, teamName, description }: TeamInfo): Promise<TeamInfo> {
const { team } = await this.graphQLService.sdk.updateTeam({
teamId,
teamName,
Expand All @@ -78,7 +71,6 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou

this.set(team.teamId, team);

await this.setMetaParameters(team.teamId, metaParameters);
await this.setSubjectPermissions(team.teamId, teamPermissions);

this.markOutdated(team.teamId);
Expand Down Expand Up @@ -125,10 +117,6 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou
}
}

async setMetaParameters(teamId: string, parameters: Record<string, any>): Promise<void> {
await this.graphQLService.sdk.saveTeamMetaParameters({ teamId, parameters });
}

protected async loader(originalKey: ResourceKey<string>, includes?: string[]): Promise<Map<string, TeamInfo>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const teamsList: TeamInfo[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CachedDataResource, ResourceKey } from '@cloudbeaver/core-resource';
import { GraphQLService } from '@cloudbeaver/core-sdk';

import { UserInfoResource } from './UserInfoResource';
import { UserMetaParameter } from './UserMetaParametersResource';
import type { UserMetaParameter } from './UserMetaParametersResource';

@injectable()
export class UserInfoMetaParametersResource extends CachedDataResource<UserMetaParameter | null> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@cloudbeaver/core-resource';
import { GraphQLService } from '@cloudbeaver/core-sdk';

import { UserMetaParameter } from './UserMetaParametersResource';
import type { UserMetaParameter } from './UserMetaParametersResource';
import { UsersResource, UsersResourceFilterKey } from './UsersResource';

@injectable()
Expand All @@ -39,7 +39,6 @@ export class UsersMetaParametersResource extends CachedMapResource<string, UserM
this.markOutdated(userId);
}

// TODO after CB-5511 is merged. fix the logic according to the UsersResource loader
protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, UserMetaParameter>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const keys: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { TeamInfoConfig } from '../ITeamFormProps';
import type { TeamInfoConfig } from '../ITeamFormProps';

export function teamContext(): TeamInfoConfig {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import React from 'react';

import { TeamsResource } from '@cloudbeaver/core-authentication';
import { TeamInfoMetaParametersResource, TeamsResource } from '@cloudbeaver/core-authentication';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
import { LocalizationService } from '@cloudbeaver/core-localization';
Expand All @@ -27,6 +27,7 @@ export class TeamOptionsTabService extends Bootstrap {
constructor(
private readonly teamFormService: TeamFormService,
private readonly teamResource: TeamsResource,
private readonly teamsMetaParametersResource: TeamInfoMetaParametersResource,
private readonly localizationService: LocalizationService,
) {
super();
Expand Down Expand Up @@ -108,11 +109,18 @@ export class TeamOptionsTabService extends Bootstrap {

try {
if (create) {
const team = await this.teamResource.createTeam(config, metaParameters);
const [team] = await Promise.all([
this.teamResource.createTeam(config),
this.teamsMetaParametersResource.setMetaParameters(config.teamId, metaParameters),
]);

status.info('administration_teams_team_info_created');
status.info(team.teamId);
} else {
const team = await this.teamResource.updateTeam(config, metaParameters);
const [team] = await Promise.all([
this.teamResource.updateTeam(config),
this.teamsMetaParametersResource.setMetaParameters(config.teamId, metaParameters),
]);

status.info('administration_teams_team_info_updated');
status.info(team.teamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export class TeamFormState implements ITeamFormState {
return;
}

await this.resource.load(data.config.teamId);
await this.teamInfoMetaParametersResource.load(data.config.teamId);
await Promise.all([this.resource.load(data.config.teamId), this.teamInfoMetaParametersResource.load(data.config.teamId)]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
const metaParameters = toJS(this.state.metaParameters);

if (this.state.userId) {
const user = this.usersResource.get(this.state.userId);
const userMetaParameters = this.usersMetaParametersResource.get(this.state.userId);

if (user && isObjectsEqual(userMetaParameters, metaParameters)) {
if (userMetaParameters && isObjectsEqual(userMetaParameters, metaParameters)) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { NotificationService } from '@cloudbeaver/core-events';
import { LocalizationService } from '@cloudbeaver/core-localization';
import { isGlobalProject, isSharedProject, ProjectInfoResource, projectInfoSortByName } from '@cloudbeaver/core-projects';
import { resourceKeyList } from '@cloudbeaver/core-resource';
import { DatabaseConnectionOriginFragment } from '@cloudbeaver/core-sdk';
import type { DatabaseConnectionOriginFragment } from '@cloudbeaver/core-sdk';
import { isArraysEqual, isDefined, isObjectsEqual } from '@cloudbeaver/core-utils';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dial
import { NotificationService } from '@cloudbeaver/core-events';
import { CachedMapAllKey } from '@cloudbeaver/core-resource';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { DatabaseConnectionOriginFragment } from '@cloudbeaver/core-sdk';
import type { DatabaseConnectionOriginFragment } from '@cloudbeaver/core-sdk';

import { CreateConnectionService } from './CreateConnectionService';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { PasswordPolicyService, UserInfoMetaParametersResource, UserInfoResource, UserResourceIncludes } from '@cloudbeaver/core-authentication';
import type { PasswordPolicyService, UserInfoMetaParametersResource, UserInfoResource } from '@cloudbeaver/core-authentication';
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
import { FormPart, formValidationContext, IFormState } from '@cloudbeaver/core-ui';
import { isValuesEqual, schemaValidationError } from '@cloudbeaver/core-utils';
Expand Down

0 comments on commit ee4b614

Please sign in to comment.