mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 01:03:58 +00:00
better column chooser
This commit is contained in:
@@ -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),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
<div class="m-3">
|
{#if resetValue.length == 0}
|
||||||
When no columns are defined in this mapping, source row is copied to target without any modifications
|
<div class="m-3">
|
||||||
</div>
|
When no columns are defined in this mapping, source row is copied to target without any modifications
|
||||||
|
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user