Skip to content

Commit 44935dc

Browse files
null bug fixes
1 parent cae753f commit 44935dc

File tree

4 files changed

+90
-29
lines changed

4 files changed

+90
-29
lines changed

src/cloud/components/Automations/actions/ActionConfigurationInput.tsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, { useMemo, useState } from 'react'
1+
import React, { useMemo } from 'react'
22
import FormSelect from '../../../../design/components/molecules/Form/atoms/FormSelect'
33
import FormRowItem from '../../../../design/components/molecules/Form/templates/FormRowItem'
44
import { pickBy } from 'ramda'
5-
import { BoostAST } from '../../../lib/automations'
6-
import { RefNode } from '../../../lib/automations/ast'
5+
import { BoostAST, BoostPrimitives } from '../../../lib/automations'
6+
import { LiteralNode, RefNode } from '../../../lib/automations/ast'
7+
import { StdPrimitives } from '../../../lib/automations/types'
78

89
const CONFIG_TYPES = [
910
{ label: 'Event', value: 'event' },
@@ -15,19 +16,25 @@ interface ActionConfigurationInputProps {
1516
value: BoostAST
1617
customInput: (
1718
onChange: ActionConfigurationInputProps['onChange'],
18-
value: any
19+
value: Extract<BoostAST, { type: 'literal' }> | null
1920
) => React.ReactNode
2021
eventDataOptions: Record<string, string>
21-
type?: string
22+
type: BoostPrimitives | StdPrimitives
23+
defaultValue: any
2224
}
2325
const ActionConfigurationInput = ({
2426
value,
2527
eventDataOptions,
2628
onChange,
2729
customInput,
2830
type: dataType,
31+
defaultValue,
2932
}: ActionConfigurationInputProps) => {
30-
const [type, setType] = useState(() => {
33+
const type = useMemo(() => {
34+
if (value == null) {
35+
return CONFIG_TYPES[1]
36+
}
37+
3138
if (value.type === 'reference') {
3239
if (value.identifier.startsWith('$event')) {
3340
return CONFIG_TYPES[0]
@@ -37,7 +44,7 @@ const ActionConfigurationInput = ({
3744
}
3845
}
3946
return CONFIG_TYPES[1]
40-
})
47+
}, [value])
4148

4249
const options = useMemo(() => {
4350
return Object.keys(
@@ -46,6 +53,10 @@ const ActionConfigurationInput = ({
4653
}, [eventDataOptions, dataType])
4754

4855
const normalized = useMemo(() => {
56+
if (value == null) {
57+
return ''
58+
}
59+
4960
if (value.type === 'reference') {
5061
if (value.identifier.startsWith('$event')) {
5162
return value.identifier.substr('$event.'.length)
@@ -56,13 +67,23 @@ const ActionConfigurationInput = ({
5667
}
5768
}
5869

59-
return value.type === 'literal' ? value.value.toString() : ''
70+
return value.type === 'literal' ? value.value?.toString() || '' : ''
6071
}, [value])
6172

6273
return (
6374
<>
6475
<FormRowItem>
65-
<FormSelect options={CONFIG_TYPES} value={type} onChange={setType} />
76+
<FormSelect
77+
options={CONFIG_TYPES}
78+
value={type}
79+
onChange={(val) => {
80+
if (val.value === 'event') {
81+
onChange(RefNode('$event.'))
82+
} else {
83+
onChange(LiteralNode(dataType, defaultValue))
84+
}
85+
}}
86+
/>
6687
</FormRowItem>
6788
<FormRowItem>
6889
{type.value === 'event' && (
@@ -72,7 +93,13 @@ const ActionConfigurationInput = ({
7293
onChange={({ value }) => onChange(RefNode(`$event.${value}`))}
7394
/>
7495
)}
75-
{type.value === 'custom' && customInput(onChange, value)}
96+
{type.value === 'custom' &&
97+
customInput(
98+
onChange,
99+
value == null || value.type !== 'literal'
100+
? LiteralNode(dataType, defaultValue)
101+
: value
102+
)}
76103
</FormRowItem>
77104
</>
78105
)

src/cloud/components/Automations/actions/CreateDocActionConfigurator.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ const CreateDocActionConfigurator = ({
4141
<ActionConfigurationInput
4242
value={constructorTree.title}
4343
type={'string'}
44+
defaultValue=''
4445
onChange={(title) =>
4546
onChange(StructNode({ ...constructorTree, title }))
4647
}
4748
eventDataOptions={eventDataOptions}
4849
customInput={(onChange, value) => {
4950
return (
5051
<FormInput
51-
value={value}
52+
value={value?.value || ''}
5253
onChange={(ev) =>
5354
onChange(LiteralNode('string', ev.target.value))
5455
}
@@ -60,15 +61,16 @@ const CreateDocActionConfigurator = ({
6061
<FormRow row={{ title: 'Emoji' }}>
6162
<ActionConfigurationInput
6263
value={constructorTree.emoji}
63-
type={'string'}
64+
type='string'
65+
defaultValue=''
6466
onChange={(emoji) =>
6567
onChange(StructNode({ ...constructorTree, emoji }))
6668
}
6769
eventDataOptions={eventDataOptions}
6870
customInput={(onChange, value) => {
6971
return (
7072
<FormEmoji
71-
emoji={value}
73+
emoji={value?.value}
7274
defaultIcon={mdiFileDocumentOutline}
7375
setEmoji={(emojiStr) =>
7476
onChange(LiteralNode('string', emojiStr))
@@ -81,15 +83,16 @@ const CreateDocActionConfigurator = ({
8183
<FormRow row={{ title: 'Content' }}>
8284
<ActionConfigurationInput
8385
value={constructorTree.content}
84-
type={'string'}
86+
type='string'
87+
defaultValue=''
8588
onChange={(content) =>
8689
onChange(StructNode({ ...constructorTree, content }))
8790
}
8891
eventDataOptions={eventDataOptions}
8992
customInput={(onChange, value) => {
9093
return (
9194
<FormTextarea
92-
value={value}
95+
value={value?.value}
9396
onChange={(ev) =>
9497
onChange(LiteralNode('string', ev.target.value))
9598
}
@@ -102,14 +105,15 @@ const CreateDocActionConfigurator = ({
102105
<ActionConfigurationInput
103106
value={constructorTree.parentFolder}
104107
type={'folder'}
108+
defaultValue={undefined}
105109
onChange={(parentFolder) =>
106110
onChange(StructNode({ ...constructorTree, parentFolder }))
107111
}
108112
eventDataOptions={eventDataOptions}
109113
customInput={(onChange, value) => {
110114
return (
111115
<FolderSelect
112-
value={value}
116+
value={value?.value}
113117
onChange={(id) => onChange(LiteralNode('folder', id))}
114118
/>
115119
)

src/cloud/components/Automations/actions/PropertySelect.tsx

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { dissoc } from 'ramda'
21
import { mdiClose, mdiPlus } from '@mdi/js'
32
import React, { useCallback, useMemo } from 'react'
43
import Button from '../../../../design/components/atoms/Button'
@@ -10,8 +9,9 @@ import PropRegisterCreationForm from '../../Props/PropRegisterModal/PropRegister
109
import ActionConfigurationInput from './ActionConfigurationInput'
1110
import { useModal } from '../../../../design/lib/stores/modal'
1211
import { PropData } from '../../../interfaces/db/props'
13-
import { BoostAST } from '../../../lib/automations'
12+
import { BoostAST, BoostPrimitives } from '../../../lib/automations'
1413
import { LiteralNode, OpNode, StructNode } from '../../../lib/automations/ast'
14+
import { StdPrimitives } from '../../../lib/automations/types'
1515

1616
export interface PropertySelectProps {
1717
value: SupportedType[]
@@ -62,8 +62,20 @@ const PropertySelect = ({
6262
</FormRowItem>
6363
<FormRowItem>
6464
<ActionConfigurationInput
65-
value={val}
65+
value={
66+
val.type === 'operation' &&
67+
val.input.type === 'constructor' &&
68+
val.input.info.type === 'struct'
69+
? val.input.info.refs.data ||
70+
LiteralNode('propData', { type: 'string', data: null })
71+
: val
72+
}
6673
type={getDataTypeForPropType(propType)}
74+
defaultValue={{
75+
type: propType,
76+
subType,
77+
data: null,
78+
}}
6779
onChange={(data) => {
6880
if (data.type === 'literal') {
6981
addProp(key, data)
@@ -99,9 +111,17 @@ const PropertySelect = ({
99111
>
100112
<PropPickerRaw
101113
propName={key}
102-
propData={val.type === 'literal' ? val.value : null}
114+
propData={
115+
val.type === 'literal'
116+
? val.value
117+
: {
118+
type: propType,
119+
subType,
120+
data: null,
121+
}
122+
}
103123
updateProp={(data) =>
104-
onChange(LiteralNode('propData', data?.data))
124+
onChange(LiteralNode('propData', data))
105125
}
106126
disabled={false}
107127
isLoading={false}
@@ -115,7 +135,9 @@ const PropertySelect = ({
115135
<FormRowItem>
116136
<Button
117137
iconPath={mdiClose}
118-
onClick={() => onChange(dissoc(key, value))}
138+
onClick={() =>
139+
onChange(value.filter((ref) => key !== ref.key.value))
140+
}
119141
></Button>
120142
</FormRowItem>
121143
</FormRow>
@@ -159,20 +181,22 @@ const PropertySelect = ({
159181

160182
export default PropertySelect
161183

162-
function getDataTypeForPropType(type: PropData['type']): string | undefined {
184+
function getDataTypeForPropType(
185+
type: PropData['type']
186+
): BoostPrimitives | StdPrimitives {
163187
switch (type) {
164188
case 'number':
189+
case 'status':
165190
return 'number'
166191
case 'string':
167-
return 'string'
168192
default:
169-
return undefined
193+
return 'string'
170194
}
171195
}
172196

173197
function getPropTypeFromAst(x: SupportedType['val']) {
174198
if (x.type === 'literal') {
175-
return [x.value.subType, x.value.subType]
199+
return [x.value.type, x.value.subType]
176200
}
177201

178202
if (

src/cloud/components/Automations/actions/UpdateDocActionConfigurator.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ const UpdateDocActionConfigurator = ({
101101
<FormRow row={{ title: 'Title' }}>
102102
<ActionConfigurationInput
103103
value={contentNodes.title}
104+
type='string'
105+
defaultValue=''
104106
onChange={(title) => setContent({ title })}
105107
eventDataOptions={eventDataOptions}
106108
customInput={(onChange, value) => {
107109
return (
108110
<FormInput
109-
value={value}
111+
value={value?.value}
110112
onChange={(ev) =>
111113
onChange(LiteralNode('string', ev.target.value))
112114
}
@@ -118,12 +120,14 @@ const UpdateDocActionConfigurator = ({
118120
<FormRow row={{ title: 'Emoji' }}>
119121
<ActionConfigurationInput
120122
value={contentNodes.emoji}
123+
type='string'
124+
defaultValue=''
121125
onChange={(emoji) => setContent({ emoji })}
122126
eventDataOptions={eventDataOptions}
123127
customInput={(onChange, value) => {
124128
return (
125129
<FormEmoji
126-
emoji={value}
130+
emoji={value?.value}
127131
defaultIcon={mdiFileDocumentOutline}
128132
setEmoji={(emoji) => onChange(LiteralNode('string', emoji))}
129133
/>
@@ -134,12 +138,14 @@ const UpdateDocActionConfigurator = ({
134138
<FormRow row={{ title: 'Content' }}>
135139
<ActionConfigurationInput
136140
value={contentNodes.content}
141+
type='string'
142+
defaultValue=''
137143
onChange={(content) => setContent({ content })}
138144
eventDataOptions={eventDataOptions}
139145
customInput={(onChange, value) => {
140146
return (
141147
<FormTextarea
142-
value={value}
148+
value={value?.value}
143149
onChange={(ev) =>
144150
onChange(LiteralNode('string', ev.target.value))
145151
}

0 commit comments

Comments
 (0)