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 f3ffa54 commit 5b02cd7
Show file tree
Hide file tree
Showing 14 changed files with 58 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
1 change: 1 addition & 0 deletions webapp/src/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@
"projects_empty": "Žádné projekty",
"projects_empty_action": "Přidat projekt",
"project_settings_base_language": "Základní jazyk",
"project_settings_use_namespaces": "Používat namespaces",
"project_settings_base_namespace": "Výchozí namespace",
"project_settings_button": "Nastavení",
"project_settings_danger_zone_title": "Nebezpečná zóna",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@
"projects_empty": "Ingen projekter",
"projects_empty_action": "Tilføj projekt",
"project_settings_base_language": "Basis sprog",
"project_settings_use_namespaces": "Use namespaces TODO",
"project_settings_base_namespace": "Standard navnerum",
"project_settings_button": "Indstillinger",
"project_settings_danger_zone_title": "Farezone",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@
"projects_empty": "Keine Projekte",
"projects_empty_action": "Projekt hinzufügen",
"project_settings_base_language": "Basissprache",
"project_settings_use_namespaces": "Use namespaces TODO",
"project_settings_base_namespace": "Standard-Namespace",
"project_settings_button": "Einstellungen",
"project_settings_danger_zone_title": "Gefahrenzone",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@
"projects_empty": "No projects",
"projects_empty_action": "Add project",
"project_settings_base_language": "Base language",
"project_settings_use_namespaces": "Use namespaces",
"project_settings_base_namespace": "Default namespace",
"project_settings_button": "Settings",
"project_settings_danger_zone_title": "Danger zone",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/i18n/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@
"projects_empty": "Niciun proiect",
"projects_empty_action": "Adaugă proiect",
"project_settings_base_language": "Limba de bază",
"project_settings_use_namespaces": "Use namespaces TODO",
"project_settings_base_namespace": "Spațiul de nume implicit",
"project_settings_button": "Setări",
"project_settings_danger_zone_title": "Zona de pericol",
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 5b02cd7

Please sign in to comment.