Use enums for sorting
This commit is contained in:
parent
c6aa83d988
commit
795948f3a1
|
@ -4,11 +4,10 @@ packages/server/runtime_apps/
|
|||
.idea/
|
||||
bb-airgapped.tar.gz
|
||||
*.iml
|
||||
|
||||
packages/server/build/oldClientVersions/**/*
|
||||
packages/builder/src/components/deploy/clientVersions.json
|
||||
|
||||
packages/server/src/integrations/tests/utils/*.lock
|
||||
packages/builder/vite.config.mjs.timestamp*
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { getColumnIcon } from "../../../utils/schema"
|
||||
import MigrationModal from "../controls/MigrationModal.svelte"
|
||||
import { debounce } from "../../../utils/utils"
|
||||
import { FieldType, FormulaType } from "@budibase/types"
|
||||
import { FieldType, FormulaType, SortOrder } from "@budibase/types"
|
||||
import { TableNames } from "../../../constants"
|
||||
import GridPopover from "../overlays/GridPopover.svelte"
|
||||
|
||||
|
@ -143,7 +143,7 @@
|
|||
const sortAscending = () => {
|
||||
sort.set({
|
||||
column: column.name,
|
||||
order: "ascending",
|
||||
order: SortOrder.ASCENDING,
|
||||
})
|
||||
open = false
|
||||
}
|
||||
|
@ -151,7 +151,7 @@
|
|||
const sortDescending = () => {
|
||||
sort.set({
|
||||
column: column.name,
|
||||
order: "descending",
|
||||
order: SortOrder.DESCENDING,
|
||||
})
|
||||
open = false
|
||||
}
|
||||
|
@ -324,7 +324,7 @@
|
|||
<Icon
|
||||
hoverable
|
||||
size="S"
|
||||
name={$sort.order === "descending"
|
||||
name={$sort.order === SortOrder.DESCENDING
|
||||
? "SortOrderDown"
|
||||
: "SortOrderUp"}
|
||||
/>
|
||||
|
@ -372,7 +372,8 @@
|
|||
icon="SortOrderUp"
|
||||
on:click={sortAscending}
|
||||
disabled={!canBeSortColumn(column.schema) ||
|
||||
(column.name === $sort.column && $sort.order === "ascending")}
|
||||
(column.name === $sort.column &&
|
||||
$sort.order === SortOrder.ASCENDING)}
|
||||
>
|
||||
Sort {sortingLabels.ascending}
|
||||
</MenuItem>
|
||||
|
@ -380,7 +381,8 @@
|
|||
icon="SortOrderDown"
|
||||
on:click={sortDescending}
|
||||
disabled={!canBeSortColumn(column.schema) ||
|
||||
(column.name === $sort.column && $sort.order === "descending")}
|
||||
(column.name === $sort.column &&
|
||||
$sort.order === SortOrder.DESCENDING)}
|
||||
>
|
||||
Sort {sortingLabels.descending}
|
||||
</MenuItem>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { SortOrder } from "@budibase/types"
|
||||
import { get } from "svelte/store"
|
||||
|
||||
export const createActions = context => {
|
||||
|
@ -84,7 +85,7 @@ export const initialise = context => {
|
|||
inlineFilters.set([])
|
||||
sort.set({
|
||||
column: get(initialSortColumn),
|
||||
order: get(initialSortOrder) || "ascending",
|
||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
||||
})
|
||||
|
||||
// Update fetch when filter changes
|
||||
|
@ -110,7 +111,7 @@ export const initialise = context => {
|
|||
return
|
||||
}
|
||||
$fetch.update({
|
||||
sortOrder: $sort.order || "ascending",
|
||||
sortOrder: $sort.order || SortOrder.ASCENDING,
|
||||
sortColumn: $sort.column,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { SortOrder } from "@budibase/types"
|
||||
import { get } from "svelte/store"
|
||||
|
||||
const SuppressErrors = true
|
||||
|
@ -93,7 +94,7 @@ export const initialise = context => {
|
|||
inlineFilters.set([])
|
||||
sort.set({
|
||||
column: get(initialSortColumn),
|
||||
order: get(initialSortOrder) || "ascending",
|
||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
||||
})
|
||||
|
||||
// Update fetch when filter changes
|
||||
|
@ -119,7 +120,7 @@ export const initialise = context => {
|
|||
return
|
||||
}
|
||||
$fetch.update({
|
||||
sortOrder: $sort.order || "ascending",
|
||||
sortOrder: $sort.order || SortOrder.ASCENDING,
|
||||
sortColumn: $sort.column,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { get } from "svelte/store"
|
||||
import { dataFilters } from "@budibase/shared-core"
|
||||
import { SortOrder } from "@budibase/types"
|
||||
|
||||
function convertToSearchFilters(view) {
|
||||
// convert from SearchFilterGroup type
|
||||
|
@ -117,7 +118,7 @@ export const initialise = context => {
|
|||
inlineFilters.set([])
|
||||
sort.set({
|
||||
column: get(initialSortColumn),
|
||||
order: get(initialSortOrder) || "ascending",
|
||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
||||
})
|
||||
|
||||
// Keep sort and filter state in line with the view definition when in builder
|
||||
|
@ -133,7 +134,7 @@ export const initialise = context => {
|
|||
if (!get(initialSortColumn)) {
|
||||
sort.set({
|
||||
column: $definition.sort?.field,
|
||||
order: $definition.sort?.order || "ascending",
|
||||
order: $definition.sort?.order || SortOrder.ASCENDING,
|
||||
})
|
||||
}
|
||||
// Only override filter state if we don't have an initial filter
|
||||
|
@ -166,7 +167,7 @@ export const initialise = context => {
|
|||
...$view,
|
||||
sort: {
|
||||
field: $sort.column,
|
||||
order: $sort.order || "ascending",
|
||||
order: $sort.order || SortOrder.ASCENDING,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { derived, get } from "svelte/store"
|
||||
import { memo } from "../../../utils"
|
||||
import { SortOrder } from "@budibase/types"
|
||||
|
||||
export const createStores = context => {
|
||||
const { props } = context
|
||||
|
@ -8,7 +9,7 @@ export const createStores = context => {
|
|||
// Initialise to default props
|
||||
const sort = memo({
|
||||
column: $props.initialSortColumn,
|
||||
order: $props.initialSortOrder || "ascending",
|
||||
order: $props.initialSortOrder || SortOrder.ASCENDING,
|
||||
})
|
||||
|
||||
return {
|
||||
|
@ -24,7 +25,10 @@ export const initialise = context => {
|
|||
sort.update(state => ({ ...state, column: newSortColumn }))
|
||||
})
|
||||
initialSortOrder.subscribe(newSortOrder => {
|
||||
sort.update(state => ({ ...state, order: newSortOrder || "ascending" }))
|
||||
sort.update(state => ({
|
||||
...state,
|
||||
order: newSortOrder || SortOrder.ASCENDING,
|
||||
}))
|
||||
})
|
||||
|
||||
// Derive if the current sort column exists in the schema
|
||||
|
@ -40,7 +44,7 @@ export const initialise = context => {
|
|||
if (!exists) {
|
||||
sort.set({
|
||||
column: null,
|
||||
order: "ascending",
|
||||
order: SortOrder.ASCENDING,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { get } from "svelte/store"
|
||||
import DataFetch from "./DataFetch.js"
|
||||
import { SortOrder } from "@budibase/types"
|
||||
|
||||
export default class TableFetch extends DataFetch {
|
||||
determineFeatureFlags() {
|
||||
|
@ -23,7 +24,7 @@ export default class TableFetch extends DataFetch {
|
|||
query,
|
||||
limit,
|
||||
sort: sortColumn,
|
||||
sortOrder: sortOrder?.toLowerCase() ?? "ascending",
|
||||
sortOrder: sortOrder?.toLowerCase() ?? SortOrder.ASCENDING,
|
||||
sortType,
|
||||
paginate,
|
||||
bookmark: cursor,
|
||||
|
|
Loading…
Reference in New Issue