feat: multi-workspace (frontend) (#4232)
* select workspace component * generateJWT mutation * workspaces state and hooks * requested changes * mutation fix * requested changes * user workpsace delete call * migration to drop and createt user workspace * revert select props * add DropdownMenu * seperate multi-workspace dropdown as component * Signup button displayed accurately * update seed data for multi-workspace * lint fix * lint fix * css fix * lint fix * state fix * isDefined check * refactor * add default workspace constants for logo and name * update migration * lint fix * isInviteMode check on sign-in/up * removeWorkspaceMember mutation * import fixes * prop name fix * backfill migration * handle edge cases * refactor * remove migration query * delete user on no-workspace found condition * emit workspaceMember.deleted * Fix event class and unrelated fix linked to a previously missing dependency * Edit migration (I did it in prod manually) * Revert changes * Fix tests * Fix conflicts --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -15,6 +15,10 @@ import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/work
|
||||
import { WorkspaceSyncMetadataService } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service';
|
||||
import { seedCalendarEvents } from 'src/database/typeorm-seeds/workspace/calendar-events';
|
||||
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
|
||||
import {
|
||||
SeedAppleWorkspaceId,
|
||||
SeedTwentyWorkspaceId,
|
||||
} from 'src/database/typeorm-seeds/core/workspaces';
|
||||
|
||||
// TODO: implement dry-run
|
||||
@Command({
|
||||
@ -23,7 +27,7 @@ import { EnvironmentService } from 'src/engine/integrations/environment/environm
|
||||
'Seed workspace with initial data. This command is intended for development only.',
|
||||
})
|
||||
export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
workspaceId = '20202020-1c25-4d02-bf25-6aeccf7ea419';
|
||||
workspaceIds = [SeedAppleWorkspaceId, SeedTwentyWorkspaceId];
|
||||
|
||||
constructor(
|
||||
private readonly environmentService: EnvironmentService,
|
||||
@ -45,79 +49,88 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
schema: 'core',
|
||||
});
|
||||
|
||||
await dataSource.initialize();
|
||||
for (const workspaceId of this.workspaceIds) {
|
||||
await dataSource.initialize();
|
||||
|
||||
await seedCoreSchema(dataSource, this.workspaceId);
|
||||
await seedCoreSchema(dataSource, workspaceId);
|
||||
|
||||
await dataSource.destroy();
|
||||
await dataSource.destroy();
|
||||
|
||||
const schemaName =
|
||||
await this.workspaceDataSourceService.createWorkspaceDBSchema(
|
||||
this.workspaceId,
|
||||
);
|
||||
const schemaName =
|
||||
await this.workspaceDataSourceService.createWorkspaceDBSchema(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.createDataSourceMetadata(
|
||||
this.workspaceId,
|
||||
schemaName,
|
||||
);
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.createDataSourceMetadata(
|
||||
workspaceId,
|
||||
schemaName,
|
||||
);
|
||||
|
||||
await this.workspaceSyncMetadataService.synchronize({
|
||||
workspaceId: this.workspaceId,
|
||||
dataSourceId: dataSourceMetadata.id,
|
||||
});
|
||||
await this.workspaceSyncMetadataService.synchronize({
|
||||
workspaceId: workspaceId,
|
||||
dataSourceId: dataSourceMetadata.id,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||
this.workspaceId,
|
||||
);
|
||||
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('Could not connect to workspace data source');
|
||||
}
|
||||
|
||||
try {
|
||||
const objectMetadata =
|
||||
await this.objectMetadataService.findManyWithinWorkspace(
|
||||
this.workspaceId,
|
||||
for (const workspaceId of this.workspaceIds) {
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||
workspaceId,
|
||||
);
|
||||
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
|
||||
acc[object.nameSingular] = {
|
||||
id: object.id,
|
||||
fields: object.fields.reduce((acc, field) => {
|
||||
acc[field.name] = field.id;
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('Could not connect to workspace data source');
|
||||
}
|
||||
|
||||
await seedCompanies(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedPeople(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedPipelineStep(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedOpportunity(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedCalendarEvents(workspaceDataSource, dataSourceMetadata.schema);
|
||||
try {
|
||||
const objectMetadata =
|
||||
await this.objectMetadataService.findManyWithinWorkspace(workspaceId);
|
||||
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
|
||||
acc[object.nameSingular] = {
|
||||
id: object.id,
|
||||
fields: object.fields.reduce((acc, field) => {
|
||||
acc[field.name] = field.id;
|
||||
|
||||
await seedViews(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
objectMetadataMap,
|
||||
);
|
||||
await seedWorkspaceMember(workspaceDataSource, dataSourceMetadata.schema);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
await seedCompanies(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedPeople(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedPipelineStep(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedOpportunity(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedCalendarEvents(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
);
|
||||
|
||||
await seedViews(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
objectMetadataMap,
|
||||
);
|
||||
await seedWorkspaceMember(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
workspaceId,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
await this.typeORMService.disconnectFromDataSource(dataSourceMetadata.id);
|
||||
}
|
||||
|
||||
await this.typeORMService.disconnectFromDataSource(dataSourceMetadata.id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user