Skip to content

Commit

Permalink
187573237 case card attribute menu (#1325)
Browse files Browse the repository at this point in the history
* Opens EditAttributePropertiesModal from case card attribute menu

* Change add new attribute function to use V3 code. This fixes a bug where user could not add a value to the new attribute in the case card, which also meant evaluated formulas were could not be added as values.

Adds ability add a formula to an attribute in the case card, using V3 modal.

* Adds ability to hide attributes in case card.
Case card hides attributes that were hidden in case table.

* Fixes adding new attribute in case card again

* Moves the loop for adding values to the attr before the logic of where to place the new attr

* Moves card case attribute menu functionality to the DG data context utilities.

* Moves SharedCaseMetDataPropType declaration to case-card.v2

Cleans up unused imports

* Fizes broken jest test

* fixes change in variables

* chore: code review tweaks

---------

Co-authored-by: Kirk Swenson <[email protected]>
  • Loading branch information
eireland and kswenson authored Jul 9, 2024
1 parent 96e8665 commit f9ca77e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 241 deletions.
73 changes: 53 additions & 20 deletions v3/src/components/case-card/case-card.v2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import createReactClass from "create-react-class"
import PropTypes from 'prop-types'
import React from 'react'
import ReactDOMFactories from "react-dom-factories"
import { createReactFactory, DG } from "../../v2/dg-compat.v2"
import { SC } from "../../v2/sc-compat"
import { getSharedCaseMetadataFromDataset } from "../../models/shared/shared-data-utils"
import { EditAttributePropertiesModal } from "../case-table/attribute-menu/edit-attribute-properties-modal"
import { EditFormulaModal } from "../case-table/attribute-menu/edit-formula-modal"

import "./attribute-name-cell.v2"
import "./attribute-value-cell.v2"
Expand Down Expand Up @@ -231,6 +235,30 @@ iDataContext.doSelectCases({
}
},

/**
* --------------Show the modal for editing attribute --------
*/
editAttributePropModal(attributeId, isOpen) {
if (attributeId) {
this.setState({editAttributePropModalIsOpen: isOpen, currentAttributeId: attributeId})
}
},

closeEditAttributePropModal() {
this.setState({ editAttributePropModalIsOpen: false, currentAttributeId: null })
},

editFormulaModal(attributeId, isOpen) {
if (attributeId) {
this.setState({editFormulaModalIsOpen: isOpen, currentAttributeId: attributeId})
}
},

closeEditFormulaModal() {
this.setState({ editFormulaModalIsOpen: false, currentAttributeId: null })
this.incrementStateCount()
},

/**
* ------------------Below here are rendering functions---------------
*/
Expand Down Expand Up @@ -501,22 +529,16 @@ iDataContext.doSelectCases({
}
}.bind(this),
editAttribute = function () {
this.updateAttribute = function(iAttrRef, iChangedAttrProps) {
updateAttribute(iChangedAttrProps)
}
var attributePane = DG.AttributeEditorView.create({attrRef: {attribute: iAttr}, attrUpdater: this})
attributePane.append()
this.editAttributePropModal(iAttr.get('id'), true)
}.bind(this),

editFormula = function () {
iContext.invokeLater(function () {
DG.DataContextUtilities.editAttributeFormula(iContext, iCollection,
iAttr.get('name'), iAttr.get('formula'))
}, 30)
this.editFormulaModal(iAttr.get('id'), true)
}.bind(this),

hideAttribute = function () {
DG.DataContextUtilities.hideAttribute(iContext, iAttr.get('id'))
this.incrementStateCount() // Force a re-render
}.bind(this),

attributeCanBeHidden = function () {
Expand Down Expand Up @@ -553,14 +575,13 @@ iDataContext.doSelectCases({
},

makeNewAttribute = function() {
var collection = iContext.getCollectionByID(iCollection.get('id')),
position = 1, // Just after the first attribute
onComplete = function(attrName) {
var attrRef = iContext.getAttrRefByName(attrName),
attrID = attrRef?.attribute.get('id')
attrID && this.setState({ attrIdOfNameToEdit: attrID })
}.bind(this)
DG.DataContextUtilities.newAttribute(iContext, collection, position, onComplete)
const position = 1 // Just after the first attribute
const onComplete = function(attrName) {
var attrRef = iContext.getAttrRefByName(attrName),
attrID = attrRef?.attribute.get('id')
attrID && this.setState({ attrIdOfNameToEdit: attrID })
}.bind(this)
DG.DataContextUtilities.newAttribute(iContext, iCollection, position, onComplete)
}.bind(this)

/**
Expand Down Expand Up @@ -850,7 +871,8 @@ return tResult
return tParents
}

var tCollClient = tContext.getCollectionByID(iCollection.get('id')),
var tCaseMetadata = getSharedCaseMetadataFromDataset(tContext.data),
tCollClient = tContext.getCollectionByID(iCollection.get('id')),
tCollectionName = tCollClient.get('name'),
tSelectedCases = tCollClient ? tCollClient.getPath('casesController.selection').toArray() : null,
tSelLength = tSelectedCases ? tSelectedCases.length : 0,
Expand All @@ -867,7 +889,7 @@ return tResult
tResizeHandle

iCollection.get('attrs').forEach(function (iAttr, iAttrIndex) {
if (!iAttr.get('hidden')) {
if (!tCaseMetadata?.isHidden(iAttr.get("id"))) {
tAttrEntries.push(
this.renderAttribute(tContext, iCollection, tCases,
iAttr, iAttrIndex, tShouldSummarize,
Expand Down Expand Up @@ -906,7 +928,18 @@ return tResult
return div({
className: 'react-data-card dg-wants-wheel',
onMouseDownCapture: DG.Core.setClickHandlingForReact,
}, tCollEntries)
},
tCollEntries,
this.state.editAttributePropModalIsOpen && React.createElement(EditAttributePropertiesModal, {
attributeId: this.state.currentAttributeId,
isOpen: this.state.editAttributePropModalIsOpen,
onClose: this.closeEditAttributePropModal
}),
this.state.editFormulaModalIsOpen && React.createElement(EditFormulaModal, {
attributeId: this.state.currentAttributeId,
isOpen: this.state.editFormulaModalIsOpen,
onClose: this.closeEditFormulaModal
}))
}
}
}()), [])
Expand Down
11 changes: 6 additions & 5 deletions v3/src/models/data/data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,12 @@ export const DataSet = V2Model.named("DataSet").props({
// add attribute to attrNameMap
self.attrNameMap.set(attribute.name, attribute.id)

// fill out any missing values
// for (let i = attribute.strValues.length; i < self.cases.length; ++i) {
for (let i = attribute.strValues.length; i < self.itemIds.length; ++i) {
attribute.addValue()
}

// add attribute reference to attributes array
const beforeIndex = beforeID ? self.attrIndexFromID(beforeID) ?? -1 : -1
if (beforeID && beforeIndex >= 0) {
Expand All @@ -723,11 +729,6 @@ export const DataSet = V2Model.named("DataSet").props({
return attribute
}

// fill out any missing values
for (let i = attribute.strValues.length; i < self.items.length; ++i) {
attribute.addValue()
}

// add the attribute to the specified collection (if any) or the childmost collection
if (!collection && collectionId) {
collection = self.getCollection(collectionId)
Expand Down
Loading

0 comments on commit f9ca77e

Please sign in to comment.