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 4e257a9 commit 7031594
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* 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
* Inline checkbox styling
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open class ProjectModel(
val avatar: Avatar?,
val organizationOwner: SimpleOrganizationModel?,
val baseLanguage: LanguageModel?,
val useNamespaces: Boolean,
val defaultNamespace: NamespaceModel?,
val organizationRole: OrganizationRoleType?,
@Schema(description = "Current user's direct permission", example = "MANAGE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ProjectModelAssembler(
organizationRole = view.organizationRole,
organizationOwner = view.organizationOwner.let { simpleOrganizationModelAssembler.toModel(it) },
baseLanguage = baseLanguage.let { languageModelAssembler.toModel(LanguageDto.fromEntity(it, it.id)) },
useNamespaces = view.useNamespaces,
defaultNamespace = defaultNamespace,
directPermission = view.directPermission?.let { permissionModelAssembler.toModel(it) },
computedPermission = computedPermissionModelAssembler.toModel(computedPermissions),
Expand Down
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 @@ -11,6 +11,7 @@ interface ProjectView {
val description: String?
val slug: String?
val avatarHash: String?
val useNamespaces: Boolean
val defaultNamespace: Namespace?
val organizationOwner: Organization
val organizationRole: OrganizationRoleType?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open class ProjectWithLanguagesView(
override val description: String?,
override val slug: String?,
override val avatarHash: String?,
override val useNamespaces: Boolean,
override val defaultNamespace: Namespace?,
override val organizationOwner: Organization,
override val organizationRole: OrganizationRoleType?,
Expand All @@ -29,6 +30,7 @@ open class ProjectWithLanguagesView(
description = view.description,
slug = view.slug,
avatarHash = view.avatarHash,
useNamespaces = view.useNamespaces,
defaultNamespace = view.defaultNamespace,
organizationOwner = view.organizationOwner,
organizationRole = view.organizationRole,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ProjectWithStatsView(
view.description,
view.slug,
view.avatarHash,
view.useNamespaces,
view.defaultNamespace,
view.organizationOwner,
view.organizationRole,
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
7 changes: 7 additions & 0 deletions backend/data/src/main/resources/db/changelog/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3878,4 +3878,11 @@
<column name="organization_id"/>
</createIndex>
</changeSet>
<changeSet author="stanov (generated)" id="1732537248089-1">
<addColumn tableName="project">
<column defaultValueBoolean="false" name="use_namespaces" type="boolean">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
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 7031594

Please sign in to comment.