Skip to content

Commit 61311de

Browse files
committed
Cleanup
1 parent 525e8d4 commit 61311de

File tree

6 files changed

+83
-74
lines changed

6 files changed

+83
-74
lines changed

assets/studio/js/src/modules/data-importer/components/tabs/execution-tab/manual-execution-button/manual-execution-button.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export const ManualExecutionButton = (props: ManualExecutionButtonProps): React.
2727
const push = loaderType === 'push'
2828
const disabled = push || isDirty || isStarting
2929

30-
const tooltipTitle = isDirty
31-
? t('data-importer.execution.start-import.tooltip-dirty')
32-
: push
33-
? t('data-importer.execution.start-import.tooltip-push')
34-
: undefined
30+
const tooltipTitle = ((): string | undefined => {
31+
if (isDirty) return t('data-importer.execution.start-import.tooltip-dirty')
32+
if (push) return t('data-importer.execution.start-import.tooltip-push')
33+
return undefined
34+
})()
3535

3636
return (
3737
<Tooltip title={ tooltipTitle }>

assets/studio/js/src/modules/data-importer/components/tabs/steps/advanced-mapping-modal/preview-panel/preview-panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export const PreviewPanel = (props: PreviewPanelProps): React.JSX.Element => {
234234
isHighlighted && styles.tableRowHighlighted,
235235
!isLastRow && styles.tableRowBorder
236236
) }
237-
key={ i }
237+
key={ row.dataIndex }
238238
>
239239
<Flex
240240
align="center"
@@ -287,7 +287,7 @@ export const PreviewPanel = (props: PreviewPanelProps): React.JSX.Element => {
287287
{ !(isResultLoading || isResultFetching) && previews.map((line, i) => (
288288
<div
289289
className={ styles.previewLine }
290-
key={ i }
290+
key={ `preview-${i}` }
291291
>
292292
{ line }
293293
</div>

assets/studio/js/src/modules/data-importer/components/tabs/steps/interpreters/csv-interpreter-settings.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import { useTranslation } from '@pimcore/studio-ui-bundle/app'
1515
export const CsvInterpreterSettings = (): React.JSX.Element => {
1616
const { t } = useTranslation()
1717

18-
const singleCharRule = (fieldLabel: string): { validator: (_: unknown, value: string | undefined) => Promise<void> } => ({
19-
async validator (_: unknown, value: string | undefined): Promise<void> {
20-
const normalized = value ?? ''
21-
if (normalized.length <= 1) {
18+
const singleCharRule = (fieldLabel: string): { validator: (_: unknown, value?: string) => Promise<void> } => ({
19+
async validator (_: unknown, value: string = ''): Promise<void> {
20+
if (value.length <= 1) {
2221
await Promise.resolve(); return
2322
}
2423

assets/studio/js/src/modules/data-importer/components/tabs/steps/loaders/upload-loader-settings.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export interface UploadLoaderSettingsProps {
1818
configName: string
1919
}
2020

21+
function resolveStatusType (isError: boolean, hasUploadedFile: boolean): 'success' | 'warning' | 'error' {
22+
if (isError) return 'error'
23+
if (hasUploadedFile) return 'success'
24+
return 'warning'
25+
}
26+
2127
export const UploadLoaderSettings = ({ configName }: UploadLoaderSettingsProps): React.JSX.Element => {
2228
const { t } = useTranslation()
2329
const form = Form.useFormInstance()
@@ -50,9 +56,7 @@ export const UploadLoaderSettings = ({ configName }: UploadLoaderSettingsProps):
5056
const hasUploadedFile = fileStatus?.exists === true
5157
const isCheckingStatus = isLoading || (isFetching && fileStatus === undefined)
5258

53-
const statusType: 'success' | 'warning' | 'error' = isError
54-
? 'error'
55-
: (hasUploadedFile ? 'success' : 'warning')
59+
const statusType = resolveStatusType(isError, hasUploadedFile)
5660
const statusMessage = fileStatus?.message ?? (hasUploadedFile
5761
? t('data-importer.loader.upload.file-uploaded')
5862
: t('data-importer.loader.upload.no-file'))

assets/studio/js/src/modules/data-importer/components/tabs/steps/mapping-step/mapping-item/mapping-item-content.tsx

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -135,68 +135,68 @@ export const MappingItemContent = ({
135135
{ t('data-importer.mapping.item.destination') }
136136
</div>
137137

138-
{ isAdvanced
139-
? (
140-
<>
141-
<Flex
142-
className={ styles.destinationTextBlock }
143-
vertical
144-
>
145-
<span>{ selectedAttr?.title ?? selectedFieldName ?? '' }</span>
146-
</Flex>
138+
{ isAdvanced && (
139+
<>
140+
<Flex
141+
className={ styles.destinationTextBlock }
142+
vertical
143+
>
144+
<span>{ selectedAttr?.title ?? selectedFieldName ?? '' }</span>
145+
</Flex>
146+
<Form.Item
147+
hidden
148+
name={ [fieldIndex, 'dataTarget', 'settings', 'fieldName'] }
149+
style={ { display: 'none' } }
150+
>
151+
<Input />
152+
</Form.Item>
153+
</>
154+
) }
155+
156+
{ !isAdvanced && isInProgressState && (
157+
<>
158+
<div className={ styles.requiresAdvancedHint }>
159+
{ t('data-importer.mapping.item.requires-advanced-setup') }
160+
</div>
161+
<Form.Item
162+
hidden
163+
name={ [fieldIndex, 'dataTarget', 'settings', 'fieldName'] }
164+
style={ { display: 'none' } }
165+
>
166+
<Input />
167+
</Form.Item>
168+
</>
169+
) }
170+
171+
{ !isAdvanced && !isInProgressState && (
172+
<>
173+
<Form.Item
174+
name={ [fieldIndex, 'dataTarget', 'settings', 'fieldName'] }
175+
style={ { marginBottom: 0 } }
176+
>
177+
<Select
178+
filterOption={ filterByLabel }
179+
options={ attributeOptions }
180+
placeholder={ t('data-importer.mapping.item.destination-placeholder') }
181+
showSearch
182+
/>
183+
</Form.Item>
184+
185+
{ isLocalized && (
147186
<Form.Item
148-
hidden
149-
name={ [fieldIndex, 'dataTarget', 'settings', 'fieldName'] }
150-
style={ { display: 'none' } }
187+
name={ [fieldIndex, 'dataTarget', 'settings', 'language'] }
188+
style={ { marginBottom: 0 } }
151189
>
152-
<Input />
190+
<Select
191+
filterOption={ filterByLabel }
192+
options={ languageOptions }
193+
placeholder={ t('data-importer.mapping.item.data-target.language-placeholder') }
194+
showSearch
195+
/>
153196
</Form.Item>
154-
</>
155-
)
156-
: isInProgressState
157-
? (
158-
<>
159-
<div className={ styles.requiresAdvancedHint }>
160-
{ t('data-importer.mapping.item.requires-advanced-setup') }
161-
</div>
162-
<Form.Item
163-
hidden
164-
name={ [fieldIndex, 'dataTarget', 'settings', 'fieldName'] }
165-
style={ { display: 'none' } }
166-
>
167-
<Input />
168-
</Form.Item>
169-
</>
170-
)
171-
: (
172-
<>
173-
<Form.Item
174-
name={ [fieldIndex, 'dataTarget', 'settings', 'fieldName'] }
175-
style={ { marginBottom: 0 } }
176-
>
177-
<Select
178-
filterOption={ filterByLabel }
179-
options={ attributeOptions }
180-
placeholder={ t('data-importer.mapping.item.destination-placeholder') }
181-
showSearch
182-
/>
183-
</Form.Item>
184-
185-
{ isLocalized && (
186-
<Form.Item
187-
name={ [fieldIndex, 'dataTarget', 'settings', 'language'] }
188-
style={ { marginBottom: 0 } }
189-
>
190-
<Select
191-
filterOption={ filterByLabel }
192-
options={ languageOptions }
193-
placeholder={ t('data-importer.mapping.item.data-target.language-placeholder') }
194-
showSearch
195-
/>
196-
</Form.Item>
197-
) }
198-
</>
199-
) }
197+
) }
198+
</>
199+
) }
200200
</Flex>
201201
</Flex>
202202
</div>

assets/studio/js/src/modules/data-importer/utils/normalize-data-row.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export interface DataRow {
1414
value: string
1515
}
1616

17+
function stringifyData (data: unknown): string {
18+
if (typeof data === 'string') return data
19+
if (data !== undefined) return JSON.stringify(data)
20+
return ''
21+
}
22+
1723
/**
1824
* Normalizes a raw data-preview row returned by the backend into a flat
1925
* `DataRow` shape suitable for display in preview panels and the mapping step.
@@ -25,6 +31,6 @@ export function normalizeDataRow (raw: Record<string, any>): DataRow {
2531
return {
2632
dataIndex: String(raw.dataIndex ?? ''),
2733
label: String(raw.label ?? raw.dataIndex ?? ''),
28-
value: typeof raw.data === 'string' ? raw.data : (raw.data !== undefined ? JSON.stringify(raw.data) : '')
34+
value: stringifyData(raw.data)
2935
}
3036
}

0 commit comments

Comments
 (0)