budibase/packages/builder/src/components/workflow/SetupPanel/SetupPanel.svelte

241 lines
5.2 KiB
Svelte
Raw Normal View History

<script>
2020-06-01 22:31:55 +02:00
import { fade } from "svelte/transition"
import { onMount, getContext } from "svelte"
import { backendUiStore, workflowStore } from "builderStore"
import { notifier } from "builderStore/store/notifications"
import WorkflowBlockSetup from "./WorkflowBlockSetup.svelte"
import DeleteWorkflowModal from "./DeleteWorkflowModal.svelte"
2020-08-18 18:14:35 +02:00
import { Button, Input } from "@budibase/bbui"
const { open, close } = getContext("simple-modal")
2020-06-02 12:08:53 +02:00
const ACCESS_LEVELS = [
{
name: "Admin",
2020-06-02 12:40:33 +02:00
key: "ADMIN",
canExecute: true,
editable: false,
2020-06-02 12:08:53 +02:00
},
{
name: "Power User",
2020-06-02 12:40:33 +02:00
key: "POWER_USER",
canExecute: true,
editable: false,
2020-06-02 12:40:33 +02:00
},
]
2020-06-02 12:08:53 +02:00
2020-06-01 22:26:32 +02:00
let selectedTab = "SETUP"
let testResult
$: workflow =
$workflowStore.currentWorkflow && $workflowStore.currentWorkflow.workflow
$: workflowBlock = $workflowStore.selectedWorkflowBlock
function deleteWorkflow() {
open(
DeleteWorkflowModal,
{
onClosed: close,
},
{ styleContent: { padding: "0" } }
)
}
function deleteWorkflowBlock() {
workflowStore.actions.deleteWorkflowBlock(workflowBlock)
notifier.info("Workflow block deleted.")
}
2020-06-01 22:26:32 +02:00
function testWorkflow() {
testResult = "PASSED"
}
2020-06-04 21:23:46 +02:00
async function saveWorkflow() {
const workflow = $workflowStore.currentWorkflow.workflow
await workflowStore.actions.save({
instanceId: $backendUiStore.selectedDatabase._id,
workflow,
})
notifier.success(`Workflow ${workflow.name} saved.`)
}
</script>
<section>
<header>
2020-06-01 22:26:32 +02:00
<span
class="hoverable"
class:selected={selectedTab === 'SETUP'}
2020-06-01 22:31:55 +02:00
on:click={() => {
2020-06-01 22:26:32 +02:00
selectedTab = 'SETUP'
testResult = null
}}>
Setup
</span>
{#if !workflowBlock}
<span
2020-06-04 20:27:25 +02:00
class="test-tab"
2020-06-01 22:26:32 +02:00
class:selected={selectedTab === 'TEST'}
on:click={() => (selectedTab = 'TEST')}>
Test
</span>
{/if}
</header>
2020-06-01 22:26:32 +02:00
{#if selectedTab === 'TEST'}
<div class="bb-margin-m">
2020-06-01 22:26:32 +02:00
{#if testResult}
<button
transition:fade
class:passed={testResult === 'PASSED'}
class:failed={testResult === 'FAILED'}
class="test-result">
{testResult}
</button>
{/if}
2020-06-26 15:38:29 +02:00
<Button secondary wide on:click={testWorkflow}>Test Workflow</Button>
2020-06-01 22:26:32 +02:00
</div>
{/if}
{#if selectedTab === 'SETUP'}
{#if workflowBlock}
<WorkflowBlockSetup {workflowBlock} />
2020-06-04 20:27:25 +02:00
<div class="buttons">
<Button
2020-06-26 15:38:29 +02:00
green
wide
data-cy="save-workflow-setup"
on:click={saveWorkflow}>
2020-06-04 21:23:46 +02:00
Save Workflow
</Button>
2020-06-26 15:38:29 +02:00
<Button red wide on:click={deleteWorkflowBlock}>Delete Block</Button>
2020-06-04 20:27:25 +02:00
</div>
2020-06-01 22:26:32 +02:00
{:else if $workflowStore.currentWorkflow}
2020-06-04 20:27:25 +02:00
<div class="panel">
<div class="panel-body">
<div class="block-label">Workflow: {workflow.name}</div>
<div class="config-item">
<label class="uk-form-label">User Access</label>
<div class="access-levels">
{#each ACCESS_LEVELS as level}
2020-06-04 20:27:25 +02:00
<span class="access-level">
<label>{level.name}</label>
2020-06-25 17:02:30 +02:00
<input
class="uk-checkbox"
type="checkbox"
disabled={!level.editable}
bind:checked={level.canExecute} />
2020-06-04 20:27:25 +02:00
</span>
{/each}
</div>
2020-06-02 12:08:53 +02:00
</div>
</div>
2020-06-04 20:27:25 +02:00
<div class="buttons">
2020-06-26 15:38:29 +02:00
<Button
green
wide
data-cy="save-workflow-setup"
on:click={saveWorkflow}>
Save Workflow
</Button>
2020-06-26 15:38:29 +02:00
<Button red wide on:click={deleteWorkflow}>Delete Workflow</Button>
2020-06-04 20:27:25 +02:00
</div>
</div>
2020-06-01 22:26:32 +02:00
{/if}
{/if}
</section>
<style>
section {
display: flex;
flex-direction: column;
height: 100%;
2020-06-04 20:27:25 +02:00
justify-content: space-between;
}
.panel-body {
flex: 1;
}
2020-06-04 20:27:25 +02:00
.panel {
display: flex;
flex-direction: column;
justify-content: space-between;
}
header {
font-size: 18px;
font-weight: 600;
font-family: inter;
display: flex;
align-items: center;
margin-bottom: 20px;
2020-06-04 20:27:25 +02:00
color: var(--ink);
}
2020-06-01 22:26:32 +02:00
.selected {
2020-06-04 20:27:25 +02:00
color: var(--ink);
}
.block-label {
font-weight: 500;
font-size: 14px;
color: var(--grey-7);
margin-bottom: 20px;
}
2020-06-01 22:26:32 +02:00
.config-item {
margin-bottom: 20px;
2020-06-01 22:26:32 +02:00
}
header > span {
color: var(--grey-5);
2020-06-01 22:26:32 +02:00
margin-right: 20px;
cursor: pointer;
2020-06-01 22:26:32 +02:00
}
label {
font-weight: 500;
font-size: 14px;
2020-06-04 20:27:25 +02:00
color: var(--ink);
}
.buttons {
position: absolute;
bottom: 20px;
display: grid;
width: 260px;
gap: 12px;
2020-06-02 12:08:53 +02:00
}
.access-level {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 20px;
}
.access-level label {
font-weight: normal;
2020-06-04 20:27:25 +02:00
color: var(--ink);
2020-06-02 12:08:53 +02:00
}
2020-06-01 22:26:32 +02:00
.test-result {
border: none;
width: 100%;
2020-06-04 20:27:25 +02:00
border-radius: 3px;
2020-06-01 22:26:32 +02:00
height: 32px;
2020-06-04 20:27:25 +02:00
font-size: 14px;
2020-06-01 22:26:32 +02:00
font-weight: 500;
color: var(--white);
text-align: center;
margin-bottom: 10px;
}
.passed {
background: var(--green);
2020-06-01 22:26:32 +02:00
}
.failed {
2020-06-04 20:27:25 +02:00
background: var(--red);
2020-06-01 22:26:32 +02:00
}
</style>