Skip to content

Commit

Permalink
DRAFT: Making namespaces as a hidden feature
Browse files Browse the repository at this point in the history
  • Loading branch information
StaNov committed Nov 25, 2024
1 parent 09e0a54 commit 26886c7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 2 deletions.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Save settings to DB
* Hide select boxes by the settings
* Add liquibase changeset for customers already using namespaces, disable them only when there are none
* Default is off, set it to on for customers who already use it
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class EditProjectRequest(
@field:Pattern(regexp = "^[a-z0-9-]*[a-z]+[a-z0-9-]*$", message = "invalid_pattern")
var slug: String? = null,
var baseLanguageId: Long? = null,
var useNamespaces: Boolean = false,
var defaultNamespaceId: Long? = null,
@field:Size(min = 3, max = 2000)
var description: String? = null,
Expand Down
3 changes: 3 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class Project(
@ColumnDefault("true")
override var icuPlaceholders: Boolean = true

@ColumnDefault("false")
var useNamespaces: Boolean = false

@ColumnDefault("0")
var lastTaskNumber: Long = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class ProjectService(
project.name = dto.name
project.description = dto.description
project.icuPlaceholders = dto.icuPlaceholders
project.useNamespaces = dto.useNamespaces

if (project.defaultNamespace != null) {
namespaceService.deleteUnusedNamespaces(listOf(project.defaultNamespace!!))
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/service/apiSchema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ export interface components {
slug?: string;
/** Format: int64 */
baseLanguageId?: number;
useNamespaces: boolean;
/** Format: int64 */
defaultNamespaceId?: number;
description?: string;
Expand Down Expand Up @@ -1336,6 +1337,7 @@ export interface components {
avatar?: components["schemas"]["Avatar"];
organizationOwner?: components["schemas"]["SimpleOrganizationModel"];
baseLanguage?: components["schemas"]["LanguageModel"];
useNamespaces: boolean;
defaultNamespace?: components["schemas"]["NamespaceModel"];
organizationRole?: "MEMBER" | "OWNER";
directPermission?: components["schemas"]["PermissionModel"];
Expand Down
14 changes: 14 additions & 0 deletions webapp/src/views/projects/project/ProjectSettingsGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { Box, styled } from '@mui/material';
import { ProjectLanguagesProvider } from 'tg.hooks/ProjectLanguagesProvider';
import { useProjectNamespaces } from 'tg.hooks/useProjectNamespaces';
import { DefaultNamespaceSelect } from './components/DefaultNamespaceSelect';
import { UseNamespacesCheckbox } from './components/UseNamespacesCheckbox';

type FormValues = {
name: string;
description: string | undefined;
baseLanguageId: number | undefined;
useNamespaces: boolean | false;
defaultNamespaceId: number | '';
};

Expand Down Expand Up @@ -49,6 +51,15 @@ const LanguageSelect = () => {
);
};

const NamespacesCheckbox = () => {
return (
<UseNamespacesCheckbox
label={<T keyName="project_settings_use_namespaces" />}
name="useNamespaces"
/>
);
};

const NamespaceSelect = () => {
const { allNamespacesWithNone } = useProjectNamespaces();
return (
Expand All @@ -69,6 +80,7 @@ export const ProjectSettingsGeneral = () => {
name: project.name,
baseLanguageId: project.baseLanguage?.id,
description: project.description ?? '',
useNamespaces: project.useNamespaces ?? false,
defaultNamespaceId: defaultNamespace?.id ?? '',
} satisfies FormValues;

Expand All @@ -82,6 +94,7 @@ export const ProjectSettingsGeneral = () => {
const data = {
...values,
description: values.description || undefined,
useNamespaces: values.useNamespaces || false,
defaultNamespaceId:
values.defaultNamespaceId === 0 ? undefined : values.defaultNamespaceId,
};
Expand Down Expand Up @@ -157,6 +170,7 @@ export const ProjectSettingsGeneral = () => {
<ProjectLanguagesProvider>
<LanguageSelect />
</ProjectLanguagesProvider>
<NamespacesCheckbox />
<NamespaceSelect />
</Box>
</StandardForm>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { FC, ReactNode } from 'react';
import { Box, Checkbox, MenuItem } from '@mui/material';

import { Select } from 'tg.component/common/form/fields/Select';
import { components } from 'tg.service/apiSchema.generated';
import { FieldLabel } from 'tg.component/FormField';
import { useTranslate } from '@tolgee/react';

export const UseNamespacesCheckbox: FC<{
label?: ReactNode;
name: string;
}> = (props) => {
return (
<Box>
<FieldLabel>{props.label}</FieldLabel>
<Checkbox
data-cy="default-namespace-select"
sx={{ mt: 0 }}
name={props.name}
size="small"
/>
</Box>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const FormBody: React.FC<Props> = ({ onCancel, autofocus }) => {
{({ field, form }: FieldProps<any>) => {
return (
<div>
<FieldLabel>
<FieldLabel> {/*TODO tady možná taky*/}
<LabelHint title={t('translation_single_namespace_hint')}>
<T keyName="translation_single_label_namespace" />
</LabelHint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export const KeyGeneral = () => {
</EditorWrapper>
<FieldError error={errors.name} />
</StyledSection>
{/*<ConditionalFormItem>*/}
<StyledSection>
<FieldLabel>
<LabelHint title={t('translations_key_edit_label_namespace_hint')}>
{t('translations_key_edit_label_namespace')}
{t('translations_key_edit_label_namespace')} tady
</LabelHint>
</FieldLabel>
<NamespaceSelector
Expand All @@ -84,6 +85,7 @@ export const KeyGeneral = () => {
/>
<FieldError error={errors.namespace} />
</StyledSection>
{/*</ConditionalFormItem>*/}
</StyledKeyNsContainer>

<StyledSection>
Expand Down

0 comments on commit 26886c7

Please sign in to comment.