Add new shared core util for determining whether columns can be sort columns or not
This commit is contained in:
parent
bdc2bcd97d
commit
fb69c3a0da
|
@ -3,13 +3,10 @@
|
||||||
import { goto, params } from "@roxi/routify"
|
import { goto, params } from "@roxi/routify"
|
||||||
import { Table, Heading, Layout } from "@budibase/bbui"
|
import { Table, Heading, Layout } from "@budibase/bbui"
|
||||||
import Spinner from "components/common/Spinner.svelte"
|
import Spinner from "components/common/Spinner.svelte"
|
||||||
import {
|
import { TableNames, UNEDITABLE_USER_FIELDS } from "constants"
|
||||||
TableNames,
|
|
||||||
UNEDITABLE_USER_FIELDS,
|
|
||||||
UNSORTABLE_TYPES,
|
|
||||||
} from "constants"
|
|
||||||
import RoleCell from "./cells/RoleCell.svelte"
|
import RoleCell from "./cells/RoleCell.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
|
import { canBeSortColumn } from "@budibase/shared-core"
|
||||||
|
|
||||||
export let schema = {}
|
export let schema = {}
|
||||||
export let data = []
|
export let data = []
|
||||||
|
@ -32,12 +29,10 @@
|
||||||
$: isUsersTable = tableId === TableNames.USERS
|
$: isUsersTable = tableId === TableNames.USERS
|
||||||
$: data && resetSelectedRows()
|
$: data && resetSelectedRows()
|
||||||
$: {
|
$: {
|
||||||
UNSORTABLE_TYPES.forEach(type => {
|
Object.values(schema || {}).forEach(col => {
|
||||||
Object.values(schema || {}).forEach(col => {
|
if (!canBeSortColumn(col.type)) {
|
||||||
if (col.type === type) {
|
col.sortable = false
|
||||||
col.sortable = false
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
$: {
|
$: {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import { currentAsset } from "builderStore"
|
import { currentAsset } from "builderStore"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { UNSORTABLE_TYPES } from "constants"
|
import { canBeSortColumn } from "@budibase/shared-core"
|
||||||
|
|
||||||
export let componentInstance = {}
|
export let componentInstance = {}
|
||||||
export let value = ""
|
export let value = ""
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
const getSortableFields = schema => {
|
const getSortableFields = schema => {
|
||||||
return Object.entries(schema || {})
|
return Object.entries(schema || {})
|
||||||
.filter(entry => !UNSORTABLE_TYPES.includes(entry[1].type))
|
.filter(entry => canBeSortColumn(entry[1].type))
|
||||||
.map(entry => entry[0])
|
.map(entry => entry[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,6 @@ export const UNEDITABLE_USER_FIELDS = [
|
||||||
"lastName",
|
"lastName",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const UNSORTABLE_TYPES = ["formula", "attachment", "array", "link"]
|
|
||||||
|
|
||||||
export const LAYOUT_NAMES = {
|
export const LAYOUT_NAMES = {
|
||||||
MASTER: {
|
MASTER: {
|
||||||
PRIVATE: "layout_private_master",
|
PRIVATE: "layout_private_master",
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { Table } from "@budibase/bbui"
|
import { Table } from "@budibase/bbui"
|
||||||
import SlotRenderer from "./SlotRenderer.svelte"
|
import SlotRenderer from "./SlotRenderer.svelte"
|
||||||
import { UnsortableTypes } from "../../../constants"
|
|
||||||
import { onDestroy } from "svelte"
|
import { onDestroy } from "svelte"
|
||||||
|
import { canBeSortColumn } from "@budibase/shared-core"
|
||||||
|
|
||||||
export let dataProvider
|
export let dataProvider
|
||||||
export let columns
|
export let columns
|
||||||
|
@ -102,7 +102,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newSchema[columnName] = schema[columnName]
|
newSchema[columnName] = schema[columnName]
|
||||||
if (UnsortableTypes.includes(schema[columnName].type)) {
|
if (!canBeSortColumn(schema[columnName].type)) {
|
||||||
newSchema[columnName].sortable = false
|
newSchema[columnName].sortable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
import { FieldType as FieldTypes } from "@budibase/types"
|
|
||||||
export { FieldType as FieldTypes } from "@budibase/types"
|
export { FieldType as FieldTypes } from "@budibase/types"
|
||||||
|
|
||||||
export const UnsortableTypes = [
|
|
||||||
FieldTypes.FORMULA,
|
|
||||||
FieldTypes.ATTACHMENT,
|
|
||||||
FieldTypes.ARRAY,
|
|
||||||
FieldTypes.LINK,
|
|
||||||
]
|
|
||||||
|
|
||||||
export const ActionTypes = {
|
export const ActionTypes = {
|
||||||
ValidateForm: "ValidateForm",
|
ValidateForm: "ValidateForm",
|
||||||
UpdateFieldValue: "UpdateFieldValue",
|
UpdateFieldValue: "UpdateFieldValue",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext, onMount, tick } from "svelte"
|
import { getContext, onMount, tick } from "svelte"
|
||||||
import { canBeDisplayColumn } from "@budibase/shared-core"
|
import { canBeDisplayColumn, canBeSortColumn } from "@budibase/shared-core"
|
||||||
import { Icon, Popover, Menu, MenuItem, clickOutside } from "@budibase/bbui"
|
import { Icon, Popover, Menu, MenuItem, clickOutside } from "@budibase/bbui"
|
||||||
import GridCell from "./GridCell.svelte"
|
import GridCell from "./GridCell.svelte"
|
||||||
import { getColumnIcon } from "../lib/utils"
|
import { getColumnIcon } from "../lib/utils"
|
||||||
|
@ -232,14 +232,16 @@
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon="SortOrderUp"
|
icon="SortOrderUp"
|
||||||
on:click={sortAscending}
|
on:click={sortAscending}
|
||||||
disabled={column.name === $sort.column && $sort.order === "ascending"}
|
disabled={!canBeSortColumn(column.schema.type) ||
|
||||||
|
(column.name === $sort.column && $sort.order === "ascending")}
|
||||||
>
|
>
|
||||||
Sort {ascendingLabel}
|
Sort {ascendingLabel}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon="SortOrderDown"
|
icon="SortOrderDown"
|
||||||
on:click={sortDescending}
|
on:click={sortDescending}
|
||||||
disabled={column.name === $sort.column && $sort.order === "descending"}
|
disabled={!canBeSortColumn(column.schema.type) ||
|
||||||
|
(column.name === $sort.column && $sort.order === "descending")}
|
||||||
>
|
>
|
||||||
Sort {descendingLabel}
|
Sort {descendingLabel}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
|
@ -20,6 +20,30 @@ const allowDisplayColumnByType: Record<FieldType, boolean> = {
|
||||||
[FieldType.BB_REFERENCE]: false,
|
[FieldType.BB_REFERENCE]: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allowSortColumnByType: Record<FieldType, boolean> = {
|
||||||
|
[FieldType.STRING]: true,
|
||||||
|
[FieldType.LONGFORM]: true,
|
||||||
|
[FieldType.OPTIONS]: true,
|
||||||
|
[FieldType.NUMBER]: true,
|
||||||
|
[FieldType.DATETIME]: true,
|
||||||
|
[FieldType.AUTO]: true,
|
||||||
|
[FieldType.INTERNAL]: true,
|
||||||
|
[FieldType.BARCODEQR]: true,
|
||||||
|
[FieldType.BIGINT]: true,
|
||||||
|
[FieldType.BOOLEAN]: true,
|
||||||
|
[FieldType.JSON]: true,
|
||||||
|
|
||||||
|
[FieldType.FORMULA]: false,
|
||||||
|
[FieldType.ATTACHMENT]: false,
|
||||||
|
[FieldType.ARRAY]: false,
|
||||||
|
[FieldType.LINK]: false,
|
||||||
|
[FieldType.BB_REFERENCE]: false,
|
||||||
|
}
|
||||||
|
|
||||||
export function canBeDisplayColumn(type: FieldType): boolean {
|
export function canBeDisplayColumn(type: FieldType): boolean {
|
||||||
return !!allowDisplayColumnByType[type]
|
return !!allowDisplayColumnByType[type]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canBeSortColumn(type: FieldType): boolean {
|
||||||
|
return !!allowSortColumnByType[type]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue