budibase/packages/builder/src/actionsAndTriggers/Actions.svelte

115 lines
2.7 KiB
Svelte
Raw Normal View History

2019-07-13 11:35:57 +02:00
<script>
2020-02-03 10:50:30 +01:00
import getIcon from "../common/icon"
import { store } from "../builderStore"
import Button from "../common/Button.svelte"
import ButtonGroup from "../common/ButtonGroup.svelte"
import ActionView from "./ActionView.svelte"
import Modal from "../common/Modal.svelte"
import { pipe } from "../common/core"
import { keys, map, join } from "lodash/fp"
export let editingActionIsNew = false
export let editingAction = null
export let onActionEdit = action => {}
export let onActionDelete = action => {}
export let onActionSave = action => {}
export let onActionCancel = () => {}
$: isEditing = editingAction !== null
let actionsArray = []
store.subscribe(s => {
actionsArray = pipe(
s.actions,
[keys, map(k => s.actions[k])]
)
2020-02-03 10:50:30 +01:00
})
let getDefaultOptionsHtml = defaultOptions =>
pipe(
defaultOptions,
[
keys,
map(
k =>
`<span style="color:var(--slate)">${k}: </span>${JSON.stringify(
defaultOptions[k]
)}`
),
join("<br>"),
]
)
2020-02-03 10:50:30 +01:00
let actionEditingFinished = action => {
if (action) {
onActionSave(action)
2019-07-13 11:35:57 +02:00
} else {
2020-02-03 10:50:30 +01:00
onActionCancel()
2019-07-13 11:35:57 +02:00
}
2020-02-03 10:50:30 +01:00
}
2019-07-13 11:35:57 +02:00
</script>
2020-02-24 16:00:48 +01:00
<h3 class="budibase__title--3">Actions</h3>
2019-07-13 11:35:57 +02:00
{#if actionsArray}
2020-02-03 10:50:30 +01:00
<table class="fields-table uk-table uk-table-small uk-table-striped">
2019-07-13 11:35:57 +02:00
<thead>
2020-02-03 10:50:30 +01:00
<tr>
<th>Description</th>
<th>Behaviour Source</th>
<th>Behaviour Name</th>
<th>Default Options</th>
<th />
</tr>
2019-07-13 11:35:57 +02:00
</thead>
<tbody>
2020-02-03 10:50:30 +01:00
{#each actionsArray as action}
2019-07-13 11:35:57 +02:00
<tr>
2020-02-03 10:50:30 +01:00
<td class="table-content">{action.name}</td>
<td class="table-content">{action.behaviourSource}</td>
<td class="table-content">{action.behaviourName}</td>
<td class="table-content">
{@html getDefaultOptionsHtml(action.initialOptions)}
</td>
<td class="edit-button">
<span on:click={() => onActionEdit(action)}>
{@html getIcon('edit')}
</span>
<span on:click={() => onActionDelete(action)}>
{@html getIcon('trash')}
</span>
</td>
2019-07-13 11:35:57 +02:00
</tr>
2020-02-03 10:50:30 +01:00
{/each}
2019-07-13 11:35:57 +02:00
</tbody>
2020-02-03 10:50:30 +01:00
</table>
{:else}(no actions added){/if}
2019-07-13 11:35:57 +02:00
<Modal
title={editingActionIsNew ? 'Create Action' : 'Edit Action'}
bind:isOpen={isEditing}>
2020-02-03 10:50:30 +01:00
{#if isEditing}
<ActionView
action={editingAction}
allActions={$store.actions}
onFinished={actionEditingFinished}
isNew={editingActionIsNew} />
{/if}
2019-07-13 11:35:57 +02:00
</Modal>
<style>
2020-02-03 10:50:30 +01:00
.edit-button {
cursor: pointer;
color: var(--secondary25);
2020-02-03 10:50:30 +01:00
}
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
tr:hover .edit-button {
2019-07-13 11:35:57 +02:00
color: var(--secondary75);
2020-02-03 10:50:30 +01:00
}
2019-07-13 11:35:57 +02:00
2020-02-03 10:50:30 +01:00
.table-content {
font-weight: 500;
2020-02-03 10:50:30 +01:00
font-size: 0.9rem;
}
</style>