mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 19:58:09 +00:00
Add more github analytics (#6506)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
9a9d7195bf
commit
87b8e59969
@ -29,6 +29,7 @@ import {
|
|||||||
type DocAttributeRule,
|
type DocAttributeRule,
|
||||||
type DocCreateExtension,
|
type DocCreateExtension,
|
||||||
type DocCreateFunction,
|
type DocCreateFunction,
|
||||||
|
type DocCreateAnalyticsPropsFunction,
|
||||||
type DocRules,
|
type DocRules,
|
||||||
type FileOrBlob,
|
type FileOrBlob,
|
||||||
type FilePreviewExtension,
|
type FilePreviewExtension,
|
||||||
@ -42,7 +43,14 @@ import presentation from './plugin'
|
|||||||
|
|
||||||
export { presentationId } from '@hcengineering/presentation/src/plugin'
|
export { presentationId } from '@hcengineering/presentation/src/plugin'
|
||||||
export { default } from './plugin'
|
export { default } from './plugin'
|
||||||
export type { CreateExtensionKind, DocCreateExtension, DocCreateFunction, ObjectSearchCategory, ObjectSearchFactory }
|
export type {
|
||||||
|
CreateExtensionKind,
|
||||||
|
DocCreateExtension,
|
||||||
|
DocCreateFunction,
|
||||||
|
ObjectSearchCategory,
|
||||||
|
ObjectSearchFactory,
|
||||||
|
DocCreateAnalyticsPropsFunction
|
||||||
|
}
|
||||||
|
|
||||||
@Model(presentation.class.ObjectSearchCategory, core.class.Doc, DOMAIN_MODEL)
|
@Model(presentation.class.ObjectSearchCategory, core.class.Doc, DOMAIN_MODEL)
|
||||||
export class TObjectSearchCategory extends TDoc implements ObjectSearchCategory {
|
export class TObjectSearchCategory extends TDoc implements ObjectSearchCategory {
|
||||||
@ -76,6 +84,7 @@ export class TDocCreateExtension extends TDoc implements DocCreateExtension {
|
|||||||
|
|
||||||
components!: Record<CreateExtensionKind, AnyComponent>
|
components!: Record<CreateExtensionKind, AnyComponent>
|
||||||
apply!: Resource<DocCreateFunction>
|
apply!: Resource<DocCreateFunction>
|
||||||
|
getAnalyticsProps?: Resource<(doc: Doc) => Record<string, string>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Model(presentation.class.DocRules, core.class.Doc, DOMAIN_MODEL)
|
@Model(presentation.class.DocRules, core.class.Doc, DOMAIN_MODEL)
|
||||||
|
@ -65,6 +65,20 @@ export class DocCreateExtensionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAnalyticsProps (space: Space, data: DocData<Doc>): Promise<Record<string, string>> {
|
||||||
|
let result: Record<string, string> = {}
|
||||||
|
for (const e of this._extensions) {
|
||||||
|
if (e.getAnalyticsProps === undefined) continue
|
||||||
|
const state = get(this.getState(e._id))
|
||||||
|
const fn = await getResource(e.getAnalyticsProps)
|
||||||
|
const props = fn?.(space, data, state)
|
||||||
|
|
||||||
|
result = { ...result, ...props }
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
close (): void {
|
close (): void {
|
||||||
this.query.unsubscribe()
|
this.query.unsubscribe()
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,12 @@ export type DocCreateFunction = (
|
|||||||
phase: DocCreatePhase
|
phase: DocCreatePhase
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
|
|
||||||
|
export type DocCreateAnalyticsPropsFunction = (
|
||||||
|
space: Space,
|
||||||
|
document: DocData<Doc>,
|
||||||
|
extraData: Record<string, any>
|
||||||
|
) => Record<string, any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -123,6 +129,7 @@ export interface DocCreateExtension extends Doc {
|
|||||||
|
|
||||||
components: Partial<Record<CreateExtensionKind, AnyComponent>>
|
components: Partial<Record<CreateExtensionKind, AnyComponent>>
|
||||||
apply: Resource<DocCreateFunction>
|
apply: Resource<DocCreateFunction>
|
||||||
|
getAnalyticsProps?: Resource<DocCreateAnalyticsPropsFunction>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DocAttributeRule {
|
export interface DocAttributeRule {
|
||||||
|
@ -575,10 +575,12 @@
|
|||||||
descriptionBox?.removeDraft(false)
|
descriptionBox?.removeDraft(false)
|
||||||
isAssigneeTouched = false
|
isAssigneeTouched = false
|
||||||
const d1 = Date.now()
|
const d1 = Date.now()
|
||||||
|
const analyticsProps = await docCreateManager.getAnalyticsProps(currentProject, value)
|
||||||
Analytics.handleEvent(TrackerEvents.IssueCreated, {
|
Analytics.handleEvent(TrackerEvents.IssueCreated, {
|
||||||
ok: true,
|
ok: true,
|
||||||
id: value.identifier,
|
id: value.identifier,
|
||||||
project: currentProject.identifier
|
project: currentProject.identifier,
|
||||||
|
...analyticsProps
|
||||||
})
|
})
|
||||||
console.log('createIssue measure', result, Date.now() - d1)
|
console.log('createIssue measure', result, Date.now() - d1)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Analytics.handleEvent('Connect project to github')
|
Analytics.handleEvent('github.project.connected', { project: projectInst.identifier, repository: repository._id })
|
||||||
|
|
||||||
if (!client.getHierarchy().hasMixin(projectInst, github.mixin.GithubProject)) {
|
if (!client.getHierarchy().hasMixin(projectInst, github.mixin.GithubProject)) {
|
||||||
// We need to add GithubProject mixin
|
// We need to add GithubProject mixin
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
showPopup
|
showPopup
|
||||||
} from '@hcengineering/ui'
|
} from '@hcengineering/ui'
|
||||||
import { ObjectPresenter } from '@hcengineering/view-resources'
|
import { ObjectPresenter } from '@hcengineering/view-resources'
|
||||||
|
import { Analytics } from '@hcengineering/analytics'
|
||||||
|
|
||||||
import github from '../plugin'
|
import github from '../plugin'
|
||||||
import ConnectProject from './ConnectProject.svelte'
|
import ConnectProject from './ConnectProject.svelte'
|
||||||
import { githubLanguageColors } from './languageColors'
|
import { githubLanguageColors } from './languageColors'
|
||||||
@ -45,6 +47,10 @@
|
|||||||
await client.update(prj, {
|
await client.update(prj, {
|
||||||
$pull: { repositories: repository._id }
|
$pull: { repositories: repository._id }
|
||||||
})
|
})
|
||||||
|
Analytics.handleEvent('github.project.disconnected', {
|
||||||
|
project: prj.identifier,
|
||||||
|
repository: repository._id
|
||||||
|
})
|
||||||
// // We need to delete all issues related to repository
|
// // We need to delete all issues related to repository
|
||||||
// const ops = client.apply('cleanup:' + repository._id)
|
// const ops = client.apply('cleanup:' + repository._id)
|
||||||
// const issuesQuery = await client.findAll(
|
// const issuesQuery = await client.findAll(
|
||||||
|
@ -4,7 +4,12 @@
|
|||||||
|
|
||||||
import { type Data, type Ref, type Space, type TxOperations } from '@hcengineering/core'
|
import { type Data, type Ref, type Space, type TxOperations } from '@hcengineering/core'
|
||||||
import { type Resources } from '@hcengineering/platform'
|
import { type Resources } from '@hcengineering/platform'
|
||||||
import { getClient, type DocCreateFunction, type DocCreatePhase } from '@hcengineering/presentation'
|
import {
|
||||||
|
getClient,
|
||||||
|
type DocCreateFunction,
|
||||||
|
type DocCreatePhase,
|
||||||
|
type DocCreateAnalyticsPropsFunction
|
||||||
|
} from '@hcengineering/presentation'
|
||||||
import tracker, { type Issue } from '@hcengineering/tracker'
|
import tracker, { type Issue } from '@hcengineering/tracker'
|
||||||
import { type GithubIntegrationRepository } from '@hcengineering/github'
|
import { type GithubIntegrationRepository } from '@hcengineering/github'
|
||||||
import AuthenticationCheck from './components/AuthenticationCheck.svelte'
|
import AuthenticationCheck from './components/AuthenticationCheck.svelte'
|
||||||
@ -51,6 +56,25 @@ async function updateIssue (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCreateIssueAnalyticsProps (
|
||||||
|
space: Space,
|
||||||
|
issue: Data<Issue>,
|
||||||
|
settings: Record<string, any>
|
||||||
|
): Record<string, any> {
|
||||||
|
const hierarchy = getClient().getHierarchy()
|
||||||
|
if (hierarchy.hasMixin(space, github.mixin.GithubProject)) {
|
||||||
|
const repository = settings.repository as Ref<GithubIntegrationRepository>
|
||||||
|
if (repository == null) return {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
github: true,
|
||||||
|
githubRepository: repository
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
export default async (): Promise<Resources> => ({
|
export default async (): Promise<Resources> => ({
|
||||||
component: {
|
component: {
|
||||||
Connect,
|
Connect,
|
||||||
@ -85,6 +109,7 @@ export default async (): Promise<Resources> => ({
|
|||||||
const client = getClient()
|
const client = getClient()
|
||||||
return spaces.some((it) => client.getHierarchy().hasMixin(it, github.mixin.GithubProject))
|
return spaces.some((it) => client.getHierarchy().hasMixin(it, github.mixin.GithubProject))
|
||||||
},
|
},
|
||||||
UpdateIssue: updateIssue as DocCreateFunction
|
UpdateIssue: updateIssue as DocCreateFunction,
|
||||||
|
GetCreateIssueAnalyticsProps: getCreateIssueAnalyticsProps as DocCreateAnalyticsPropsFunction
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -655,6 +655,7 @@ export function createModel (builder: Builder): void {
|
|||||||
builder.createDoc(presentation.class.DocCreateExtension, core.space.Model, {
|
builder.createDoc(presentation.class.DocCreateExtension, core.space.Model, {
|
||||||
ofClass: tracker.class.Issue,
|
ofClass: tracker.class.Issue,
|
||||||
apply: github.functions.UpdateIssue,
|
apply: github.functions.UpdateIssue,
|
||||||
|
getAnalyticsProps: github.functions.GetCreateIssueAnalyticsProps,
|
||||||
components: {
|
components: {
|
||||||
createButton: github.component.GithubIssueInfoHeader
|
createButton: github.component.GithubIssueInfoHeader
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,11 @@ import github from '@hcengineering/github-resources/src/plugin'
|
|||||||
|
|
||||||
import { type ChatMessageViewlet } from '@hcengineering/chunter'
|
import { type ChatMessageViewlet } from '@hcengineering/chunter'
|
||||||
import { type Doc, type Ref, type Space } from '@hcengineering/core'
|
import { type Doc, type Ref, type Space } from '@hcengineering/core'
|
||||||
import { type DocCreateFunction, type ObjectSearchCategory } from '@hcengineering/model-presentation'
|
import {
|
||||||
|
type DocCreateFunction,
|
||||||
|
type ObjectSearchCategory,
|
||||||
|
type DocCreateAnalyticsPropsFunction
|
||||||
|
} from '@hcengineering/model-presentation'
|
||||||
import { type NotificationGroup } from '@hcengineering/notification'
|
import { type NotificationGroup } from '@hcengineering/notification'
|
||||||
import type { AnyComponent } from '@hcengineering/ui'
|
import type { AnyComponent } from '@hcengineering/ui'
|
||||||
import { type ActionCategory, type Viewlet } from '@hcengineering/view'
|
import { type ActionCategory, type Viewlet } from '@hcengineering/view'
|
||||||
@ -55,7 +59,8 @@ export default mergeIds(githubId, github, {
|
|||||||
},
|
},
|
||||||
functions: {
|
functions: {
|
||||||
ShowForRepositoryOnly: '' as Resource<(spaces: Space[]) => Promise<boolean>>,
|
ShowForRepositoryOnly: '' as Resource<(spaces: Space[]) => Promise<boolean>>,
|
||||||
UpdateIssue: '' as Resource<DocCreateFunction>
|
UpdateIssue: '' as Resource<DocCreateFunction>,
|
||||||
|
GetCreateIssueAnalyticsProps: '' as Resource<DocCreateAnalyticsPropsFunction>
|
||||||
},
|
},
|
||||||
ids: {
|
ids: {
|
||||||
AssigneeNotification: '' as Ref<Doc>,
|
AssigneeNotification: '' as Ref<Doc>,
|
||||||
|
Loading…
Reference in New Issue
Block a user