Skip to content

Commit

Permalink
Change incorrect model to apply changes to for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
eireland committed Jul 31, 2024
1 parent c026ea8 commit 5acfabb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
6 changes: 2 additions & 4 deletions v3/src/components/calculator/calculator.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Button, Flex, Text } from "@chakra-ui/react"
import React, { useState } from "react"
import { useDocumentContent } from "../../hooks/use-document-content"
import { ITileBaseProps } from "../tiles/tile-base-props"
import { isCalculatorModel } from "./calculator-model"
import { evaluate } from "mathjs"
Expand All @@ -10,15 +9,14 @@ import "./calculator.scss"
export const CalculatorComponent = ({ tile }: ITileBaseProps) => {
const [calcValue, setCalcValue] = useState("")
const [justEvaled, setJustEvaled] = useState(false)
const documentContent = useDocumentContent()

const calculatorModel = tile?.content
if (!isCalculatorModel(calculatorModel)) return null

const clearValue = () => {
setCalcValue("")
setJustEvaled(false)
documentContent?.applyModelChange(() => {}, {
calculatorModel?.applyModelChange(() => {}, {
log: "Calculator value cleared"
})
}
Expand All @@ -44,7 +42,7 @@ export const CalculatorComponent = ({ tile }: ITileBaseProps) => {
try {
const solution = evaluate(calcValue)
!isNaN(solution) && setCalcValue(solution)
documentContent?.applyModelChange(() => {}, {
calculatorModel?.applyModelChange(() => {}, {
log: `Calculation done: ${calcValue} = ${solution}`
})
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { observer } from "mobx-react-lite"
import { MenuItem, MenuList, useDisclosure, useToast } from "@chakra-ui/react"
import { useCaseMetadata } from "../../../hooks/use-case-metadata"
import { useDataSetContext } from "../../../hooks/use-data-set-context"
import { useDocumentContent } from "../../../hooks/use-document-content"
import {
deleteCollectionNotification, hideAttributeNotification, removeAttributesNotification
} from "../../../models/data/data-set-notifications"
Expand All @@ -27,7 +26,6 @@ const AttributeMenuListComp = forwardRef<HTMLDivElement, IProps>(
const toast = useToast()
const data = useDataSetContext()
const caseMetadata = useCaseMetadata()
const documentContent = useDocumentContent()
// each use of useDisclosure() maintains its own state and callbacks so they can be used for independent dialogs
const attributePropsModal = useDisclosure()
const formulaModal = useDisclosure()
Expand All @@ -48,13 +46,13 @@ const AttributeMenuListComp = forwardRef<HTMLDivElement, IProps>(
//TODO: move to respective logs when handlers are implemented
switch (menuItem) {
case "Fit width":
documentContent?.applyModelChange(() => {}, {
data?.applyModelChange(() => {}, {
log: {message:`Fit column width:`, event_value: {collection: data?.name, attribute: columnName}}
})
break
case "Sort Ascending":
case "Sort Descending":
documentContent?.applyModelChange(() => {}, {
data?.applyModelChange(() => {}, {
log: {message:`Sort cases by attribute:`, event_value: {attributeId: attribute?.id, attribute: columnName}}
})
break
Expand Down
4 changes: 1 addition & 3 deletions v3/src/components/case-table/case-table-inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import { ICaseTableModel, isCaseTableModel } from "./case-table-model"
import { useDataSet } from "../../hooks/use-data-set"
import { DataSetContext } from "../../hooks/use-data-set-context"
import { CaseMetadataContext } from "../../hooks/use-case-metadata"
import { useDocumentContent } from "../../hooks/use-document-content"
import { CaseTableModelContext } from "./use-case-table-model"
import "./case-table-inspector.scss"

export const CaseTableInspector = ({ tile, show }: ITileInspectorPanelProps) => {
const [showInfoModal, setShowInfoModal] = useState(false)
const tableModel: ICaseTableModel | undefined = isCaseTableModel(tile?.content) ? tile?.content : undefined
const { data, metadata } = useDataSet(tableModel?.data, tableModel?.metadata)
const documentContent = useDocumentContent()

if (!tableModel) return null

Expand All @@ -34,7 +32,7 @@ export const CaseTableInspector = ({ tile, show }: ITileInspectorPanelProps) =>
break
case "resizeColumns":
//TODO move log to respective handler
documentContent?.applyModelChange(() => {}, {
tableModel?.applyModelChange(() => {}, {
log: {message:`resizeColumns`, event_value: {dataContext: data?.name}}
})
break
Expand Down

0 comments on commit 5acfabb

Please sign in to comment.