Skip to content

Commit

Permalink
Draft implementation of dictionary action and set and get value actions
Browse files Browse the repository at this point in the history
  • Loading branch information
electrikmilk committed Apr 26, 2024
1 parent 34cbe2d commit 2a6e789
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import Output from "~/actions/output";
import CopyToClipboard from "~/actions/copy-to-clipboard";
import RunShortcut from "~/actions/run-shortcut";
import CalculateExpression from "~/actions/calculate-expression";
import Dictionary from "~/actions/dictionary";
import GetDictionary from "~/actions/get-dictionary";
import GetDictionaryValue from "~/actions/get-dictionary-value";
import setDictionaryValue from "~/actions/set-dictionary-value";

interface ActionDefinitions {
[key: string]: ActionDefinition
Expand Down Expand Up @@ -75,6 +79,10 @@ export let actions: ActionDefinitions = {
'setclipboard': CopyToClipboard,
'runworkflow': RunShortcut,
'calculateexpression': CalculateExpression,
'dictionary': Dictionary,
'detect.dictionary': GetDictionary,
'getvalueforkey': GetDictionaryValue,
'setvalueforkey': setDictionaryValue,
};

export function actionText(value: string): HTMLElement {
Expand Down
85 changes: 85 additions & 0 deletions src/actions/dictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {renderActionHeader, renderTable} from "~/render";
import {actions} from "~/actions";
import {renderValue} from "~/value";

interface DictionaryParameters {
WFItems: WFItems
}

interface WFItems {
Value: Value
}

interface Value {
WFDictionaryFieldValueItems: DictionaryItem[]
}

interface DictionaryItem {
WFKey: Object,
WFItemType: Number,
WFValue: WFValue,

Key: Object,
Type: Number,
Value: WFValue,
}

interface WFValue {
Value: Object,
WFSerializationType: string
}

export default {
title: 'Dictionary',
color: 'white',
background: '#fc880f',
icon: 'book_fill',
render: (container: HTMLElement, params: DictionaryParameters) => {
const action = document.createElement('div');
const header = renderActionHeader(actions['dictionary']);
action.appendChild(header);

for (let item of params.WFItems.Value.WFDictionaryFieldValueItems) {
item.Key = item.WFKey
item.Type = item.WFItemType
item.Value = item.WFValue
// @ts-ignore
delete item.WFKey;
// @ts-ignore
delete item.WFItemType;
// @ts-ignore
delete item.WFValue;
}

action.appendChild(renderTable(params.WFItems.Value.WFDictionaryFieldValueItems, function (key: any, value: any) {
if (key === 'Type') {
switch (value) {
case 0:
return 'Text';
case 3:
return 'Number';
case 2:
return 'Array';
case 1:
return 'Dictionary';
case 4:
return 'Boolean';
}
}

const valueElement = renderValue(value, key);
valueElement.classList.add('sp-unstyled-value');

return valueElement;
}));

const br = document.createElement('br');
action.appendChild(br);

return action;
}
}

function dictToJSON() {

}
25 changes: 25 additions & 0 deletions src/actions/get-dictionary-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {renderValue} from "~/value";
import {renderActionHeader} from "~/render";
import {actions, actionText} from "~/actions";

interface GetDictionaryValueParameters {
WFGetDictionaryValueType: string
WFInput: string | object
WFDictionaryKey: string | object
}

export default {
title: 'Get',
color: 'white',
background: '#fc880f',
icon: 'book_fill',
render: (container: HTMLElement, params: GetDictionaryValueParameters) => {
let content: HTMLElement[] = [renderValue(params.WFGetDictionaryValueType)];
if (params.WFGetDictionaryValueType === 'Value') {
content.push(actionText('for'), renderValue(params['WFDictionaryKey'], 'Key'));
}
content.push(actionText('in'), renderValue(params['WFInput'], 'Dictionary'))

return renderActionHeader(actions['getvalueforkey'], ...content);
}
}
19 changes: 19 additions & 0 deletions src/actions/get-dictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {renderValue} from "~/value";
import {renderActionHeader} from "~/render";
import {actions} from "~/actions";

interface GetDictionaryParameters {
WFInput: string | object
}

export default {
title: 'Get dictionary from',
color: 'white',
background: '#fc880f',
icon: 'book_fill',
render: (container: HTMLElement, params: GetDictionaryParameters) => {
return renderActionHeader(actions['detect.dictionary'],
renderValue(params['WFInput'], 'Input'),
);
}
}
25 changes: 25 additions & 0 deletions src/actions/set-dictionary-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {renderValue} from "~/value";
import {renderActionHeader} from "~/render";
import {actions, actionText} from "~/actions";

interface SetDictionaryValueParameters {
WFInput: string | object
WFDictionaryKey: string | object
WFGetDictionaryValueType: string | object
}

export default {
title: 'Set',
color: 'white',
background: '#fc880f',
icon: 'book_fill',
render: (container: HTMLElement, params: SetDictionaryValueParameters) => {
return renderActionHeader(actions['setvalueforkey'],
renderValue(params['WFInput'], 'Key'),
actionText('to'),
renderValue(params['WFGetDictionaryValueType'], 'Value'),
actionText('in'),
renderValue(params['WFInput'], 'Dictionary'),
);
}
}
4 changes: 2 additions & 2 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const contentItemTypes = {
"WFContactContentItem": "Contact",
"WFDateContentItem": "Date",
"WFEmailAddressContentItem": "Email address",
"WFDictionaryContentItem": "Dictionary",
"WFFolderContentItem": "Folder",
"WFGenericFileContentItem": "File",
"WFImageContentItem": "Image",
Expand Down Expand Up @@ -377,8 +378,7 @@ export function renderTable(data: Array<Object>, callback: Function) {
footer.className = 'sp-action-list-footer';
const itemsSize = data.length;
const s = itemsSize ? 's' : null;
footer.innerHTML = `<td>${itemsSize} item${s}</td>`;
footer.innerHTML += '<td></td>'.repeat(itemsSize - 1)
footer.innerHTML = `<td>${itemsSize} item${s}</td><td></td><td></td>`;
tbody.appendChild(footer);

table.appendChild(tbody);
Expand Down

0 comments on commit 2a6e789

Please sign in to comment.