Removed debugging statements and updated event data for screen create workflows

This commit is contained in:
Dean 2022-04-07 09:35:12 +01:00
parent 679b2339bb
commit 737a7b78d1
4 changed files with 40 additions and 26 deletions

View File

@ -22,6 +22,7 @@ export const Events = {
}, },
SCREEN: { SCREEN: {
CREATED: "Screen Created", CREATED: "Screen Created",
CREATE_ROLE_UPDATED: "Changed Role On Screen Creation"
}, },
AUTOMATION: { AUTOMATION: {
CREATED: "Automation Created", CREATED: "Automation Created",

View File

@ -1,10 +1,11 @@
<script> <script>
import { store, selectedAccessRole } from "builderStore" import { store, selectedAccessRole } from "builderStore"
import { ModalContent, Layout, Select } from "@budibase/bbui" import { ModalContent, Layout, Select, Divider } from "@budibase/bbui"
import { tables, datasources, roles } from "stores/backend" import { tables, datasources, roles } from "stores/backend"
import getTemplates from "builderStore/store/screenTemplates" import getTemplates from "builderStore/store/screenTemplates"
import ICONS from "../../backend/DatasourceNavigator/icons" import ICONS from "../../backend/DatasourceNavigator/icons"
import { IntegrationNames } from "constants" import { IntegrationNames } from "constants"
import analytics, { Events } from "analytics"
export let onCancel export let onCancel
export let onConfirm export let onConfirm
@ -12,14 +13,21 @@
let selectedScreens = [] let selectedScreens = []
let screenAccessRole = $selectedAccessRole + "" let screenAccessRole = $selectedAccessRole + ""
const toggleScreenSelection = table => { const toggleScreenSelection = (table, datasource) => {
if (selectedScreens.find(s => s.table === table.name)) { if (selectedScreens.find(s => s.table === table.name)) {
selectedScreens = selectedScreens.filter( selectedScreens = selectedScreens.filter(
screen => screen.table !== table.name screen => screen.table !== table.name
) )
} else { } else {
let partialTemplates = getTemplates($store, $tables.list).filter( let partialTemplates = getTemplates($store, $tables.list).reduce(
template => template.table === table.name (acc, template) => {
if (template.table === table.name) {
template.datasource = datasource.name
acc.push(template)
}
return acc
},
[]
) )
selectedScreens = [...partialTemplates, ...selectedScreens] selectedScreens = [...partialTemplates, ...selectedScreens]
} }
@ -33,15 +41,11 @@
} }
$: filteredSources = $datasources.list.reduce((acc, datasource) => { $: filteredSources = $datasources.list.reduce((acc, datasource) => {
acc["restSources"] = !acc["restSources"] ? [] : acc["restSources"] if (datasource.source !== IntegrationNames.REST && datasource["entities"]) {
acc["otherSources"] = !acc["otherSources"] ? [] : acc["otherSources"] acc.push(datasource)
if (datasource.source === IntegrationNames.REST) {
acc["restSources"].push(datasource)
} else {
acc["otherSources"].push(datasource)
} }
return acc return acc
}, {}) }, [])
</script> </script>
<ModalContent <ModalContent
@ -54,7 +58,7 @@
size="L" size="L"
> >
<Layout noPadding gap="XS"> <Layout noPadding gap="XS">
{#each filteredSources.otherSources as datasource} {#each filteredSources as datasource}
<div class="data-source-header"> <div class="data-source-header">
<div class="datasource-icon"> <div class="datasource-icon">
<svelte:component <svelte:component
@ -72,7 +76,7 @@
<div <div
class="data-source-entry" class="data-source-entry"
class:selected={selectedScreens.find(x => x.table === table.name)} class:selected={selectedScreens.find(x => x.table === table.name)}
on:click={() => toggleScreenSelection(table)} on:click={() => toggleScreenSelection(table, datasource)}
> >
<svg <svg
width="16px" width="16px"
@ -95,7 +99,7 @@
x => x.table === datasource.entities[table_key].name x => x.table === datasource.entities[table_key].name
)} )}
on:click={() => on:click={() =>
toggleScreenSelection(datasource.entities[table_key])} toggleScreenSelection(datasource.entities[table_key], datasource)}
> >
<svg <svg
width="16px" width="16px"
@ -111,8 +115,16 @@
{/each} {/each}
{/if} {/if}
{/each} {/each}
<div>
<Divider size="S" />
</div>
<Select <Select
bind:value={screenAccessRole} bind:value={screenAccessRole}
on:change={() => {
analytics.captureEvent(Events.SCREEN.CREATE_ROLE_UPDATED, {
screenAccessRole,
})
}}
label="Screen access" label="Screen access"
getOptionLabel={role => role.name} getOptionLabel={role => role.name}
getOptionValue={role => role._id} getOptionValue={role => role._id}

View File

@ -4,6 +4,7 @@
import { selectedAccessRole, allScreens } from "builderStore" import { selectedAccessRole, allScreens } from "builderStore"
import { get } from "svelte/store" import { get } from "svelte/store"
import { roles } from "stores/backend" import { roles } from "stores/backend"
import analytics, { Events } from "analytics"
export let onConfirm export let onConfirm
export let onCancel export let onCancel
@ -53,7 +54,6 @@
cancelText={"Back"} cancelText={"Back"}
disabled={!screenAccessRole || !screenUrl || routeError || !touched} disabled={!screenAccessRole || !screenUrl || routeError || !touched}
> >
<!-- <Input label="Name" bind:value={screenName} /> -->
<Input <Input
label="URL" label="URL"
error={routeError} error={routeError}
@ -62,6 +62,11 @@
/> />
<Select <Select
bind:value={screenAccessRole} bind:value={screenAccessRole}
on:change={() => {
analytics.captureEvent(Events.SCREEN.CREATE_ROLE_UPDATED, {
screenAccessRole,
})
}}
label="Screen access" label="Screen access"
getOptionLabel={role => role.name} getOptionLabel={role => role.name}
getOptionValue={role => role._id} getOptionValue={role => role._id}
@ -69,6 +74,3 @@
options={$roles} options={$roles}
/> />
</ModalContent> </ModalContent>
<style>
</style>

View File

@ -11,7 +11,6 @@
import { tables } from "stores/backend" import { tables } from "stores/backend"
let pendingScreen let pendingScreen
let showProgressCircle = false
// Modal refs // Modal refs
let newScreenModal let newScreenModal
@ -24,7 +23,6 @@
// Reset state when showing modal again // Reset state when showing modal again
pendingScreen = null pendingScreen = null
showProgressCircle = false
} }
// Creates an array of screens, checking and sanitising their URLs // Creates an array of screens, checking and sanitising their URLs
@ -32,7 +30,6 @@
if (!screens?.length) { if (!screens?.length) {
return return
} }
showProgressCircle = true
try { try {
for (let screen of screens) { for (let screen of screens) {
@ -61,6 +58,8 @@
if (screen.template) { if (screen.template) {
analytics.captureEvent(Events.SCREEN.CREATED, { analytics.captureEvent(Events.SCREEN.CREATED, {
template: screen.template, template: screen.template,
datasource: screen.datasource,
screenAccessRole,
}) })
} }
@ -75,8 +74,6 @@
} catch (error) { } catch (error) {
notifications.error("Error creating screens") notifications.error("Error creating screens")
} }
showProgressCircle = false
} }
// Checks if any screens exist in the store with the given route and // Checks if any screens exist in the store with the given route and
@ -119,12 +116,14 @@
// Handler for DatasourceModal // Handler for DatasourceModal
const confirmScreenDatasources = async ({ templates, screenAccessRole }) => { const confirmScreenDatasources = async ({ templates, screenAccessRole }) => {
console.log("selected ", screenAccessRole)
console.log("global ", $selectedAccessRole)
// // Handle template selection // // Handle template selection
if (templates?.length > 1) { if (templates?.length > 1) {
// Autoscreens, so create immediately // Autoscreens, so create immediately
const screens = templates.map(template => template.create()) const screens = templates.map(template => {
let screenTemplate = template.create()
screenTemplate.datasource = template.datasource
return screenTemplate
})
await createScreens({ screens, screenAccessRole }) await createScreens({ screens, screenAccessRole })
} }
} }