Skip to content

Commit

Permalink
only use undefined to move attribute to front
Browse files Browse the repository at this point in the history
  • Loading branch information
scytacki committed Jan 9, 2025
1 parent 622e800 commit 1fd429c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export const AttributeHeaderDivider = ({ before = false, columnKey, cellElt, get
if (!targetCollection || !dataSet || (dataSet !== dataset) || !dragAttrId) return

const sourceCollection = dataSet.getCollectionForAttribute(dragAttrId)
// If the columnKey is the special kIndexColumnKey then we use undefined for
// afterAttrId. This means the attribute will be moved to the beginning
const maybeColumnKey = columnKey === kIndexColumnKey ? undefined : columnKey
moveAttribute({
afterAttrId: before ? kIndexColumnKey : columnKey,
afterAttrId: before ? undefined : maybeColumnKey,
attrId: dragAttrId,
dataset,
includeNotifications: true,
Expand Down
2 changes: 1 addition & 1 deletion v3/src/components/common/edit-formula-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Box, Button, Flex, FormControl, FormLabel, Input, ModalBody, ModalFooter, Tooltip
Box, Button, Flex, FormControl, FormLabel, ModalBody, ModalFooter, Tooltip
} from "@chakra-ui/react"
import React, { useCallback, useEffect, useRef, useState } from "react"
import { observer } from "mobx-react-lite"
Expand Down
3 changes: 1 addition & 2 deletions v3/src/models/data/data-set-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isAlive } from "mobx-state-tree"
import { kIndexColumnKey } from "../../components/case-tile-common/case-tile-types"
import { logMessageWithReplacement } from "../../lib/log-message"
import { AttributeFormulaAdapter } from "../formula/attribute-formula-adapter"
import { FilterFormulaAdapter } from "../formula/filter-formula-adapter"
Expand Down Expand Up @@ -74,7 +73,7 @@ export function moveAttribute({
}: IMoveAttributeParameters) {
const firstAttr: IAttribute | undefined = getCollectionAttrs(targetCollection, dataset)[0]
const options: IMoveAttributeOptions =
!afterAttrId || afterAttrId === kIndexColumnKey ? { before: firstAttr?.id } : { after: afterAttrId }
afterAttrId ? { after: afterAttrId }: { before: firstAttr?.id }

// bail if we're moving the attribute before/after itself
if (attrId === options.after || attrId === options.before) return
Expand Down

0 comments on commit 1fd429c

Please sign in to comment.