Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/features/installed-apps/lib/dynamic-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ import { isIconType } from '@installed-apps/lib/icon-names'
// Stands in when an install's `icon` is absent or not a design-system IconType.
const FALLBACK_ICON: IconType = 'CustomApps'

// App builders register `actionLabel.verb` with no casing rule enforced, so it arrives in
// whatever shape the app author typed ("review", "reView", "REVIEW"). The verb leads the
// rendered row, so normalize it to sentence case: first letter up, remainder down.
export const capitalizeVerb = (verb: string) => {
const trimmed = verb.trim()
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1).toLowerCase()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Suffix casing is discarded

When a Studio app registers a valid verb with meaningful internal capitalization, such as eSign, PDF, or logToCRM, lowercasing the entire suffix produces Esign, Pdf, or Logtocrm, which ActionItem displays verbatim as a misspelled action label.

Suggested change
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1).toLowerCase()
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think verb should not be logToCRM or eSign, it should be a valid english verb and we are enforcing it. Dont be stupid @greptile.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point — if the builder side enforces valid English verbs, then inputs like eSign or logToCRM are invalid by contract and the normalization behavior is correct as written. I'll withdraw the concern.

}

// A "Your Actions" row synthesized at runtime from an actionable Studio app install.
// Mirrors ActionDefinition's presentational fields so ActionItem renders it identically,
// but is identified by its install/app rather than a built-in ActionKey.
export type DynamicActionDefinition = {
/** Sentence-cased verb, e.g. "Review". */
verb: string
/** Plural noun, e.g. "documents". */
label: string
Expand All @@ -26,7 +35,7 @@ export type RenderableAction = ActionDefinition | DynamicActionDefinition
export const isDynamicAction = (action: RenderableAction): action is DynamicActionDefinition => 'installId' in action

export const toDynamicActionDefinition = (install: ActionableInstallDto): DynamicActionDefinition => ({
verb: install.actionLabel.verb,
verb: capitalizeVerb(install.actionLabel.verb),
label: install.actionLabel.pluralNoun,
singularLabel: install.actionLabel.singularNoun,
icon: isIconType(install.icon) ? install.icon : FALLBACK_ICON,
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/dynamic-action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { ActionableInstallDto } from '@installed-apps/installed-apps.dto'
import { capitalizeVerb, toDynamicActionDefinition } from '@installed-apps/lib/dynamic-action'
import { describe, expect, it } from 'vitest'

const createActionableInstall = (verb: string): ActionableInstallDto => ({
installId: 'install_1',
appId: 'app_1',
displayName: 'Docs',
icon: 'CustomApps',
actionLabel: { verb, singularNoun: 'document', pluralNoun: 'documents' },
})

describe('capitalizeVerb', () => {
it('capitalizes a lowercase verb', () => {
expect(capitalizeVerb('review')).toBe('Review')
})

it('normalizes inconsistent inner casing', () => {
expect(capitalizeVerb('reView')).toBe('Review')
})

it('normalizes an all-caps verb', () => {
expect(capitalizeVerb('REVIEW')).toBe('Review')
})

it('leaves an already-capitalized verb unchanged', () => {
expect(capitalizeVerb('Review')).toBe('Review')
})

it('capitalizes only the first word of a multi-word verb', () => {
expect(capitalizeVerb('sign off')).toBe('Sign off')
})

it('trims surrounding whitespace', () => {
expect(capitalizeVerb(' review ')).toBe('Review')
})

it('returns an empty string for an empty verb', () => {
expect(capitalizeVerb(' ')).toBe('')
})
})

describe('toDynamicActionDefinition', () => {
it('capitalizes the verb and passes the nouns through verbatim', () => {
const action = toDynamicActionDefinition(createActionableInstall('reView'))

expect(action.verb).toBe('Review')
expect(action.label).toBe('documents')
expect(action.singularLabel).toBe('document')
})
})
Loading