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

311 lines
6.7 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"
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="uk-margin config-item">
{#if testResult}
<button
transition:fade
class:passed={testResult === 'PASSED'}
class:failed={testResult === 'FAILED'}
class="test-result">
{testResult}
</button>
{/if}
<button class="workflow-button hoverable" on:click={testWorkflow}>
Test
</button>
</div>
{/if}
{#if selectedTab === 'SETUP'}
{#if workflowBlock}
<WorkflowBlockSetup {workflowBlock} />
2020-06-04 20:27:25 +02:00
<div class="buttons">
<button
data-cy="save-workflow-setup"
class="workflow-button hoverable"
on:click={saveWorkflow}>
2020-06-04 21:23:46 +02:00
Save Workflow
</button>
2020-06-04 20:30:44 +02:00
<button
class="delete-workflow-button hoverable"
on:click={deleteWorkflowBlock}>
2020-06-04 20:27:25 +02:00
Delete Block
</button>
</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>Name</label>
<div class="form">
<input
type="text"
class="budibase_input"
bind:value={workflow.name} />
</div>
2020-06-01 22:26:32 +02:00
</div>
2020-06-04 20:27:25 +02:00
<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">
<button
data-cy="save-workflow-setup"
class="workflow-button hoverable"
on:click={saveWorkflow}>
Save Workflow
</button>
2020-06-04 20:27:25 +02:00
<button class="delete-workflow-button" on:click={deleteWorkflow}>
Delete Workflow
</button>
</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: 20px;
font-weight: 600;
display: flex;
align-items: center;
2020-06-04 20:27:25 +02:00
margin-bottom: 18px;
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(--ink);
margin: 0px 0px 16px 0px;
}
2020-06-01 22:26:32 +02:00
.config-item {
2020-06-04 20:27:25 +02:00
margin: 0px 0px 4px 0px;
padding: 12px 0px;
2020-06-01 22:26:32 +02:00
}
2020-06-04 20:27:25 +02:00
.budibase_input {
height: 36px;
width: 244px;
2020-06-04 20:27:25 +02:00
border-radius: 3px;
background-color: var(--grey-2);
border: 1px solid var(--grey-2);
2020-06-04 20:27:25 +02:00
text-align: left;
color: var(--ink);
font-size: 14px;
padding-left: 12px;
2020-06-04 20:30:44 +02:00
}
2020-06-04 20:27:25 +02:00
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;
}
2020-06-04 20:27:25 +02:00
.form {
margin-top: 12px;
}
label {
font-weight: 500;
font-size: 14px;
2020-06-04 20:27:25 +02:00
color: var(--ink);
}
.buttons {
position: absolute;
bottom: 10px;
}
.delete-workflow-button {
cursor: pointer;
border: 1px solid var(--red);
border-radius: 3px;
width: 260px;
padding: 8px 16px;
display: flex;
justify-content: center;
align-items: center;
background: var(--white);
color: var(--red);
font-size: 14px;
font-weight: 500;
transition: all 2ms;
align-self: flex-end;
margin-bottom: 10px;
}
.delete-workflow-button:hover {
background: var(--red);
border: 1px solid var(--red);
color: var(--white);
}
2020-06-01 22:26:32 +02:00
.workflow-button {
2020-06-04 20:27:25 +02:00
cursor: pointer;
border: 1px solid var(--grey-4);
2020-06-04 20:27:25 +02:00
border-radius: 3px;
width: 100%;
2020-06-04 20:27:25 +02:00
padding: 8px 16px;
display: flex;
justify-content: center;
align-items: center;
background: white;
color: var(--ink);
font-size: 14px;
font-weight: 500;
2020-06-04 20:27:25 +02:00
transition: all 2ms;
2020-06-04 21:23:46 +02:00
margin-bottom: 10px;
}
2020-06-01 22:26:32 +02:00
2020-06-02 12:08:53 +02:00
.workflow-button:hover {
background: var(--grey-1);
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 {
2020-06-04 20:30:44 +02:00
background: #84c991;
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>