Format with prettier. Use screen mode for invitation import - dialog mode is broken.

This commit is contained in:
2026-03-23 10:15:48 +00:00
parent 7fd89c5663
commit b475b23beb
47 changed files with 1718 additions and 1098 deletions

View File

@@ -1,12 +1,12 @@
/**
* Template utility functions.
*
*
* Pure functions for parsing and formatting template data.
* These functions have no React dependencies and can be used
* in both TUI and CLI contexts.
*/
import type { XOTemplate, XOTemplateAction } from '@xo-cash/types';
import type { XOTemplate, XOTemplateAction } from "@xo-cash/types";
/**
* Formatted template list item data.
@@ -57,25 +57,25 @@ export interface TemplateRole {
/**
* Format a template for display in a list.
*
*
* @param template - The template to format
* @param index - Optional index for numbered display
* @returns Formatted item data for display
*/
export function formatTemplateListItem(
template: XOTemplate | null | undefined,
index?: number
index?: number,
): FormattedTemplateItem {
if (!template) {
return {
label: '',
label: "",
description: undefined,
isValid: false,
};
}
const name = template.name || 'Unnamed Template';
const prefix = index !== undefined ? `${index + 1}. ` : '';
const name = template.name || "Unnamed Template";
const prefix = index !== undefined ? `${index + 1}. ` : "";
return {
label: `${prefix}${name}`,
@@ -86,7 +86,7 @@ export function formatTemplateListItem(
/**
* Format an action for display in a list.
*
*
* @param actionId - The action identifier
* @param action - The action definition from the template
* @param roleCount - Number of roles that can start this action
@@ -97,11 +97,11 @@ export function formatActionListItem(
actionId: string,
action: XOTemplateAction | null | undefined,
roleCount: number = 1,
index?: number
index?: number,
): FormattedActionItem {
if (!actionId) {
return {
label: '',
label: "",
description: undefined,
roleCount: 0,
isValid: false,
@@ -109,8 +109,8 @@ export function formatActionListItem(
}
const name = action?.name || actionId;
const prefix = index !== undefined ? `${index + 1}. ` : '';
const roleSuffix = roleCount > 1 ? ` (${roleCount} roles)` : '';
const prefix = index !== undefined ? `${index + 1}. ` : "";
const roleSuffix = roleCount > 1 ? ` (${roleCount} roles)` : "";
return {
label: `${prefix}${name}${roleSuffix}`,
@@ -124,14 +124,14 @@ export function formatActionListItem(
* Deduplicate starting actions from a template.
* Multiple roles that can start the same action are counted
* but returned as a single entry.
*
*
* @param template - The template to process
* @param startingActions - Array of { action, role } pairs
* @returns Array of unique starting actions with role counts
*/
export function deduplicateStartingActions(
template: XOTemplate,
startingActions: Array<{ action: string; role: string }>
startingActions: Array<{ action: string; role: string }>,
): UniqueStartingAction[] {
const actionMap = new Map<string, UniqueStartingAction>();
@@ -154,7 +154,7 @@ export function deduplicateStartingActions(
/**
* Get all roles from a template.
*
*
* @param template - The template to process
* @returns Array of role information
*/
@@ -163,7 +163,7 @@ export function getTemplateRoles(template: XOTemplate): TemplateRole[] {
return Object.entries(template.roles).map(([roleId, role]) => {
// Handle case where role might be a string instead of object
const roleObj = typeof role === 'object' ? role : null;
const roleObj = typeof role === "object" ? role : null;
return {
roleId,
name: roleObj?.name || roleId,
@@ -174,21 +174,22 @@ export function getTemplateRoles(template: XOTemplate): TemplateRole[] {
/**
* Get roles that can start a specific action.
*
*
* @param template - The template to check
* @param actionIdentifier - The action to check
* @returns Array of role information for roles that can start this action
*/
export function getRolesForAction(
template: XOTemplate,
actionIdentifier: string
actionIdentifier: string,
): TemplateRole[] {
const startEntries = (template.start ?? [])
.filter((s) => s.action === actionIdentifier);
const startEntries = (template.start ?? []).filter(
(s) => s.action === actionIdentifier,
);
return startEntries.map((entry) => {
const roleDef = template.roles?.[entry.role];
const roleObj = typeof roleDef === 'object' ? roleDef : null;
const roleObj = typeof roleDef === "object" ? roleDef : null;
return {
roleId: entry.role,
name: roleObj?.name || entry.role,
@@ -199,48 +200,52 @@ export function getRolesForAction(
/**
* Get template name safely.
*
*
* @param template - The template
* @returns The template name or a default
*/
export function getTemplateName(template: XOTemplate | null | undefined): string {
return template?.name || 'Unknown Template';
export function getTemplateName(
template: XOTemplate | null | undefined,
): string {
return template?.name || "Unknown Template";
}
/**
* Get template description safely.
*
*
* @param template - The template
* @returns The template description or undefined
*/
export function getTemplateDescription(template: XOTemplate | null | undefined): string | undefined {
export function getTemplateDescription(
template: XOTemplate | null | undefined,
): string | undefined {
return template?.description;
}
/**
* Get action name safely.
*
*
* @param template - The template containing the action
* @param actionId - The action identifier
* @returns The action name or the action ID as fallback
*/
export function getActionName(
template: XOTemplate | null | undefined,
actionId: string
actionId: string,
): string {
return template?.actions?.[actionId]?.name || actionId;
}
/**
* Get action description safely.
*
*
* @param template - The template containing the action
* @param actionId - The action identifier
* @returns The action description or undefined
*/
export function getActionDescription(
template: XOTemplate | null | undefined,
actionId: string
actionId: string,
): string | undefined {
return template?.actions?.[actionId]?.description;
}