Skip to content

Commit cfd6ddd

Browse files
committed
fix bug in multirow delete, refactor based on comments
1 parent 4416390 commit cfd6ddd

File tree

10 files changed

+34
-46
lines changed

10 files changed

+34
-46
lines changed

packages/backend/src/apps/custom-api/actions/http-request/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,22 @@ const action: IRawAction = {
5353
required: false,
5454
description: 'Add custom headers here.',
5555
variables: true,
56-
customButtonText: 'Add',
56+
addRowButtonText: 'Add',
5757
hideBlankRow: true,
58-
showDivider: false,
5958
subFields: [
6059
{
6160
placeholder: 'Key',
6261
key: 'key',
6362
type: 'string' as const,
6463
required: true,
6564
variables: false,
66-
customStyle: { flex: 0.5 },
6765
},
6866
{
6967
placeholder: 'Value',
7068
key: 'value',
7169
type: 'string' as const,
7270
required: true,
7371
variables: true,
74-
isSingleLine: true,
75-
customStyle: { flex: 1, minWidth: 0 },
7672
},
7773
],
7874
},

packages/backend/src/apps/custom-api/actions/http-request/schema.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@ export const requestSchema = z.object({
66
customHeaders: z
77
.array(
88
z.object({
9-
key: z.string().trim().min(1, 'Key empty'),
10-
value: z.string().trim().min(1, 'Value empty'),
9+
// key cannot be null or empty
10+
key: z
11+
.string({
12+
required_error: 'Key empty',
13+
invalid_type_error: 'Key empty',
14+
})
15+
.trim()
16+
.min(1, 'Key empty'),
17+
// value optional in the event the substituted variable is empty
18+
value: z.string().trim().nullish().optional(),
1119
}),
1220
)
1321
.transform((params, context) => {
1422
const result = Object.create(null)
1523
const seenFields = new Set<string>()
1624
for (const { key, value } of params) {
17-
// no null fields or values are allowed
25+
// no null keys are allowed
1826
if (!key) {
1927
context.addIssue({
2028
code: z.ZodIssueCode.custom,
2129
message: 'Key empty',
2230
})
2331
return z.NEVER
2432
}
25-
if (!value) {
26-
context.addIssue({
27-
code: z.ZodIssueCode.custom,
28-
message: 'Value empty',
29-
})
30-
return z.NEVER
31-
}
3233
// catch duplicate fields
3334
if (seenFields.has(key)) {
3435
context.addIssue({
@@ -40,7 +41,7 @@ export const requestSchema = z.object({
4041
}
4142
seenFields.add(key)
4243

43-
const cleanV = value.replaceAll(/\r?\n|\r/g, ' ')
44+
const cleanV = value?.replaceAll(/\r?\n|\r/g, ' ') || ''
4445
result[key] = sanitizeMarkdown(cleanV)
4546
}
4647
return result

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,8 @@ type ActionSubstepArgument {
188188
value: JSONObject
189189
source: ActionSubstepArgumentSource
190190
hiddenIf: FieldVisibilityCondition
191-
customButtonText: String
192-
customStyle: JSONObject
191+
addRowButtonText: String
193192
hideBlankRow: Boolean
194-
showDivider: Boolean
195-
isSingleLine: Boolean
196193

197194
# Only for dropdown
198195
addNewOption: DropdownAddNewOption

packages/frontend/src/components/InputCreator/index.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type InputCreatorProps = {
1515
namePrefix?: string
1616
stepId?: string
1717
disabled?: boolean
18+
parentType?: string
1819
}
1920

2021
type RawOption = {
@@ -26,7 +27,7 @@ const optionGenerator = (options: RawOption[]): IFieldDropdownOption[] =>
2627
options?.map(({ name, value }) => ({ label: name as string, value: value }))
2728

2829
export default function InputCreator(props: InputCreatorProps): JSX.Element {
29-
const { schema, namePrefix, stepId, disabled } = props
30+
const { schema, namePrefix, stepId, disabled, parentType } = props
3031

3132
const {
3233
key: name,
@@ -114,8 +115,10 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
114115
description={description}
115116
disabled={disabled}
116117
placeholder={placeholder}
117-
isSingleLine={schema.isSingleLine}
118-
customStyle={schema.customStyle}
118+
isSingleLine={parentType === 'multicol'}
119+
customStyle={
120+
parentType === 'multicol' ? { flex: 1, minWidth: 0 } : {}
121+
}
119122
variablesEnabled
120123
/>
121124
)
@@ -135,7 +138,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
135138
description={description}
136139
clickToCopy={clickToCopy}
137140
autoComplete={schema.autoComplete}
138-
customStyle={schema.customStyle}
141+
customStyle={parentType === 'multicol' ? { flex: 0.5 } : {}}
139142
/>
140143
)
141144
}
@@ -160,9 +163,9 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
160163
description={description}
161164
subFields={schema.subFields}
162165
required={required}
163-
customButtonText={schema.customButtonText}
166+
addRowButtonText={schema.addRowButtonText}
164167
hideBlankRow={schema.hideBlankRow}
165-
showDivider={schema.showDivider}
168+
showDivider={type !== 'multirow-multicol'}
166169
type={type}
167170
// These are InputCreatorProps which MultiRow will forward.
168171
stepId={stepId}

packages/frontend/src/components/MultiCol.tsx/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default function MultiCol(props: MultiColProps) {
3333
key={`${name}.${subF.key}`}
3434
schema={subF}
3535
namePrefix={name}
36+
parentType="multicol"
3637
{...forwardedInputCreatorProps}
3738
/>
3839
)
@@ -43,7 +44,7 @@ export default function MultiCol(props: MultiColProps) {
4344
aria-label="Remove"
4445
icon={<BiTrash />}
4546
isDisabled={isEditorReadOnly}
46-
onClick={() => remove && remove(index)}
47+
onClick={() => remove?.(index)}
4748
/>
4849
)}
4950
</Flex>

packages/frontend/src/components/MultiRow/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type MultiRowProps = {
2323
flexDir?: string
2424
hideBlankRow?: boolean
2525
showDivider?: boolean
26-
customButtonText?: string
26+
addRowButtonText?: string
2727
type?: string
2828
} & Omit<InputCreatorProps, 'schema' | 'namePrefix'>
2929

@@ -34,7 +34,7 @@ function MultiRow(props: MultiRowProps): JSX.Element {
3434
label,
3535
required,
3636
description,
37-
customButtonText,
37+
addRowButtonText,
3838
hideBlankRow,
3939
showDivider,
4040
type,
@@ -100,7 +100,7 @@ function MultiRow(props: MultiRowProps): JSX.Element {
100100
{actualRows.map((row, index) => {
101101
const namePrefix = `${name}.${index}`
102102
return (
103-
<Flex key={`${name}.${index}`} flexDir="column" gap={4} mb={4}>
103+
<Flex key={row.id} flexDir="column" gap={4} mb={4}>
104104
{type === 'multirow-multicol' ? (
105105
<>
106106
<MultiCol
@@ -168,7 +168,7 @@ function MultiRow(props: MultiRowProps): JSX.Element {
168168
isDisabled={isEditorReadOnly}
169169
maxW="fit-content"
170170
>
171-
{customButtonText ?? 'And'}
171+
{addRowButtonText ?? 'And'}
172172
</Button>
173173
</Flex>
174174
)

packages/frontend/src/components/RichTextEditor/RichTextEditor.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
display: flex;
201201
flex-direction: column;
202202
height: 100%;
203+
justify-content: center;
203204

204205
.tiptap p.is-editor-empty:first-child::before {
205206
color: #adb5bd;

packages/frontend/src/components/RichTextEditor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './RichTextEditor.scss'
22

3-
import React, { useCallback, useContext, useEffect, useMemo } from 'react'
3+
import { useCallback, useContext, useEffect, useMemo } from 'react'
44
import { Controller, useFormContext } from 'react-hook-form'
55
import {
66
Box,

packages/frontend/src/graphql/queries/get-apps.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,9 @@ export const GET_APPS = gql`
188188
variables
189189
variableTypes
190190
allowArbitrary
191-
customButtonText
192-
customStyle
191+
addRowButtonText
193192
hideBlankRow
194-
showDivider
195193
showOptionValue
196-
isSingleLine
197194
value
198195
options {
199196
label
@@ -229,9 +226,7 @@ export const GET_APPS = gql`
229226
variables
230227
variableTypes
231228
allowArbitrary
232-
customStyle
233229
showOptionValue
234-
isSingleLine
235230
hiddenIf {
236231
fieldKey
237232
fieldValue

packages/types/index.d.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,6 @@ export interface IFieldDropdownOption {
330330
export interface IFieldText extends IBaseField {
331331
type: 'string'
332332
value?: string
333-
customStyle?: React.CSSProperties
334-
isSingleLine?: boolean
335333

336334
// Not applicable if field has variables.
337335
autoComplete?: AutoCompleteValue
@@ -340,8 +338,6 @@ export interface IFieldText extends IBaseField {
340338
export interface IFieldMultiline extends IBaseField {
341339
type: 'multiline'
342340
value?: string
343-
customStyle?: React.CSSProperties
344-
isSingleLine?: boolean
345341

346342
// Not applicable if field has variables.
347343
autoComplete?: AutoCompleteValue
@@ -357,19 +353,17 @@ export interface IFieldMultiSelect extends IBaseField {
357353
export interface IFieldMultiRowMultiCol extends IBaseField {
358354
type: 'multirow-multicol'
359355
value?: string
360-
customButtonText?: string
356+
addRowButtonText?: string
361357
hideBlankRow?: boolean
362-
showDivider?: boolean
363358

364359
subFields: IField[]
365360
}
366361

367362
export interface IFieldMultiRow extends IBaseField {
368363
type: 'multirow'
369364
value?: string
370-
customButtonText?: string
365+
addRowButtonText?: string
371366
hideBlankRow?: boolean
372-
showDivider?: boolean
373367

374368
subFields: IField[]
375369
}

0 commit comments

Comments
 (0)