diff --git a/packages/web/src/modals/DropDownMenu.svelte b/packages/web/src/modals/DropDownMenu.svelte
index 336a12772..aeacb017b 100644
--- a/packages/web/src/modals/DropDownMenu.svelte
+++ b/packages/web/src/modals/DropDownMenu.svelte
@@ -86,26 +86,26 @@
submenuKey += 1;
return;
}
- if (item.switchStore && item.switchValue) {
- item.switchStore.update(x => {
- const res = {
+ if (item.switchStore) {
+ if (item.switchValue) {
+ item.switchStore.update(x => ({
...x,
[item.switchValue]: !x[item.switchValue],
- };
- if (item.switchGroupPrefix) {
- for (const key of Object.keys(res)) {
- if (key.startsWith(item.switchGroupPrefix) && key !== item.switchValue) {
- res[key] = false;
- }
- }
- }
- return res;
- });
+ }));
+ }
+
+ if (item.switchOption && item.switchOptionValue) {
+ item.switchStore.update(x => ({
+ ...x,
+ [item.switchOption]: item.switchOptionValue,
+ }));
+ }
switchIndex++;
if (!item.closeOnSwitchClick) {
return;
}
}
+
dispatchClose();
if (onCloseParent) onCloseParent();
if (item.onClick) item.onClick();
@@ -175,6 +175,16 @@
{/if}
{/key}
{/if}
+ {#if item.switchOption && item.switchStoreGetter}
+ {@const optionValue = item.switchStoreGetter()[item.switchOption]}
+ {#key switchIndex}
+ {#if optionValue === item.switchOptionValue || (item.switchOptionIsDefault && !optionValue)}
+
+ {:else}
+
+ {/if}
+ {/key}
+ {/if}
{item.text || item.label}
{#if item.keyText}
diff --git a/packages/web/src/stores.ts b/packages/web/src/stores.ts
index 6b169ef82..6b93b1147 100644
--- a/packages/web/src/stores.ts
+++ b/packages/web/src/stores.ts
@@ -200,6 +200,7 @@ export const DEFAULT_OBJECT_SEARCH_SETTINGS = {
sqlObjectText: false,
tableEngine: false,
tablesWithRows: false,
+ sortBy: undefined as string
};
export const DEFAULT_CONNECTION_SEARCH_SETTINGS = {
diff --git a/packages/web/src/widgets/SqlObjectList.svelte b/packages/web/src/widgets/SqlObjectList.svelte
index 814a5372c..1fb91bb7f 100644
--- a/packages/web/src/widgets/SqlObjectList.svelte
+++ b/packages/web/src/widgets/SqlObjectList.svelte
@@ -79,14 +79,30 @@
// $: console.log('OBJECTS', $objects);
- $databaseObjectAppObjectSearchSettings?.
+ $: sortArgs =
+ $databaseObjectAppObjectSearchSettings.sortBy == 'rowCount'
+ ? [
+ ['rowCount', 'sizeBytes', 'schemaName', 'pureName'],
+ ['desc', 'desc', 'asc', 'asc'],
+ ]
+ : $databaseObjectAppObjectSearchSettings.sortBy == 'sizeBytes'
+ ? [
+ ['sizeBytes', 'rowCount', 'schemaName', 'pureName'],
+ ['desc', 'desc', 'asc', 'asc'],
+ ]
+ : [
+ ['schemaName', 'pureName'],
+ ['asc', 'asc'],
+ ];
$: objectList = _.flatten([
...['tables', 'collections', 'views', 'matviews', 'procedures', 'functions', 'triggers', 'schedulerEvents'].map(
objectTypeField =>
- _.sortBy(
+ _.orderBy(
(($objects || {})[objectTypeField] || []).map(obj => ({ ...obj, objectTypeField })),
- ['schemaName', 'pureName']
+ sortArgs[0],
+ // @ts-ignore
+ sortArgs[1]
)
),
...appsForDb.map(app =>
@@ -173,20 +189,21 @@
res.push({ label: _t('sqlObject.sortBy', { defaultMessage: 'Sort by:' }), isBold: true, disabled: true });
res.push({
label: _t('sqlObject.name', { defaultMessage: 'Name' }),
- switchValue: 'sortByName',
- switchGroupPrefix: 'sortBy',
+ switchOption: 'sortBy',
+ switchOptionValue: 'name',
+ switchOptionIsDefault: true,
closeOnSwitchClick: true,
});
res.push({
label: _t('sqlObject.rowCount', { defaultMessage: 'Row count' }),
- switchValue: 'sortByRowCount',
- switchGroupPrefix: 'sortBy',
+ switchOption: 'sortBy',
+ switchOptionValue: 'rowCount',
closeOnSwitchClick: true,
});
res.push({
label: _t('sqlObject.sizeBytes', { defaultMessage: 'Size bytes' }),
- switchValue: 'sortBySizeBytes',
- switchGroupPrefix: 'sortBy',
+ switchOption: 'sortBy',
+ switchOptionValue: 'sizeBytes',
closeOnSwitchClick: true,
});