1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00
This commit is contained in:
Andrew Kingston 2020-10-27 09:37:20 +00:00
parent e9b9bbba99
commit 10252e9bc0
5 changed files with 30 additions and 31 deletions

View file

@ -3,14 +3,14 @@ import api from "../../api"
import Automation from "./Automation" import Automation from "./Automation"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
const automationActions = (store) => ({ const automationActions = store => ({
fetch: async () => { fetch: async () => {
const responses = await Promise.all([ const responses = await Promise.all([
api.get(`/api/automations`), api.get(`/api/automations`),
api.get(`/api/automations/definitions/list`), api.get(`/api/automations/definitions/list`),
]) ])
const jsonResponses = await Promise.all(responses.map((x) => x.json())) const jsonResponses = await Promise.all(responses.map(x => x.json()))
store.update((state) => { store.update(state => {
state.automations = jsonResponses[0] state.automations = jsonResponses[0]
state.blockDefinitions = { state.blockDefinitions = {
TRIGGER: jsonResponses[1].trigger, TRIGGER: jsonResponses[1].trigger,
@ -31,7 +31,7 @@ const automationActions = (store) => ({
const CREATE_AUTOMATION_URL = `/api/automations` const CREATE_AUTOMATION_URL = `/api/automations`
const response = await api.post(CREATE_AUTOMATION_URL, automation) const response = await api.post(CREATE_AUTOMATION_URL, automation)
const json = await response.json() const json = await response.json()
store.update((state) => { store.update(state => {
state.automations = [...state.automations, json.automation] state.automations = [...state.automations, json.automation]
store.actions.select(json.automation) store.actions.select(json.automation)
return state return state
@ -41,9 +41,9 @@ const automationActions = (store) => ({
const UPDATE_AUTOMATION_URL = `/api/automations` const UPDATE_AUTOMATION_URL = `/api/automations`
const response = await api.put(UPDATE_AUTOMATION_URL, automation) const response = await api.put(UPDATE_AUTOMATION_URL, automation)
const json = await response.json() const json = await response.json()
store.update((state) => { store.update(state => {
const existingIdx = state.automations.findIndex( const existingIdx = state.automations.findIndex(
(existing) => existing._id === automation._id existing => existing._id === automation._id
) )
state.automations.splice(existingIdx, 1, json.automation) state.automations.splice(existingIdx, 1, json.automation)
state.automations = state.automations state.automations = state.automations
@ -56,9 +56,9 @@ const automationActions = (store) => ({
const DELETE_AUTOMATION_URL = `/api/automations/${_id}/${_rev}` const DELETE_AUTOMATION_URL = `/api/automations/${_id}/${_rev}`
await api.delete(DELETE_AUTOMATION_URL) await api.delete(DELETE_AUTOMATION_URL)
store.update((state) => { store.update(state => {
const existingIdx = state.automations.findIndex( const existingIdx = state.automations.findIndex(
(existing) => existing._id === _id existing => existing._id === _id
) )
state.automations.splice(existingIdx, 1) state.automations.splice(existingIdx, 1)
state.automations = state.automations state.automations = state.automations
@ -72,24 +72,24 @@ const automationActions = (store) => ({
const TRIGGER_AUTOMATION_URL = `/api/automations/${_id}/trigger` const TRIGGER_AUTOMATION_URL = `/api/automations/${_id}/trigger`
return await api.post(TRIGGER_AUTOMATION_URL) return await api.post(TRIGGER_AUTOMATION_URL)
}, },
select: (automation) => { select: automation => {
store.update((state) => { store.update(state => {
state.selectedAutomation = new Automation(cloneDeep(automation)) state.selectedAutomation = new Automation(cloneDeep(automation))
state.selectedBlock = null state.selectedBlock = null
return state return state
}) })
}, },
addBlockToAutomation: (block) => { addBlockToAutomation: block => {
store.update((state) => { store.update(state => {
const newBlock = state.selectedAutomation.addBlock(cloneDeep(block)) const newBlock = state.selectedAutomation.addBlock(cloneDeep(block))
state.selectedBlock = newBlock state.selectedBlock = newBlock
return state return state
}) })
}, },
deleteAutomationBlock: (block) => { deleteAutomationBlock: block => {
store.update((state) => { store.update(state => {
const idx = state.selectedAutomation.automation.definition.steps.findIndex( const idx = state.selectedAutomation.automation.definition.steps.findIndex(
(x) => x.id === block.id x => x.id === block.id
) )
state.selectedAutomation.deleteBlock(block.id) state.selectedAutomation.deleteBlock(block.id)

View file

@ -36,7 +36,7 @@
{#if $backendUiStore.selectedDatabase && $backendUiStore.selectedDatabase._id} {#if $backendUiStore.selectedDatabase && $backendUiStore.selectedDatabase._id}
<div class="title"> <div class="title">
<h1>Tables</h1> <h1>Tables</h1>
<i on:click={modal.show} class="ri-add-circle-fill" /> <i data-cy="new-table" on:click={modal.show} class="ri-add-circle-fill" />
</div> </div>
<div class="hierarchy-items-container"> <div class="hierarchy-items-container">
{#each $backendUiStore.tables as table, idx} {#each $backendUiStore.tables as table, idx}

View file

@ -1,21 +1,21 @@
import { isUndefined, filter, some, includes } from "lodash/fp" import { isUndefined, filter, some, includes } from "lodash/fp"
import { pipe } from "../../../helpers" import { pipe } from "../../../helpers"
const normalString = (s) => (s || "").trim().toLowerCase() const normalString = s => (s || "").trim().toLowerCase()
export const isRootComponent = (c) => export const isRootComponent = c =>
isComponent(c) && isUndefined(c.props._component) isComponent(c) && isUndefined(c.props._component)
export const isComponent = (c) => { export const isComponent = c => {
const hasProp = (n) => !isUndefined(c[n]) const hasProp = n => !isUndefined(c[n])
return hasProp("name") && hasProp("props") return hasProp("name") && hasProp("props")
} }
export const searchAllComponents = (components, phrase) => { export const searchAllComponents = (components, phrase) => {
const hasPhrase = (...vals) => const hasPhrase = (...vals) =>
pipe(vals, [some((v) => includes(normalString(phrase))(normalString(v)))]) pipe(vals, [some(v => includes(normalString(phrase))(normalString(v)))])
const componentMatches = (c) => { const componentMatches = c => {
if (hasPhrase(c._instanceName, ...(c.tags || []))) return true if (hasPhrase(c._instanceName, ...(c.tags || []))) return true
if (isRootComponent(c)) return false if (isRootComponent(c)) return false
@ -29,7 +29,7 @@ export const searchAllComponents = (components, phrase) => {
} }
export const getExactComponent = (components, name, isScreen = false) => { export const getExactComponent = (components, name, isScreen = false) => {
return components.find((c) => return components.find(c =>
isScreen ? c.props._instanceName === name : c._instanceName === name isScreen ? c.props._instanceName === name : c._instanceName === name
) )
} }

View file

@ -1,7 +1,7 @@
import { split, last } from "lodash/fp" import { split, last } from "lodash/fp"
import { pipe } from "../../../helpers" import { pipe } from "../../../helpers"
export const splitName = (fullname) => { export const splitName = fullname => {
const componentName = pipe(fullname, [split("/"), last]) const componentName = pipe(fullname, [split("/"), last])
const libName = fullname.substring( const libName = fullname.substring(

View file

@ -1,6 +1,6 @@
import { last, flow } from "lodash/fp" import { last, flow } from "lodash/fp"
export const buildStyle = (styles) => { export const buildStyle = styles => {
let str = "" let str = ""
for (let s in styles) { for (let s in styles) {
if (styles[s]) { if (styles[s]) {
@ -11,15 +11,14 @@ export const buildStyle = (styles) => {
return str return str
} }
export const convertCamel = (str) => { export const convertCamel = str => {
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`) return str.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)
} }
export const pipe = (arg, funcs) => flow(funcs)(arg) export const pipe = (arg, funcs) => flow(funcs)(arg)
export const capitalise = (s) => export const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
s.substring(0, 1).toUpperCase() + s.substring(1)
export const get_name = (s) => (!s ? "" : last(s.split("/"))) export const get_name = s => (!s ? "" : last(s.split("/")))
export const get_capitalised_name = (name) => pipe(name, [get_name, capitalise]) export const get_capitalised_name = name => pipe(name, [get_name, capitalise])