From 2b8a81a05c507586c06769c997b8b90626b1c77c Mon Sep 17 00:00:00 2001 From: bosiraphael <71827178+bosiraphael@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:57:16 +0200 Subject: [PATCH] Created two new env variables (#2120) * created the two env variables * modify according to comments --- front/src/generated/graphql.tsx | 16 +++++- .../components/ClientConfigProvider.tsx | 16 ++++++ .../graphql/queries/getClientConfig.ts | 2 + .../states/isDataModelSettingsEnabled.ts | 6 ++ .../states/isDevelopersSettingsEnabled.ts | 6 ++ .../settings/components/SettingsNavbar.tsx | 57 ++++++++++++------- front/src/testing/graphqlMocks.ts | 2 + server/.env.example | 2 + server/.env.test | 2 + .../client-config/client-config.entity.ts | 6 ++ .../client-config/client-config.resolver.ts | 4 ++ .../environment/environment.service.ts | 12 ++++ .../environment/environment.validation.ts | 10 ++++ 13 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 front/src/modules/client-config/states/isDataModelSettingsEnabled.ts create mode 100644 front/src/modules/client-config/states/isDevelopersSettingsEnabled.ts diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx index b47700e4c..7b3cdc668 100644 --- a/front/src/generated/graphql.tsx +++ b/front/src/generated/graphql.tsx @@ -648,7 +648,9 @@ export type BoolFilter = { export type ClientConfig = { __typename?: 'ClientConfig'; authProviders: AuthProviders; + dataModelSettingsEnabled: Scalars['Boolean']; debugMode: Scalars['Boolean']; + developersSettingsEnabled: Scalars['Boolean']; flexibleBackendEnabled: Scalars['Boolean']; signInPrefilled: Scalars['Boolean']; support: Support; @@ -1383,6 +1385,8 @@ export type Mutation = { createOneApiKey: AuthToken; createOneComment: Comment; createOneCompany: Company; + createOneField: Field; + createOneObject: Object; createOnePerson: Person; createOnePipelineProgress: PipelineProgress; createOnePipelineStage: PipelineStage; @@ -1397,6 +1401,8 @@ export type Mutation = { deleteManyView: AffectedRows; deleteManyViewFilter: AffectedRows; deleteManyViewSort: AffectedRows; + deleteOneField: FieldDeleteResponse; + deleteOneObject: ObjectDeleteResponse; deleteOnePipelineStage: PipelineStage; deleteOneView: View; deleteUserAccount: User; @@ -1407,6 +1413,8 @@ export type Mutation = { signUp: LoginToken; updateOneActivity: Activity; updateOneCompany?: Maybe; + updateOneField: Field; + updateOneObject: Object; updateOnePerson?: Maybe; updateOnePipelineProgress?: Maybe; updateOnePipelineStage?: Maybe; @@ -2483,6 +2491,8 @@ export type Query = { clientConfig: ClientConfig; currentUser: User; currentWorkspace: Workspace; + field: Field; + fields: FieldConnection; findFavorites: Array; findManyActivities: Array; findManyApiKey: Array; @@ -2500,6 +2510,8 @@ export type Query = { findUniqueCompany: Company; findUniquePerson: Person; findWorkspaceFromInviteHash: Workspace; + object: Object; + objects: ObjectConnection; }; @@ -3769,7 +3781,7 @@ export type CheckUserExistsQuery = { __typename?: 'Query', checkUserExists: { __ export type GetClientConfigQueryVariables = Exact<{ [key: string]: never; }>; -export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, debugMode: boolean, flexibleBackendEnabled: boolean, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean }, telemetry: { __typename?: 'Telemetry', enabled: boolean, anonymizationEnabled: boolean }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null } } }; +export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, dataModelSettingsEnabled: boolean, developersSettingsEnabled: boolean, debugMode: boolean, flexibleBackendEnabled: boolean, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean }, telemetry: { __typename?: 'Telemetry', enabled: boolean, anonymizationEnabled: boolean }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null } } }; export type BaseCompanyFieldsFragmentFragment = { __typename?: 'Company', address: string, annualRecurringRevenue?: number | null, createdAt: string, domainName: string, employees?: number | null, id: string, idealCustomerProfile: boolean, linkedinUrl?: string | null, name: string, xUrl?: string | null, _activityCount: number }; @@ -5212,6 +5224,8 @@ export const GetClientConfigDocument = gql` password } signInPrefilled + dataModelSettingsEnabled + developersSettingsEnabled debugMode telemetry { enabled diff --git a/front/src/modules/client-config/components/ClientConfigProvider.tsx b/front/src/modules/client-config/components/ClientConfigProvider.tsx index be71a8ad4..b0986351f 100644 --- a/front/src/modules/client-config/components/ClientConfigProvider.tsx +++ b/front/src/modules/client-config/components/ClientConfigProvider.tsx @@ -8,6 +8,8 @@ import { supportChatState } from '@/client-config/states/supportChatState'; import { telemetryState } from '@/client-config/states/telemetryState'; import { useGetClientConfigQuery } from '~/generated/graphql'; +import { isDataModelSettingsEnabledState } from '../states/isDataModelSettingsEnabled'; +import { isDevelopersSettingsEnabledState } from '../states/isDevelopersSettingsEnabled'; import { isFlexibleBackendEnabledState } from '../states/isFlexibleBackendEnabledState'; export const ClientConfigProvider: React.FC = ({ @@ -20,6 +22,12 @@ export const ClientConfigProvider: React.FC = ({ ); const [, setIsSignInPrefilled] = useRecoilState(isSignInPrefilledState); + const [, setIsDataModelSettingsEnabled] = useRecoilState( + isDataModelSettingsEnabledState, + ); + const [, setIsDevelopersSettingsEnabled] = useRecoilState( + isDevelopersSettingsEnabledState, + ); const [, setTelemetry] = useRecoilState(telemetryState); const [isLoading, setIsLoading] = useState(true); const setSupportChat = useSetRecoilState(supportChatState); @@ -39,6 +47,12 @@ export const ClientConfigProvider: React.FC = ({ setIsFlexibleBackendEnabled(data?.clientConfig.flexibleBackendEnabled); setIsDebugMode(data?.clientConfig.debugMode); setIsSignInPrefilled(data?.clientConfig.signInPrefilled); + setIsDataModelSettingsEnabled( + data?.clientConfig.dataModelSettingsEnabled, + ); + setIsDevelopersSettingsEnabled( + data?.clientConfig.developersSettingsEnabled, + ); setTelemetry(data?.clientConfig.telemetry); setSupportChat(data?.clientConfig.support); } @@ -48,6 +62,8 @@ export const ClientConfigProvider: React.FC = ({ setIsDebugMode, setIsFlexibleBackendEnabled, setIsSignInPrefilled, + setIsDataModelSettingsEnabled, + setIsDevelopersSettingsEnabled, setTelemetry, setIsLoading, loading, diff --git a/front/src/modules/client-config/graphql/queries/getClientConfig.ts b/front/src/modules/client-config/graphql/queries/getClientConfig.ts index 59b439a2b..6c173143e 100644 --- a/front/src/modules/client-config/graphql/queries/getClientConfig.ts +++ b/front/src/modules/client-config/graphql/queries/getClientConfig.ts @@ -8,6 +8,8 @@ export const GET_CLIENT_CONFIG = gql` password } signInPrefilled + dataModelSettingsEnabled + developersSettingsEnabled debugMode telemetry { enabled diff --git a/front/src/modules/client-config/states/isDataModelSettingsEnabled.ts b/front/src/modules/client-config/states/isDataModelSettingsEnabled.ts new file mode 100644 index 000000000..4f839312c --- /dev/null +++ b/front/src/modules/client-config/states/isDataModelSettingsEnabled.ts @@ -0,0 +1,6 @@ +import { atom } from 'recoil'; + +export const isDataModelSettingsEnabledState = atom({ + key: 'isDataModelSettingsEnabledState', + default: false, +}); diff --git a/front/src/modules/client-config/states/isDevelopersSettingsEnabled.ts b/front/src/modules/client-config/states/isDevelopersSettingsEnabled.ts new file mode 100644 index 000000000..d745a11ef --- /dev/null +++ b/front/src/modules/client-config/states/isDevelopersSettingsEnabled.ts @@ -0,0 +1,6 @@ +import { atom } from 'recoil'; + +export const isDevelopersSettingsEnabledState = atom({ + key: 'isDevelopersSettingsEnabledState', + default: false, +}); diff --git a/front/src/modules/settings/components/SettingsNavbar.tsx b/front/src/modules/settings/components/SettingsNavbar.tsx index 7645a966f..b65beb434 100644 --- a/front/src/modules/settings/components/SettingsNavbar.tsx +++ b/front/src/modules/settings/components/SettingsNavbar.tsx @@ -1,7 +1,10 @@ import { useCallback } from 'react'; import { useMatch, useNavigate, useResolvedPath } from 'react-router-dom'; +import { useRecoilValue } from 'recoil'; import { useAuth } from '@/auth/hooks/useAuth'; +import { isDataModelSettingsEnabledState } from '@/client-config/states/isDataModelSettingsEnabled'; +import { isDevelopersSettingsEnabledState } from '@/client-config/states/isDevelopersSettingsEnabled'; import { AppPath } from '@/types/AppPath'; import { IconColorSwatch, @@ -26,6 +29,22 @@ export const SettingsNavbar = () => { navigate(AppPath.SignIn); }, [signOut, navigate]); + const isDataModelSettingsEnabled = useRecoilValue( + isDataModelSettingsEnabledState, + ); + const isDevelopersSettingsEnabled = useRecoilValue( + isDevelopersSettingsEnabledState, + ); + + const isDataModelSettingsActive = !!useMatch({ + path: useResolvedPath('/settings/objects').pathname, + end: false, + }); + const isDevelopersSettingsActive = !!useMatch({ + path: useResolvedPath('/settings/api').pathname, + end: true, + }); + return ( @@ -74,28 +93,22 @@ export const SettingsNavbar = () => { }) } /> - - + {isDataModelSettingsEnabled && ( + + )} + {isDevelopersSettingsEnabled && ( + + )} diff --git a/front/src/testing/graphqlMocks.ts b/front/src/testing/graphqlMocks.ts index bec2b0d21..0f905b58a 100644 --- a/front/src/testing/graphqlMocks.ts +++ b/front/src/testing/graphqlMocks.ts @@ -217,6 +217,8 @@ export const graphqlMocks = [ ctx.data({ clientConfig: { signInPrefilled: true, + dataModelSettingsEnabled: true, + developersSettingsEnabled: true, debugMode: false, authProviders: { google: true, password: true, magicLink: false }, telemetry: { enabled: false, anonymizationEnabled: true }, diff --git a/server/.env.example b/server/.env.example index 0f5546ca3..061db59ec 100644 --- a/server/.env.example +++ b/server/.env.example @@ -27,3 +27,5 @@ SIGN_IN_PREFILLED=true # SENTRY_DSN=https://xxx@xxx.ingest.sentry.io/xxx # LOG_LEVEL=error,warn # FLEXIBLE_BACKEND_ENABLED=false +# IS_DATA_MODEL_SETTINGS_ENABLED=false +# IS_DEVELOPERS_SETTINGS_ENABLED=false diff --git a/server/.env.test b/server/.env.test index a976e6eaf..67be1c20a 100644 --- a/server/.env.test +++ b/server/.env.test @@ -14,6 +14,8 @@ REFRESH_TOKEN_SECRET=secret_refresh_token # ———————— Optional ———————— # DEBUG_MODE=false # SIGN_IN_PREFILLED=false +# IS_DATA_MODEL_SETTINGS_ENABLED=false +# IS_DEVELOPERS_SETTINGS_ENABLED=false # ACCESS_TOKEN_EXPIRES_IN=30m # LOGIN_TOKEN_EXPIRES_IN=15m # REFRESH_TOKEN_EXPIRES_IN=90d diff --git a/server/src/core/client-config/client-config.entity.ts b/server/src/core/client-config/client-config.entity.ts index c26035d7d..f722424ae 100644 --- a/server/src/core/client-config/client-config.entity.ts +++ b/server/src/core/client-config/client-config.entity.ts @@ -41,6 +41,12 @@ export class ClientConfig { @Field(() => Boolean) signInPrefilled: boolean; + @Field(() => Boolean) + dataModelSettingsEnabled: boolean; + + @Field(() => Boolean) + developersSettingsEnabled: boolean; + @Field(() => Boolean) debugMode: boolean; diff --git a/server/src/core/client-config/client-config.resolver.ts b/server/src/core/client-config/client-config.resolver.ts index 736bfbfae..86a7fef7f 100644 --- a/server/src/core/client-config/client-config.resolver.ts +++ b/server/src/core/client-config/client-config.resolver.ts @@ -22,6 +22,10 @@ export class ClientConfigResolver { this.environmentService.isTelemetryAnonymizationEnabled(), }, signInPrefilled: this.environmentService.isSignInPrefilled(), + dataModelSettingsEnabled: + this.environmentService.isDataModelSettingsEnabled(), + developersSettingsEnabled: + this.environmentService.isDevelopersSettingsEnabled(), debugMode: this.environmentService.isDebugMode(), flexibleBackendEnabled: this.environmentService.isFlexibleBackendEnabled(), diff --git a/server/src/integrations/environment/environment.service.ts b/server/src/integrations/environment/environment.service.ts index 9fc60e966..82096a4f9 100644 --- a/server/src/integrations/environment/environment.service.ts +++ b/server/src/integrations/environment/environment.service.ts @@ -19,6 +19,18 @@ export class EnvironmentService { return this.configService.get('SIGN_IN_PREFILLED') ?? false; } + isDataModelSettingsEnabled(): boolean { + return ( + this.configService.get('IS_DATA_MODEL_SETTINGS_ENABLED') ?? false + ); + } + + isDevelopersSettingsEnabled(): boolean { + return ( + this.configService.get('IS_DEVELOPERS_SETTINGS_ENABLED') ?? false + ); + } + isTelemetryEnabled(): boolean { return this.configService.get('TELEMETRY_ENABLED') ?? true; } diff --git a/server/src/integrations/environment/environment.validation.ts b/server/src/integrations/environment/environment.validation.ts index 5a1135092..c3bcba2e5 100644 --- a/server/src/integrations/environment/environment.validation.ts +++ b/server/src/integrations/environment/environment.validation.ts @@ -36,6 +36,16 @@ export class EnvironmentVariables { @IsBoolean() SIGN_IN_PREFILLED?: boolean; + @CastToBoolean() + @IsOptional() + @IsBoolean() + IS_DATA_MODEL_SETTINGS_ENABLED?: boolean; + + @CastToBoolean() + @IsOptional() + @IsBoolean() + IS_DEVELOPERS_SETTINGS_ENABLED?: boolean; + @CastToBoolean() @IsOptional() @IsBoolean()