Support template variables in command menu item labels (#18707)

- Adds template variable interpolation (`${...}`) to command menu item
labels and short labels, enabling dynamic text like `Create new
${capitalize(objectMetadataItem.labelSingular)}` instead of static
`Create new record`.
- Supports `capitalize` and `lowercase` transform functions within
template expressions.
This commit is contained in:
Raphaël Bosi
2026-03-18 11:26:58 +01:00
committed by GitHub
parent 928194cee4
commit dedcf4e9b9
25 changed files with 673 additions and 236 deletions
@@ -1,6 +1,6 @@
import { getCommandMenuItemLabel } from '@/command-menu-item/utils/getCommandMenuItemLabel';
import { styled } from '@linaria/react';
import { i18n, type MessageDescriptor } from '@lingui/core';
import { isString } from '@sniptt/guards';
import { type MessageDescriptor } from '@lingui/core';
import { type MouseEvent } from 'react';
import { type Nullable } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
@@ -20,7 +20,7 @@ const StyledWrapper = styled.div`
export type CommandMenuButtonProps = {
command: {
key: string;
label: string | MessageDescriptor;
label: Nullable<string | MessageDescriptor>;
shortLabel?: Nullable<string | MessageDescriptor>;
Icon: IconComponent;
isPrimaryCTA?: boolean;
@@ -30,22 +30,16 @@ export type CommandMenuButtonProps = {
disabled?: boolean;
};
const getCommandMenuButtonLabel = (
label: string | MessageDescriptor,
): string => {
return isString(label) ? label : i18n._(label);
};
export const CommandMenuButton = ({
command,
onClick,
to,
disabled = false,
}: CommandMenuButtonProps) => {
const resolvedLabel = getCommandMenuButtonLabel(command.label);
const resolvedLabel = getCommandMenuItemLabel(command.label);
const resolvedShortLabel = isDefined(command.shortLabel)
? getCommandMenuButtonLabel(command.shortLabel)
? getCommandMenuItemLabel(command.shortLabel)
: undefined;
const buttonAccent = command.isPrimaryCTA ? 'blue' : 'default';