Skip to content

Commit

Permalink
Refactor rendering action cards
Browse files Browse the repository at this point in the history
  • Loading branch information
electrikmilk committed Nov 24, 2023
1 parent a604b11 commit 0472642
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,27 @@ export function renderShortcut(shortcutActions: Array<ActionData>) {
console.groupEnd();
}

function renderAction(identifier: string, action: ActionData): Node {
console.group(`Render ${action.WFWorkflowActionIdentifier}`);

const card = document.createElement('div');
card.className = 'card';

function renderCardContent(element: HTMLElement) {
const content = document.createElement('div');
content.className = 'card-content';

const list = document.createElement('div');
list.className = 'list';

const ul = document.createElement('ul');
ul.innerHTML = element.outerHTML;

list.appendChild(ul);
content.appendChild(list);

return content;
}

function renderAction(identifier: string, action: ActionData): Node {
console.group(`Render ${action.WFWorkflowActionIdentifier}`);

const card = document.createElement('div');
card.className = 'card';

renderActionConnection(card, action);

Expand All @@ -58,25 +66,20 @@ function renderAction(identifier: string, action: ActionData): Node {
}
}
if (actionData && actionData.render) {
const items = actionData.render(card, action.WFWorkflowActionParameters ?? []);
ul.innerHTML = items.innerHTML;
list.appendChild(ul);
content.appendChild(list);
card.appendChild(content);
card.innerHTML = renderCardContent(actionData.render(card, action.WFWorkflowActionParameters ?? [])).outerHTML;

console.log('Rendered by definition function.');
console.groupEnd();

return card;
}
const auto = document.createElement('div');
const header = actionData ? renderActionHeader(actionData) : renderHeader(renderActionIcon('gear', 'white', 'darkgray'), identifier);
ul.appendChild(header);

auto.appendChild(header);
if (action.WFWorkflowActionParameters) {
ul.appendChild(renderParameters(actionData, action.WFWorkflowActionParameters));
auto.appendChild(renderParameters(actionData, action.WFWorkflowActionParameters));
}
list.appendChild(ul);
content.appendChild(list);
card.appendChild(content);
card.appendChild(renderCardContent(auto));

console.log('Automatically rendered.');
console.groupEnd();
Expand Down

0 comments on commit 0472642

Please sign in to comment.