Skip to content

Commit

Permalink
feat: Frontend + fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Jul 12, 2023
1 parent 909481a commit d27dbf2
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@CrossOrigin(origins = ["*"])
@RequestMapping(value = ["/v2/business-events"])
@Tag(name = "Reports business events from frontend app")
@Tag(name = "Business events reporting")
class BusinessEventController(
private val businessEventPublisher: BusinessEventPublisher,
private val securityService: SecurityService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.tolgee.testing.assert
import net.javacrumbs.jsonunit.assertj.JsonAssert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.mockito.kotlin.any
import org.mockito.kotlin.argThat
import org.mockito.kotlin.eq
Expand All @@ -35,6 +36,7 @@ class ActivityLogTest : ProjectAuthControllerTest("/v2/projects/") {

@BeforeEach
fun setup() {
Mockito.reset(postHog)
testData = BaseTestData()
testData.user.name = "Franta"
testData.projectBuilder.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter
import org.springframework.web.method.HandlerMethod
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.util.*
import javax.servlet.FilterChain
Expand Down Expand Up @@ -52,7 +53,8 @@ class ActivityFilter(
}

fun parseUtmValues(headerValue: String?): Map<String, Any?>? {
val base64Decoded = Base64.getDecoder().decode(headerValue)
val urlDecoded = URLDecoder.decode(headerValue, StandardCharsets.UTF_8)
val base64Decoded = Base64.getDecoder().decode(urlDecoded)
val utmParamsJson = String(base64Decoded, StandardCharsets.UTF_8)
val utmParams = mutableMapOf<String, String>()
return jacksonObjectMapper().readValue(utmParamsJson, utmParams::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class BusinessEventPublisher(
applicationEventPublisher.publishEvent(
event.copy(
utmData = event.utmData ?: getUtmData(),
userAccountId = authenticationFacade.userAccount.id,
userAccountDto = authenticationFacade.userAccount
userAccountId = authenticationFacade.userAccountOrNull?.id,
userAccountDto = authenticationFacade.userAccountOrNull
)
)
}
Expand Down
14 changes: 9 additions & 5 deletions webapp/src/hooks/useProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { components } from '../service/apiSchema.generated';
import { ProjectContext } from './ProjectProvider';

export const useProject = (): components['schemas']['ProjectModel'] => {
const { project } = useProjectSettings();
const { project } = useProjectContext();
return project;
};

export const useProjectSettings = () => {
const projectDTOLoadable = useContext(ProjectContext);
if (!projectDTOLoadable) {
export function useProjectContextOptional() {
return useContext(ProjectContext);
}

export const useProjectContext = () => {
const projectContext = useProjectContextOptional();
if (!projectContext) {
throw new GlobalError(
'Unexpected error',
'No data in loadable? Did you use provider before using hook?'
);
}

return projectDTOLoadable;
return projectContext;
};
108 changes: 71 additions & 37 deletions webapp/src/service/apiSchema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ export interface paths {
"/v2/ee-license/prepare-set-license-key": {
post: operations["prepareSetLicenseKey"];
};
"/v2/business-events/report": {
post: operations["report"];
};
"/v2/api-keys": {
get: operations["allByUser"];
post: operations["create_10"];
Expand Down Expand Up @@ -558,14 +561,6 @@ export interface components {
| "ORGANIZATION_OWNER"
| "NONE"
| "SERVER_ADMIN";
/**
* @deprecated
* @description Deprecated (use translateLanguageIds).
*
* List of languages current user has TRANSLATE permission to. If null, all languages edition is permitted.
* @example 200001,200004
*/
permittedLanguageIds?: number[];
/**
* @description List of languages user can translate to. If null, all languages editing is permitted.
* @example 200001,200004
Expand All @@ -581,6 +576,14 @@ export interface components {
* @example 200001,200004
*/
viewLanguageIds?: number[];
/**
* @deprecated
* @description Deprecated (use translateLanguageIds).
*
* List of languages current user has TRANSLATE permission to. If null, all languages edition is permitted.
* @example 200001,200004
*/
permittedLanguageIds?: number[];
/**
* @description Granted scopes to the user. When user has type permissions, this field contains permission scopes of the type.
* @example KEYS_EDIT,TRANSLATIONS_VIEW
Expand Down Expand Up @@ -1138,12 +1141,12 @@ export interface components {
/** Format: int64 */
updatedAt: number;
/** Format: int64 */
expiresAt?: number;
/** Format: int64 */
lastUsedAt?: number;
description: string;
/** Format: int64 */
expiresAt?: number;
/** Format: int64 */
id: number;
description: string;
};
SetOrganizationRoleDto: {
roleType: "MEMBER" | "OWNER";
Expand Down Expand Up @@ -1274,19 +1277,19 @@ export interface components {
RevealedApiKeyModel: {
/** @description Resulting user's api key */
key: string;
projectName: string;
userFullName?: string;
username?: string;
/** Format: int64 */
projectId: number;
/** Format: int64 */
expiresAt?: number;
/** Format: int64 */
lastUsedAt?: number;
username?: string;
/** Format: int64 */
expiresAt?: number;
projectName: string;
userFullName?: string;
scopes: string[];
description: string;
/** Format: int64 */
id: number;
description: string;
};
SuperTokenRequest: {
/** @description Has to be provided when TOTP enabled */
Expand Down Expand Up @@ -1638,6 +1641,14 @@ export interface components {
credits?: components["schemas"]["SumUsageItemModel"];
total: number;
};
BusinessEventReportRequest: {
eventName: string;
/** Format: int64 */
organizationId?: number;
/** Format: int64 */
projectId?: number;
data?: { [key: string]: { [key: string]: unknown } };
};
CreateApiKeyDto: {
/** Format: int64 */
projectId: number;
Expand Down Expand Up @@ -1759,22 +1770,22 @@ export interface components {
| "ACCOUNT_MANAGER"
| "STANDARD_SUPPORT"
)[];
basePermissions: components["schemas"]["PermissionModel"];
/**
* @description The role of currently authorized user.
*
* Can be null when user has direct access to one of the projects owned by the organization.
*/
currentUserRole?: "MEMBER" | "OWNER";
avatar?: components["schemas"]["Avatar"];
/** @example btforg */
slug: string;
/** @example This is a beautiful organization full of beautiful and clever people */
description?: string;
basePermissions: components["schemas"]["PermissionModel"];
avatar?: components["schemas"]["Avatar"];
/** @example Beautiful organization */
name: string;
/** Format: int64 */
id: number;
/** @example This is a beautiful organization full of beautiful and clever people */
description?: string;
};
PublicBillingConfigurationDTO: {
enabled: boolean;
Expand Down Expand Up @@ -1806,9 +1817,9 @@ export interface components {
postHogHost?: string;
};
DocItem: {
description?: string;
displayName?: string;
name: string;
displayName?: string;
description?: string;
};
PagedModelProjectModel: {
_embedded?: {
Expand Down Expand Up @@ -1872,18 +1883,18 @@ export interface components {
extraCreditBalance: number;
};
KeySearchResultView: {
baseTranslation?: string;
namespace?: string;
translation?: string;
namespace?: string;
baseTranslation?: string;
name: string;
/** Format: int64 */
id: number;
};
KeySearchSearchResultModel: {
view?: components["schemas"]["KeySearchResultView"];
baseTranslation?: string;
namespace?: string;
translation?: string;
namespace?: string;
baseTranslation?: string;
name: string;
/** Format: int64 */
id: number;
Expand Down Expand Up @@ -2007,7 +2018,6 @@ export interface components {
page?: components["schemas"]["PageMetadata"];
};
EntityModelImportFileIssueView: {
params: components["schemas"]["ImportFileIssueParamView"][];
/** Format: int64 */
id: number;
type:
Expand All @@ -2020,6 +2030,7 @@ export interface components {
| "ID_ATTRIBUTE_NOT_PROVIDED"
| "TARGET_NOT_PROVIDED"
| "TRANSLATION_TOO_LONG";
params: components["schemas"]["ImportFileIssueParamView"][];
};
ImportFileIssueParamView: {
value?: string;
Expand Down Expand Up @@ -2322,12 +2333,12 @@ export interface components {
/** Format: int64 */
updatedAt: number;
/** Format: int64 */
expiresAt?: number;
/** Format: int64 */
lastUsedAt?: number;
description: string;
/** Format: int64 */
expiresAt?: number;
/** Format: int64 */
id: number;
description: string;
};
OrganizationRequestParamsDto: {
filterCurrentUserOwner: boolean;
Expand Down Expand Up @@ -2444,19 +2455,19 @@ export interface components {
* If null, all languages are permitted.
*/
permittedLanguageIds?: number[];
projectName: string;
userFullName?: string;
username?: string;
/** Format: int64 */
projectId: number;
/** Format: int64 */
expiresAt?: number;
/** Format: int64 */
lastUsedAt?: number;
username?: string;
/** Format: int64 */
expiresAt?: number;
projectName: string;
userFullName?: string;
scopes: string[];
description: string;
/** Format: int64 */
id: number;
description: string;
};
PagedModelUserAccountModel: {
_embedded?: {
Expand Down Expand Up @@ -5708,6 +5719,29 @@ export interface operations {
};
};
};
report: {
responses: {
/** OK */
200: unknown;
/** Bad Request */
400: {
content: {
"*/*": string;
};
};
/** Not Found */
404: {
content: {
"*/*": string;
};
};
};
requestBody: {
content: {
"application/json": components["schemas"]["BusinessEventReportRequest"];
};
};
};
allByUser: {
parameters: {
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PrivateRoute } from 'tg.component/common/PrivateRoute';
import { Box, ButtonGroup } from '@mui/material';
import { SelfHostedEeSubscriptions } from './selfHostedEe/SelfHostedEeSubscriptions';
import { ButtonGroupRouterItem } from 'tg.component/common/ButtonGroupRouter';
import { useReportEvent } from '../../useReportEvent';

export const OrganizationSubscriptionsView: FunctionComponent = () => {
const { search, pathname } = useLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { useGlobalLoading } from 'tg.component/GlobalLoading';
import { useOrganization } from '../../../useOrganization';
import { BillingPeriodType } from './Plans/PeriodSwitch';
import { useOrganizationCreditBalance } from '../../useOrganizationCreditBalance';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { planIsPeriodDependant } from './Plans/PlanPrice';
import { useReportEvent } from '../../../useReportEvent';

const StyledShopping = styled('div')`
display: grid;
Expand Down Expand Up @@ -60,6 +61,12 @@ export const CloudSubscriptions = () => {

useGlobalLoading(activeSubscription.isLoading || plansLoadable.isLoading);

const reportEvent = useReportEvent();

useEffect(() => {
reportEvent('BILLING_CLOUD_SUBSCRIPTIONS_VIEW');
}, []);

return (
<>
{plansLoadable.data?._embedded?.plans &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { SelfHostedEePlan } from './SelfHostedEePlan';
import { SelfHostedEeActiveSubscription } from './SelfHostedEeActiveSubscription';
import { BillingPeriodType } from '../cloud/Plans/PeriodSwitch';
import { useGlobalLoading } from 'tg.component/GlobalLoading';
import { components } from 'tg.service/apiSchema.generated';
import { components } from 'tg.service/billingApiSchema.generated';
import { useReportEvent } from '../../../useReportEvent';

type SelfHostedEeSubscriptionModel =
components['schemas']['SelfHostedEeSubscriptionModel'];
Expand Down Expand Up @@ -70,6 +71,12 @@ export const SelfHostedEeSubscriptions = () => {
method: 'put',
});

const reportEvent = useReportEvent();

useEffect(() => {
reportEvent('BILLING_SELF_HOSTED_EE_SUBSCRIPTIONS_VIEW');
}, []);

useEffect(() => {
if (isSuccess) {
refreshSubscriptions.mutate(
Expand Down
Loading

0 comments on commit d27dbf2

Please sign in to comment.