Capitalize labels objectmetadata (#11609)
Capitalize labels singular and plural from objectmetadata Fixes [#664](https://github.com/twentyhq/core-team-issues/issues/664)
This commit is contained in:
@ -11,9 +11,7 @@ import styled from '@emotion/styled';
|
|||||||
import { useLingui } from '@lingui/react/macro';
|
import { useLingui } from '@lingui/react/macro';
|
||||||
import { plural } from 'pluralize';
|
import { plural } from 'pluralize';
|
||||||
import { Controller, useFormContext } from 'react-hook-form';
|
import { Controller, useFormContext } from 'react-hook-form';
|
||||||
import { isDefined } from 'twenty-shared/utils';
|
import { capitalize, isDefined } from 'twenty-shared/utils';
|
||||||
import { StringKeyOf } from 'type-fest';
|
|
||||||
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
|
||||||
import {
|
import {
|
||||||
AppTooltip,
|
AppTooltip,
|
||||||
IconInfoCircle,
|
IconInfoCircle,
|
||||||
@ -21,6 +19,8 @@ import {
|
|||||||
TooltipDelay,
|
TooltipDelay,
|
||||||
} from 'twenty-ui/display';
|
} from 'twenty-ui/display';
|
||||||
import { Card } from 'twenty-ui/layout';
|
import { Card } from 'twenty-ui/layout';
|
||||||
|
import { StringKeyOf } from 'type-fest';
|
||||||
|
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
||||||
|
|
||||||
type SettingsDataModelObjectAboutFormProps = {
|
type SettingsDataModelObjectAboutFormProps = {
|
||||||
disableEdition?: boolean;
|
disableEdition?: boolean;
|
||||||
@ -155,8 +155,8 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
placeholder={'Listing'}
|
placeholder={'Listing'}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
onChange(value);
|
onChange(capitalize(value));
|
||||||
fillLabelPlural(value);
|
fillLabelPlural(capitalize(value));
|
||||||
if (isLabelSyncedWithName === true) {
|
if (isLabelSyncedWithName === true) {
|
||||||
fillNameSingularFromLabelSingular(value);
|
fillNameSingularFromLabelSingular(value);
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
placeholder={t`Listings`}
|
placeholder={t`Listings`}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
onChange(value);
|
onChange(capitalize(value));
|
||||||
if (isLabelSyncedWithName === true) {
|
if (isLabelSyncedWithName === true) {
|
||||||
fillNamePluralFromLabelPlural(value);
|
fillNamePluralFromLabelPlural(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
|
||||||
import { isDefined } from 'class-validator';
|
|
||||||
import Stripe from 'stripe';
|
import Stripe from 'stripe';
|
||||||
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
|
|
||||||
import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';
|
import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';
|
||||||
import { StripeSDKService } from 'src/engine/core-modules/billing/stripe/stripe-sdk/services/stripe-sdk.service';
|
import { StripeSDKService } from 'src/engine/core-modules/billing/stripe/stripe-sdk/services/stripe-sdk.service';
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||||||
import { i18n } from '@lingui/core';
|
import { i18n } from '@lingui/core';
|
||||||
import { Query, QueryOptions } from '@ptc-org/nestjs-query-core';
|
import { Query, QueryOptions } from '@ptc-org/nestjs-query-core';
|
||||||
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
|
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
|
||||||
import { isDefined } from 'class-validator';
|
|
||||||
import { APP_LOCALES, SOURCE_LOCALE } from 'twenty-shared/translations';
|
import { APP_LOCALES, SOURCE_LOCALE } from 'twenty-shared/translations';
|
||||||
|
import { capitalize, isDefined } from 'twenty-shared/utils';
|
||||||
import { FindManyOptions, FindOneOptions, In, Not, Repository } from 'typeorm';
|
import { FindManyOptions, FindOneOptions, In, Not, Repository } from 'typeorm';
|
||||||
|
|
||||||
import { ObjectMetadataStandardIdToIdMap } from 'src/engine/metadata-modules/object-metadata/interfaces/object-metadata-standard-id-to-id-map';
|
import { ObjectMetadataStandardIdToIdMap } from 'src/engine/metadata-modules/object-metadata/interfaces/object-metadata-standard-id-to-id-map';
|
||||||
@ -89,6 +89,13 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
objectMetadataInput.workspaceId,
|
objectMetadataInput.workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
objectMetadataInput.labelSingular = capitalize(
|
||||||
|
objectMetadataInput.labelSingular,
|
||||||
|
);
|
||||||
|
objectMetadataInput.labelPlural = capitalize(
|
||||||
|
objectMetadataInput.labelPlural,
|
||||||
|
);
|
||||||
|
|
||||||
validateObjectMetadataInputNamesOrThrow(objectMetadataInput);
|
validateObjectMetadataInputNamesOrThrow(objectMetadataInput);
|
||||||
validateObjectMetadataInputLabelsOrThrow(objectMetadataInput);
|
validateObjectMetadataInputLabelsOrThrow(objectMetadataInput);
|
||||||
|
|
||||||
@ -212,6 +219,18 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
input: UpdateOneObjectInput,
|
input: UpdateOneObjectInput,
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
): Promise<ObjectMetadataEntity> {
|
): Promise<ObjectMetadataEntity> {
|
||||||
|
const { update } = input;
|
||||||
|
|
||||||
|
if (isDefined(update.labelSingular)) {
|
||||||
|
update.labelSingular = capitalize(update.labelSingular);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDefined(update.labelPlural)) {
|
||||||
|
update.labelPlural = capitalize(update.labelPlural);
|
||||||
|
}
|
||||||
|
|
||||||
|
input.update = update;
|
||||||
|
|
||||||
validateObjectMetadataInputNamesOrThrow(input.update);
|
validateObjectMetadataInputNamesOrThrow(input.update);
|
||||||
|
|
||||||
const existingObjectMetadata = await this.objectMetadataRepository.findOne({
|
const existingObjectMetadata = await this.objectMetadataRepository.findOne({
|
||||||
|
|||||||
Reference in New Issue
Block a user