feat(automations): Templates marketplace tab (search, favorites, import)

Promote 'New from template' from a popup to its own Templates tab, built to grow
like a marketplace:
- Responsive card grid (icon, name, description, integration tags) with a
  'Use template' action per card.
- Search box to filter.
- Per-card favorite star; favorites persist in localStorage and float to the
  top (server-side store can replace this later without UI changes).
- 'Import template' action: paste a tramo workflow JSON or load a .json file to
  create it as a new automation.
Removes the old modal picker and its topbar button.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Juan DenisandClaude Opus 4.8 committed 2026-07-12 00:01:03 -04:00
1 parent 049235b12d
commit 5fce53f779
4 files changed
+694 -210

No files matched your search

@@ -3,7 +3,8 @@ import { useParams, useNavigate } from 'react-router-dom';
import {
Workflow, RefreshCw, Plus, Trash2, Rocket, Pencil, Play, LayoutTemplate,
Server, Power, KeyRound, CheckCircle2, X, Send, Github, MessageSquare,
Zap, ChevronRight, MousePointerClick, Clock, Webhook, Check,
Zap, MousePointerClick, Clock, Webhook, Check, Search, Star,
Upload, FileJson,
} from 'lucide-react';
import api from '@/services/api';
import { PageTopbar, Pill } from '@/components/ds';
@@ -20,11 +21,24 @@ import '../styles/tramo-automations.scss';
// Route-driven tabs (manifest maps /automations and /automations/:tab here).
const TABS = [
{ slug: 'workflows', to: '/automations', label: 'Workflows', end: true },
{ slug: 'templates', to: '/automations/templates', label: 'Templates' },
{ slug: 'runs', to: '/automations/runs', label: 'Runs' },
{ slug: 'settings', to: '/automations/settings', label: 'Settings' },
];
const VALID_TABS = TABS.map((t) => t.slug);
// Favorited template ids live in the browser for now (per-device). A server-side
// favorites store can replace this later without touching the card UI.
const FAVORITES_KEY = 'tramo:favorite-templates';
const readFavorites = () => {
try {
const raw = JSON.parse(localStorage.getItem(FAVORITES_KEY) || '[]');
return new Set(Array.isArray(raw) ? raw : []);
} catch {
return new Set();
}
};
// Presentation for the starter templates (icon + accent + tags). Keyed by the
// backend template id; unknown ids fall back to a neutral card so new templates
// still render cleanly.
@@ -102,8 +116,13 @@ const AutomationsPage = () => {
const [newModal, setNewModal] = useState(false);
const [newName, setNewName] = useState('');
const [newTrigger, setNewTrigger] = useState('manual');
const [templateModal, setTemplateModal] = useState(false);
const [templates, setTemplates] = useState([]);
const [templatesLoading, setTemplatesLoading] = useState(false);
const [templateSearch, setTemplateSearch] = useState('');
const [favorites, setFavorites] = useState(readFavorites);
const [importModal, setImportModal] = useState(false);
const [importName, setImportName] = useState('');
const [importText, setImportText] = useState('');
// Runs tab
const [runs, setRuns] = useState([]);
@@ -164,11 +183,33 @@ const AutomationsPage = () => {
}
}, [toast]);
const loadTemplates = useCallback(async () => {
setTemplatesLoading(true);
try {
const data = await api.request('/tramo/templates');
setTemplates(data.templates || []);
} catch (error) {
toast.error(`Could not load templates: ${error.message}`);
} finally {
setTemplatesLoading(false);
}
}, [toast]);
useEffect(() => {
if (activeTab === 'workflows') loadWorkflows();
else if (activeTab === 'templates') loadTemplates();
else if (activeTab === 'runs') loadRuns();
else if (activeTab === 'settings') loadSettings();
}, [activeTab, loadWorkflows, loadRuns, loadSettings]);
}, [activeTab, loadWorkflows, loadTemplates, loadRuns, loadSettings]);
const toggleFavorite = (id) => {
setFavorites((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id); else next.add(id);
try { localStorage.setItem(FAVORITES_KEY, JSON.stringify([...next])); } catch { /* ignore */ }
return next;
});
};
// ── Workflow actions ──
const openNewModal = () => {
@@ -197,21 +238,10 @@ const AutomationsPage = () => {
}
};
const openTemplateModal = async () => {
setTemplateModal(true);
try {
const data = await api.request('/tramo/templates');
setTemplates(data.templates || []);
} catch (error) {
toast.error(`Could not load templates: ${error.message}`);
}
};
const handleFromTemplate = async (template) => {
setBusy(true);
try {
const wf = await api.request(`/tramo/workflows/from-template/${template.id}`, { method: 'POST', body: {} });
setTemplateModal(false);
toast.success(`Created "${wf.name}" from ${template.name}`);
navigate(`/automations/edit/${wf.slug}`);
} catch (error) {
@@ -221,6 +251,52 @@ const AutomationsPage = () => {
}
};
const openImportModal = () => {
setImportName('');
setImportText('');
setImportModal(true);
};
const handleImportFile = async (e) => {
const file = e.target.files?.[0];
if (!file) return;
try {
setImportText(await file.text());
if (!importName.trim()) setImportName(file.name.replace(/\.json$/i, ''));
} catch {
toast.error('Could not read that file.');
}
e.target.value = '';
};
const handleImport = async () => {
let doc;
try {
doc = JSON.parse(importText);
} catch {
toast.error('That is not valid JSON. Paste a tramo workflow document.');
return;
}
if (!doc || typeof doc !== 'object' || !Array.isArray(doc.nodes)) {
toast.error('That JSON does not look like a workflow (missing a nodes array).');
return;
}
const name = importName.trim() || doc.name || 'Imported automation';
setBusy(true);
try {
const wf = await api.request('/tramo/workflows', {
method: 'POST', body: { name, doc: { ...doc, name } },
});
setImportModal(false);
toast.success(`Imported "${wf.name}"`);
navigate(`/automations/edit/${wf.slug}`);
} catch (error) {
toast.error(`Could not import: ${error.message}`);
} finally {
setBusy(false);
}
};
const handleToggleEnabled = async (wf) => {
try {
await api.request(`/tramo/workflows/${wf.slug}`, { method: 'PUT', body: { enabled: !wf.enabled } });
@@ -403,6 +479,83 @@ const AutomationsPage = () => {
};
// ── Renderers ──
const renderTemplates = () => {
const q = templateSearch.trim().toLowerCase();
const filtered = templates.filter((t) => !q
|| t.name.toLowerCase().includes(q)
|| (t.description || '').toLowerCase().includes(q));
// Favorites float to the top; otherwise preserve the incoming order.
const sorted = [...filtered].sort(
(a, b) => (favorites.has(a.id) ? 0 : 1) - (favorites.has(b.id) ? 0 : 1));
return (
<div className="tramo-templates">
<div className="tramo-templates__bar">
<div className="tramo-search">
<Search size={15} />
<input
type="text"
placeholder="Search templates..."
value={templateSearch}
onChange={(e) => setTemplateSearch(e.target.value)}
/>
</div>
<span className="tramo-templates__count">
{filtered.length} template{filtered.length === 1 ? '' : 's'}
</span>
</div>
{templatesLoading ? (
<EmptyState loading title="Loading templates..." />
) : sorted.length === 0 ? (
<EmptyState
icon={LayoutTemplate}
title={q ? 'No templates match your search' : 'No templates yet'}
description={q ? 'Try a different search.' : 'Import your own to get started.'}
/>
) : (
<div className="tramo-tpl-grid">
{sorted.map((t) => {
const meta = TEMPLATE_META[t.id] || DEFAULT_TEMPLATE_META;
const { Icon } = meta;
const fav = favorites.has(t.id);
return (
<div className="tramo-card" key={t.id}>
<div className="tramo-card__top">
<span className={`tramo-card__icon tramo-card__icon--${meta.brand}`}>
<Icon size={20} />
</span>
<button
type="button"
className={`tramo-card__fav${fav ? ' is-fav' : ''}`}
onClick={() => toggleFavorite(t.id)}
title={fav ? 'Remove from favorites' : 'Add to favorites'}
aria-pressed={fav}
>
<Star size={16} />
</button>
</div>
<h4 className="tramo-card__name">{t.name}</h4>
{t.description && <p className="tramo-card__desc">{t.description}</p>}
{meta.tags.length > 0 && (
<div className="tramo-card__tags">
{meta.tags.map((tag) => (
<span className="tramo-card__tag" key={tag}>{tag}</span>
))}
</div>
)}
<div className="tramo-card__foot">
<Button variant="default" size="sm" disabled={busy} onClick={() => handleFromTemplate(t)}>
<Plus size={14} /> Use template
</Button>
</div>
</div>
);
})}
</div>
)}
</div>
);
};
const renderWorkflows = () => (
<div className="card">
<div className="card-body">
@@ -705,14 +858,17 @@ const AutomationsPage = () => {
<Button variant="outline" size="sm" onClick={handleDeploy} disabled={busy}>
<Rocket size={14} /> Deploy
</Button>
<Button variant="secondary" size="sm" onClick={openTemplateModal}>
<LayoutTemplate size={14} /> New from template
</Button>
<Button variant="default" size="sm" onClick={openNewModal}>
<Plus size={14} /> New workflow
</Button>
</>
);
} else if (activeTab === 'templates') {
topbarActions = (
<Button variant="default" size="sm" onClick={openImportModal}>
<Upload size={14} /> Import template
</Button>
);
} else if (activeTab === 'runs') {
topbarActions = (
<Button variant="outline" size="sm" onClick={loadRuns} disabled={runsLoading}>
@@ -739,6 +895,7 @@ const AutomationsPage = () => {
<div className="sk-tabgroup__content">
<div className="sk-tabgroup__inner">
{activeTab === 'workflows' && renderWorkflows()}
{activeTab === 'templates' && renderTemplates()}
{activeTab === 'runs' && renderRuns()}
{activeTab === 'settings' && renderSettings()}
</div>
@@ -828,59 +985,50 @@ const AutomationsPage = () => {
</div>
</Modal>
{/* New from template modal */}
{/* Import template / workflow modal */}
<Modal
open={templateModal}
onClose={() => setTemplateModal(false)}
title="Start from a template"
open={importModal}
onClose={() => setImportModal(false)}
title="Import a template"
size="lg"
footer={(
<Button variant="outline" onClick={() => setTemplateModal(false)}>
<X size={14} /> Close
</Button>
<>
<Button variant="outline" onClick={() => setImportModal(false)}>Cancel</Button>
<Button variant="default" onClick={handleImport} disabled={busy || !importText.trim()}>
<Upload size={14} /> Import
</Button>
</>
)}
>
<p className="tramo-tpl-intro">
Pick a ready-made automation. You will land on the visual editor to
customize it and add the credentials its integrations need.
Paste a tramo workflow document (JSON), or load one from a file. It is
created as a new automation you can edit and deploy.
</p>
{templates.length === 0 ? (
<EmptyState icon={LayoutTemplate} title="No templates available" />
) : (
<div className="tramo-tpl-list">
{templates.map((t) => {
const meta = TEMPLATE_META[t.id] || DEFAULT_TEMPLATE_META;
const { Icon } = meta;
return (
<button
type="button"
className="tramo-tpl"
key={t.id}
onClick={() => handleFromTemplate(t)}
disabled={busy}
>
<span className={`tramo-tpl__icon tramo-tpl__icon--${meta.brand}`}>
<Icon size={20} />
</span>
<span className="tramo-tpl__body">
<span className="tramo-tpl__name">{t.name}</span>
{t.description && (
<span className="tramo-tpl__desc">{t.description}</span>
)}
{meta.tags.length > 0 && (
<span className="tramo-tpl__tags">
{meta.tags.map((tag) => (
<span className="tramo-tpl__tag" key={tag}>{tag}</span>
))}
</span>
)}
</span>
<ChevronRight className="tramo-tpl__arrow" size={18} />
</button>
);
})}
<div className="form-group">
<Label>Name (optional)</Label>
<Input
type="text"
value={importName}
placeholder="My imported automation"
onChange={(e) => setImportName(e.target.value)}
/>
</div>
<div className="form-group">
<div className="tramo-import__labelrow">
<Label>Workflow JSON</Label>
<label className="tramo-import__file">
<FileJson size={14} /> Load file
<input type="file" accept="application/json,.json" onChange={handleImportFile} hidden />
</label>
</div>
)}
<textarea
className="tramo-import__text"
value={importText}
placeholder={'{\n "name": "My flow",\n "nodes": [],\n "edges": []\n}'}
onChange={(e) => setImportText(e.target.value)}
spellCheck={false}
/>
</div>
</Modal>
{confirmDialog && (
@@ -214,77 +214,136 @@
opacity: 0.7;
}
.tramo-tpl-list {
/* Templates marketplace tab (page content) + Import modal (portaled). Kept at
top level so the portaled Import modal picks these up too. */
.tramo-templates {
display: flex;
flex-direction: column;
gap: 16px;
&__bar {
display: flex;
align-items: center;
gap: 12px;
}
&__count {
font-size: 12px;
opacity: 0.6;
white-space: nowrap;
}
}
.tramo-search {
display: flex;
align-items: center;
gap: 8px;
flex: 1;
max-width: 340px;
padding: 8px 12px;
border-radius: 9px;
border: 1px solid var(--border, rgba(128, 128, 128, 0.25));
background: var(--bg-elevated, rgba(128, 128, 128, 0.04));
svg { flex-shrink: 0; opacity: 0.55; }
input {
flex: 1;
min-width: 0;
border: 0;
outline: 0;
background: transparent;
color: inherit;
font-size: 13px;
&::placeholder { opacity: 0.5; }
}
}
.tramo-tpl-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
gap: 14px;
}
.tramo-card {
display: flex;
flex-direction: column;
gap: 10px;
}
.tramo-tpl {
display: flex;
align-items: flex-start;
gap: 14px;
text-align: left;
width: 100%;
padding: 14px 16px;
border-radius: 12px;
border: 1px solid var(--border, rgba(128, 128, 128, 0.25));
background: var(--bg-elevated, rgba(128, 128, 128, 0.04));
color: inherit;
cursor: pointer;
transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
padding: 16px;
border-radius: 14px;
border: 1px solid var(--border, rgba(128, 128, 128, 0.22));
background: var(--bg-card, rgba(128, 128, 128, 0.03));
transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
&:hover {
border-color: var(--accent-bright, #6366f1);
background: rgba(99, 102, 241, 0.06);
transform: translateY(-1px);
border-color: rgba(99, 102, 241, 0.4);
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
&:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
&__top {
display: flex;
align-items: flex-start;
justify-content: space-between;
}
&__icon {
flex-shrink: 0;
width: 42px;
height: 42px;
border-radius: 11px;
display: grid;
place-items: center;
background: rgba(128, 128, 128, 0.16);
color: var(--accent-bright, #6366f1);
color: var(--accent-bright, #818cf8);
&--telegram { background: rgba(42, 171, 238, 0.16); color: #2aabee; }
&--github { background: rgba(139, 92, 246, 0.16); color: #a78bfa; }
&--discord { background: rgba(88, 101, 242, 0.16); color: #7c86f5; }
}
&__body {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
&__fav {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border-radius: 8px;
border: 0;
background: transparent;
color: inherit;
opacity: 0.4;
cursor: pointer;
transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
&:hover { opacity: 0.85; background: rgba(128, 128, 128, 0.12); }
&.is-fav {
opacity: 1;
color: #f5b301;
svg { fill: #f5b301; }
}
}
&__name {
font-weight: 600;
margin: 0;
font-size: 14px;
font-weight: 600;
line-height: 1.3;
}
&__desc {
margin: 0;
flex: 1;
font-size: 12.5px;
opacity: 0.7;
line-height: 1.45;
opacity: 0.68;
}
&__tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 4px;
}
&__tag {
@@ -296,19 +355,54 @@
opacity: 0.9;
}
&__arrow {
flex-shrink: 0;
align-self: center;
opacity: 0.35;
transition: opacity 0.15s ease, transform 0.15s ease;
}
&__foot {
display: flex;
margin-top: auto;
padding-top: 4px;
&:hover &__arrow {
opacity: 0.9;
transform: translateX(2px);
> button { width: 100%; justify-content: center; }
}
}
/* Import modal */
.tramo-import__labelrow {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
}
.tramo-import__file {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12px;
padding: 4px 10px;
border-radius: 7px;
border: 1px solid var(--border, rgba(128, 128, 128, 0.3));
cursor: pointer;
opacity: 0.85;
&:hover { opacity: 1; border-color: var(--accent-bright, #6366f1); }
}
.tramo-import__text {
width: 100%;
min-height: 200px;
resize: vertical;
padding: 12px 14px;
border-radius: 10px;
border: 1px solid var(--border, rgba(128, 128, 128, 0.3));
background: var(--bg-elevated, rgba(128, 128, 128, 0.05));
color: inherit;
font-family: var(--font-mono, ui-monospace, monospace);
font-size: 12.5px;
line-height: 1.5;
&:focus { outline: 0; border-color: var(--accent-bright, #6366f1); }
&::placeholder { opacity: 0.4; }
}
/* New-automation two-column modal (portaled -> top-level scope). Kill the modal
body padding so the hero panel can bleed to the dialog edges. */
.tramo-newflow-modal .sk-modal__body { padding: 0; }