better column chooser

This commit is contained in:
SPRINX0\prochazka
2024-09-26 12:14:10 +02:00
parent 3603501ae2
commit 4dd3f15ba3
2 changed files with 43 additions and 7 deletions

View File

@@ -76,6 +76,7 @@
const { values, setFieldValue } = getFormContext(); const { values, setFieldValue } = getFormContext();
$: targetDbinfo = useDatabaseInfo({ conid: $values.targetConnectionId, database: $values.targetDatabaseName }); $: targetDbinfo = useDatabaseInfo({ conid: $values.targetConnectionId, database: $values.targetDatabaseName });
$: sourceDbinfo = useDatabaseInfo({ conid: $values.sourceConnectionId, database: $values.sourceDatabaseName });
$: sourceConnectionInfo = useConnectionInfo({ conid: $values.sourceConnectionId }); $: sourceConnectionInfo = useConnectionInfo({ conid: $values.sourceConnectionId });
$: sourceEngine = $sourceConnectionInfo?.engine; $: sourceEngine = $sourceConnectionInfo?.engine;
$: sourceList = $values.sourceList; $: sourceList = $values.sourceList;
@@ -219,7 +220,9 @@
<Link <Link
onClick={() => { onClick={() => {
showModal(ColumnMapModal, { showModal(ColumnMapModal, {
value: $values[`columns_${row}`], initialValue: $values[`columns_${row}`],
sourceTableInfo: $sourceDbinfo?.tables?.find(x => x.pureName == row),
targetTableInfo: $targetDbinfo?.tables?.find(x => x.pureName == values[`targetName_${row}`] || row),
onConfirm: value => setFieldValue(`columns_${row}`, value), onConfirm: value => setFieldValue(`columns_${row}`, value),
}); });
}} }}

View File

@@ -12,16 +12,48 @@
export let header = 'Configure columns'; export let header = 'Configure columns';
export let onConfirm; export let onConfirm;
export let value = [];
export let sourceTableInfo;
export let targetTableInfo;
export let initialValue;
function getResetValue() {
if (sourceTableInfo && !targetTableInfo) {
return sourceTableInfo.columns.map(x => ({
src: x.columnName,
dst: x.columnName,
skip: false,
}));
}
return [];
}
const resetValue = getResetValue();
function equalValues(v1, v2) {
if (!v1 || !v2) return false;
if (v1.length != v2.length) return false;
for (let i = 0; i < v1.length; i++) {
if (v1[i].src != v2[i].src || v1[i].dst != v2[i].dst || !!v1[i].skip != !!v2[i].skip) return false;
}
return true;
}
$: differentFromReset = !equalValues(value, resetValue);
let value = initialValue?.length > 0 ? initialValue : resetValue;
</script> </script>
<FormProvider> <FormProvider>
<ModalBase {...$$restProps}> <ModalBase {...$$restProps}>
<div slot="header">{header}</div> <div slot="header">{header}</div>
{#if resetValue.length == 0}
<div class="m-3"> <div class="m-3">
When no columns are defined in this mapping, source row is copied to target without any modifications When no columns are defined in this mapping, source row is copied to target without any modifications
</div> </div>
{/if}
<TableControl <TableControl
columns={[ columns={[
@@ -68,7 +100,7 @@
value="OK" value="OK"
on:click={() => { on:click={() => {
closeCurrentModal(); closeCurrentModal();
onConfirm(!value || value.length == 0 ? null : value); onConfirm(!value || value.length == 0 || !differentFromReset ? null : value);
}} }}
/> />
<FormStyledButton type="button" value="Close" on:click={closeCurrentModal} /> <FormStyledButton type="button" value="Close" on:click={closeCurrentModal} />
@@ -82,8 +114,9 @@
<FormStyledButton <FormStyledButton
type="button" type="button"
value="Reset" value="Reset"
disabled={!differentFromReset}
on:click={() => { on:click={() => {
value = []; value = resetValue;
}} }}
/> />
</svelte:fragment> </svelte:fragment>