feat: fix junction toggle persistence and add type-safe documentation paths (#17421)

## Summary

- **Fix junction relation toggle not being saved**: The form schema
wasn't tracking the `settings` field, so changes to
`junctionTargetFieldId` weren't marked as dirty
- **Add type-safe documentation paths**: Generate TypeScript constants
from `base-structure.json` to prevent broken documentation links
- **Create many-to-many relations documentation**: Step-by-step guide
for building many-to-many relations using junction objects
- **Update `getDocumentationUrl`**: Now uses shared constants from
`twenty-shared` for base URL, default path, and supported languages

## Key Changes

### Junction Toggle Fix
- Added `settings` field to the form schema in
`SettingsDataModelFieldRelationForm.tsx`
- Fixed the toggle to properly merge settings when updating
`junctionTargetFieldId`

### Type-Safe Documentation Paths
- New constants in `twenty-shared/constants`:
- `DOCUMENTATION_PATHS` - All 161 documentation paths as typed constants
  - `DOCUMENTATION_SUPPORTED_LANGUAGES` - 14 supported languages
  - `DOCUMENTATION_BASE_URL` / `DOCUMENTATION_DEFAULT_PATH`
- Generator script: `yarn docs:generate-paths`
- CI integration: Added to `docs-i18n-pull.yaml` workflow

### Documentation
- New article:
`/user-guide/data-model/how-tos/create-many-to-many-relations`
- Updated `/user-guide/data-model/capabilities/relation-fields.mdx` with
Lab warning and link

## Test plan
- [ ] Verify junction toggle saves correctly when enabled/disabled
- [ ] Verify documentation link opens correct localized page
- [ ] Verify `yarn docs:generate-paths` regenerates paths correctly
This commit is contained in:
Félix Malfait
2026-01-25 13:29:20 +01:00
committed by GitHub
parent 3b512164d1
commit 161689be18
22 changed files with 736 additions and 50 deletions
@@ -55,6 +55,12 @@ export const settingsDataModelFieldMorphRelationFormSchema = z.object({
),
targetFieldLabel: z.string().min(1),
iconOnDestination: z.string().min(1),
settings: z
.object({
junctionTargetFieldId: z.string().optional(),
})
.catchall(z.unknown())
.optional(),
});
export type SettingsDataModelFieldMorphRelationFormValues = z.infer<
@@ -1,16 +1,19 @@
import { Trans, useLingui } from '@lingui/react/macro';
import { useFormContext } from 'react-hook-form';
import { useRecoilValue } from 'recoil';
import { DOCUMENTATION_PATHS } from 'twenty-shared/constants';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { IconLink } from 'twenty-ui/display';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { SettingsOptionCardContentSelect } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSelect';
import { SettingsOptionCardContentToggle } from '@/settings/components/SettingsOptions/SettingsOptionCardContentToggle';
import { getDocumentationUrl } from '@/support/utils/getDocumentationUrl';
import { Select } from '@/ui/input/components/Select';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import { useLingui } from '@lingui/react/macro';
import { useRecoilValue } from 'recoil';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { IconLink } from 'twenty-ui/display';
import { RelationType } from '~/generated-metadata/graphql';
import { type SettingsDataModelFieldEditFormValues } from '~/pages/settings/data-model/SettingsObjectFieldEdit';
@@ -26,6 +29,12 @@ export const SettingsDataModelFieldRelationJunctionForm = ({
useFormContext<SettingsDataModelFieldEditFormValues>();
const isAdvancedModeEnabled = useRecoilValue(isAdvancedModeEnabledState);
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const documentationUrl = getDocumentationUrl({
locale: currentWorkspaceMember?.locale,
path: DOCUMENTATION_PATHS.USER_GUIDE_DATA_MODEL_HOW_TOS_CREATE_MANY_TO_MANY_RELATIONS,
});
const { objectMetadataItem: sourceObjectMetadataItem } =
useObjectMetadataItem({ objectNameSingular });
@@ -34,7 +43,8 @@ export const SettingsDataModelFieldRelationJunctionForm = ({
const relationType = watch('relationType') ?? RelationType.ONE_TO_MANY;
const targetObjectIds = watch('morphRelationObjectMetadataIds') ?? [];
const junctionTargetFieldId = watch('settings.junctionTargetFieldId');
const currentSettings = watch('settings');
const junctionTargetFieldId = currentSettings?.junctionTargetFieldId;
// Only applies to ONE_TO_MANY with single target
if (
@@ -112,23 +122,40 @@ export const SettingsDataModelFieldRelationJunctionForm = ({
const handleJunctionToggle = (checked: boolean) => {
if (checked && junctionFieldOptions.length > 0) {
setValue(
'settings.junctionTargetFieldId',
junctionFieldOptions[0].value,
'settings',
{
...currentSettings,
junctionTargetFieldId: junctionFieldOptions[0].value,
},
{
shouldDirty: true,
},
);
} else {
setValue('settings.junctionTargetFieldId', undefined, {
shouldDirty: true,
});
setValue(
'settings',
{
...currentSettings,
junctionTargetFieldId: undefined,
},
{
shouldDirty: true,
},
);
}
};
const handleSelectionChange = (selectedValue: string) => {
setValue('settings.junctionTargetFieldId', selectedValue, {
shouldDirty: true,
});
setValue(
'settings',
{
...currentSettings,
junctionTargetFieldId: selectedValue,
},
{
shouldDirty: true,
},
);
};
return (
@@ -136,7 +163,19 @@ export const SettingsDataModelFieldRelationJunctionForm = ({
<SettingsOptionCardContentToggle
Icon={IconLink}
title={t`This is a relation to a Junction Object`}
description={t`Will show linked records directly instead of intermediate junction record`}
description={
<Trans>
Build many-to-many relations.{' '}
<a
href={documentationUrl}
target="_blank"
rel="noopener noreferrer"
style={{ textDecoration: 'underline', color: 'inherit' }}
>
Learn more
</a>
</Trans>
}
checked={isJunctionConfigEnabled}
onChange={handleJunctionToggle}
divider={isJunctionConfigEnabled}