Skip to content

Commit

Permalink
Added workspace Id tracking (#3637)
Browse files Browse the repository at this point in the history
* Added workspace Id tracking

* updated workspace id to correct snake_case
  • Loading branch information
JR-Morgan authored Oct 15, 2024
1 parent 2d9942b commit 0230748
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
24 changes: 24 additions & 0 deletions Core/Core/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Serilog.Core.Enrichers;
using Serilog.Events;
using Speckle.Core.Api.GraphQL;
using Speckle.Core.Api.GraphQL.Models.Responses;
using Speckle.Core.Api.GraphQL.Resources;
using Speckle.Core.Api.GraphQL.Serializer;
using Speckle.Core.Credentials;
Expand Down Expand Up @@ -372,4 +373,27 @@ private static HttpClient CreateHttpClient(Account account)
);
return httpClient;
}

public async Task<string?> GetWorkspaceId(string projectId, CancellationToken cancellationToken = default)
{
Version serverVersion = await GQLClient.GetServerVersion(cancellationToken).ConfigureAwait(false);

if (serverVersion < new Version(2, 20, 6))
{
return null;
}

const string QUERY = """
query Project($projectId: String!) {
project(id: $projectId) {
workspaceId
}
}
""";

GraphQLRequest request = new() { Query = QUERY, Variables = new { projectId } };

var response = await ExecuteGraphQLRequest<ProjectResponse>(request, cancellationToken).ConfigureAwait(false);
return response.project.workspaceId;
}
}
1 change: 1 addition & 0 deletions Core/Core/Api/GraphQL/Models/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public sealed class Project
public Model model { get; init; }
public List<ModelsTreeItem> modelChildrenTree { get; init; }
public ResourceCollection<ModelsTreeItem> modelsTree { get; init; }
public string workspaceId { get; init; }
}
10 changes: 8 additions & 2 deletions DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,8 @@ public async void SendCommand()
LastUsedTime = DateTime.UtcNow;
var view = MainViewModel.RouterInstance.NavigationStack.Last() is StreamViewModel ? "Stream" : "Home";

string? workspaceId = await Client.GetWorkspaceId(StreamState.StreamId).ConfigureAwait(false);

Analytics.TrackEvent(
Client.Account,
Analytics.Events.Send,
Expand All @@ -1420,7 +1422,8 @@ public async void SendCommand()
{ "isMain", SelectedBranch.Branch.name == "main" ? true : false },
{ "branches", Stream.branches?.totalCount },
{ "commits", Stream.commits?.totalCount },
{ "savedStreams", HomeViewModel.Instance.SavedStreams?.Count }
{ "savedStreams", HomeViewModel.Instance.SavedStreams?.Count },
{ "workspace_id", workspaceId },
}
);

Expand Down Expand Up @@ -1548,6 +1551,8 @@ public async void ReceiveCommand()
var view = MainViewModel.RouterInstance.NavigationStack.Last() is StreamViewModel ? "Stream" : "Home";
LastUsedTime = DateTime.UtcNow;

string? workspaceId = await Client.GetWorkspaceId(StreamState.StreamId).ConfigureAwait(false);

Analytics.TrackEvent(
StreamState.Client.Account,
Analytics.Events.Receive,
Expand All @@ -1563,7 +1568,8 @@ public async void ReceiveCommand()
{ "branches", Stream.branches?.totalCount },
{ "commits", Stream.commits?.totalCount },
{ "savedStreams", HomeViewModel.Instance.SavedStreams?.Count },
{ "isMultiplayer", state.LastCommit != null ? state.LastCommit.authorId != state.UserId : false }
{ "isMultiplayer", state.LastCommit != null ? state.LastCommit.authorId != state.UserId : false },
{ "workspace_id", workspaceId },
}
);

Expand Down

0 comments on commit 0230748

Please sign in to comment.