mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 16:36:00 +00:00
selectfield using svelte select
This commit is contained in:
@@ -3,8 +3,15 @@
|
|||||||
import SelectField from './SelectField.svelte';
|
import SelectField from './SelectField.svelte';
|
||||||
|
|
||||||
export let name;
|
export let name;
|
||||||
|
export let isClearable = false;
|
||||||
|
|
||||||
const { values, setFieldValue } = getFormContext();
|
const { values, setFieldValue } = getFormContext();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SelectField {...$$restProps} value={$values[name]} on:change={e => setFieldValue(name, e.target['value'])} />
|
<SelectField
|
||||||
|
{...$$restProps}
|
||||||
|
value={$values[name]}
|
||||||
|
on:change={e => setFieldValue(name, e.detail)}
|
||||||
|
{isClearable}
|
||||||
|
|
||||||
|
/>
|
||||||
|
|||||||
@@ -1,14 +1,57 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _, { map } from 'lodash';
|
||||||
|
import SvelteSelect from 'svelte-select';
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
export let options = [];
|
export let options = [];
|
||||||
export let value;
|
export let value;
|
||||||
|
export let isNative = false;
|
||||||
|
export let isMulti = false;
|
||||||
|
|
||||||
|
let listOpen = false;
|
||||||
|
let isFocused = false;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (!listOpen && isFocused && isMulti) listOpen = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<select {...$$restProps} on:change>
|
{#if isNative}
|
||||||
|
<select
|
||||||
|
{...$$restProps}
|
||||||
|
on:change={e => {
|
||||||
|
dispatch('change', e.target['value']);
|
||||||
|
}}
|
||||||
|
>
|
||||||
{#each _.compact(options) as x (x.value)}
|
{#each _.compact(options) as x (x.value)}
|
||||||
<option value={x.value} selected={value == x.value}>
|
<option value={x.value} selected={value == x.value}>
|
||||||
{x.label}
|
{x.label}
|
||||||
</option>
|
</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
|
{:else}
|
||||||
|
<SvelteSelect
|
||||||
|
{...$$restProps}
|
||||||
|
items={options}
|
||||||
|
selectedValue={isMulti
|
||||||
|
? value?.map(item => options.find(x => x.value == item))
|
||||||
|
: options.find(x => x.value == value)}
|
||||||
|
on:select={e => {
|
||||||
|
if (isMulti) {
|
||||||
|
dispatch(
|
||||||
|
'change',
|
||||||
|
e.detail?.map(x => x.value)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
dispatch('change', e.detail.value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
showIndicator={!isMulti}
|
||||||
|
isClearable={isMulti}
|
||||||
|
{isMulti}
|
||||||
|
bind:listOpen
|
||||||
|
bind:isFocused
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -10,8 +10,4 @@ import FormSelectField from '../forms/FormSelectField.svelte';
|
|||||||
}));
|
}));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if connectionOptions.length == 0}
|
|
||||||
<div>Not available</div>
|
|
||||||
{:else}
|
|
||||||
<FormSelectField {...$$restProps} options={connectionOptions} />
|
<FormSelectField {...$$restProps} options={connectionOptions} />
|
||||||
{/if}
|
|
||||||
|
|||||||
@@ -14,8 +14,4 @@
|
|||||||
}));
|
}));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if databaseOptions.length == 0}
|
|
||||||
<div>Not available</div>
|
|
||||||
{:else}
|
|
||||||
<FormSelectField {...$$restProps} options={databaseOptions} />
|
<FormSelectField {...$$restProps} options={databaseOptions} />
|
||||||
{/if}
|
|
||||||
|
|||||||
@@ -15,9 +15,6 @@
|
|||||||
}));
|
}));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if schemaOptions.length > 0}
|
||||||
{#if schemaOptions.length == 0}
|
|
||||||
<div>Not available</div>
|
|
||||||
<FormSelectField {...$$restProps} options={schemaOptions} />
|
<FormSelectField {...$$restProps} options={schemaOptions} />
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
|
||||||
@@ -2,14 +2,13 @@
|
|||||||
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
||||||
import FormSelectField from '../forms/FormSelectField.svelte';
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
import { useDatabaseInfo, useDatabaseList } from '../utility/metadataLoaders';
|
import { useDatabaseInfo, useDatabaseList } from '../utility/metadataLoaders';
|
||||||
import SvelteSelect from 'svelte-select';
|
|
||||||
|
|
||||||
export let conidName;
|
export let conidName;
|
||||||
export let databaseName;
|
export let databaseName;
|
||||||
export let schemaName;
|
export let schemaName;
|
||||||
|
|
||||||
const { values } = getFormContext();
|
const { values } = getFormContext();
|
||||||
$: dbinfo = useDatabaseInfo({ conid: $values[conidName], database: values[databaseName] });
|
$: dbinfo = useDatabaseInfo({ conid: $values[conidName], database: $values[databaseName] });
|
||||||
|
|
||||||
$: tablesOptions = [...(($dbinfo && $dbinfo.tables) || []), ...(($dbinfo && $dbinfo.views) || [])]
|
$: tablesOptions = [...(($dbinfo && $dbinfo.tables) || []), ...(($dbinfo && $dbinfo.views) || [])]
|
||||||
.filter(x => !$values[schemaName] || x.schemaName == $values[schemaName])
|
.filter(x => !$values[schemaName] || x.schemaName == $values[schemaName])
|
||||||
@@ -19,8 +18,4 @@
|
|||||||
}));
|
}));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if tablesOptions.length == 0}
|
<FormSelectField {...$$restProps} options={tablesOptions} isMulti />
|
||||||
<div>Not available</div>
|
|
||||||
{:else}
|
|
||||||
<SvelteSelect {...$$restProps} items={tablesOptions} isMulti listOpen />
|
|
||||||
{/if}
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
schemaName={schemaNameField}
|
schemaName={schemaNameField}
|
||||||
databaseName={databaseNameField}
|
databaseName={databaseNameField}
|
||||||
name={tablesField}
|
name={tablesField}
|
||||||
|
label="Tables / views"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import moment from 'moment';
|
||||||
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
||||||
import LargeButton from '../elements/LargeButton.svelte';
|
import LargeButton from '../elements/LargeButton.svelte';
|
||||||
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
||||||
@@ -8,8 +9,10 @@
|
|||||||
import LargeFormButton from '../forms/LargeFormButton.svelte';
|
import LargeFormButton from '../forms/LargeFormButton.svelte';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import ImportExportConfigurator from '../impexp/ImportExportConfigurator.svelte';
|
import ImportExportConfigurator from '../impexp/ImportExportConfigurator.svelte';
|
||||||
|
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||||
import RunnerOutputFiles from '../query/RunnerOutputFiles';
|
import RunnerOutputFiles from '../query/RunnerOutputFiles';
|
||||||
import SocketMessageView from '../query/SocketMessageView.svelte';
|
import SocketMessageView from '../query/SocketMessageView.svelte';
|
||||||
|
import { currentArchive, extensions } from '../stores';
|
||||||
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
|
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
|
||||||
import WidgetColumnBarItem from '../widgets/WidgetColumnBarItem.svelte';
|
import WidgetColumnBarItem from '../widgets/WidgetColumnBarItem.svelte';
|
||||||
import ModalBase from './ModalBase.svelte';
|
import ModalBase from './ModalBase.svelte';
|
||||||
@@ -25,6 +28,8 @@
|
|||||||
export let openedFile = undefined;
|
export let openedFile = undefined;
|
||||||
export let importToArchive = false;
|
export let importToArchive = false;
|
||||||
|
|
||||||
|
$: targetArchiveFolder = importToArchive ? `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}` : $currentArchive;
|
||||||
|
|
||||||
const handleGenerateScript = async () => {
|
const handleGenerateScript = async () => {
|
||||||
// const code = await createImpExpScript(extensions, values);
|
// const code = await createImpExpScript(extensions, values);
|
||||||
// openNewTab(
|
// openNewTab(
|
||||||
@@ -61,7 +66,15 @@
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormProvider>
|
<FormProvider
|
||||||
|
initialValues={{
|
||||||
|
sourceStorageType: 'database',
|
||||||
|
targetStorageType: importToArchive ? 'archive' : getDefaultFileFormat($extensions).storageType,
|
||||||
|
sourceArchiveFolder: $currentArchive,
|
||||||
|
targetArchiveFolder,
|
||||||
|
...initialValues,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<ModalBase {...$$restProps} fullScreen skipBody skipFooter>
|
<ModalBase {...$$restProps} fullScreen skipBody skipFooter>
|
||||||
<svelte:fragment slot="header">
|
<svelte:fragment slot="header">
|
||||||
Import/Export
|
Import/Export
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const leftPanelWidth = writable(300);
|
|||||||
export const currentDropDownMenu = writable(null);
|
export const currentDropDownMenu = writable(null);
|
||||||
export const openedModals = writable([]);
|
export const openedModals = writable([]);
|
||||||
export const nullStore = readable(null, () => {});
|
export const nullStore = readable(null, () => {});
|
||||||
|
export const currentArchive = writable('default');
|
||||||
|
|
||||||
subscribeCssVariable(selectedWidget, x => (x ? 1 : 0), '--dim-visible-left-panel');
|
subscribeCssVariable(selectedWidget, x => (x ? 1 : 0), '--dim-visible-left-panel');
|
||||||
subscribeCssVariable(visibleToolbar, x => (x ? 1 : 0), '--dim-visible-toolbar');
|
subscribeCssVariable(visibleToolbar, x => (x ? 1 : 0), '--dim-visible-toolbar');
|
||||||
|
|||||||
Reference in New Issue
Block a user