-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
188497515 v3 Plotted Function/Value Formula Editor (#1574)
* Separate attribute logic from formula editor. * Use EditFormulaModal for plotted function and plotted value.
- Loading branch information
1 parent
09bf101
commit 9e67584
Showing
11 changed files
with
195 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react" | ||
import { observer } from "mobx-react-lite" | ||
import { DataSetContext } from "../../hooks/use-data-set-context" | ||
import { logStringifiedObjectMessage } from "../../lib/log-message" | ||
import { appState } from "../../models/app-state" | ||
import { updateAttributesNotification, updateCasesNotification } from "../../models/data/data-set-notifications" | ||
import { getSharedDataSets } from "../../models/shared/shared-data-utils" | ||
import { uiState } from "../../models/ui-state" | ||
import { t } from "../../utilities/translation/translate" | ||
import { EditFormulaModal } from "./edit-formula-modal" | ||
|
||
export const EditAttributeFormulaModal = observer(function EditAttributeFormulaModal() { | ||
const attributeId = uiState.editFormulaAttributeId | ||
const dataSet = getSharedDataSets(appState.document).find(ds => ds.dataSet.attrFromID(attributeId))?.dataSet | ||
const attribute = dataSet?.attrFromID(attributeId) | ||
const value = attribute?.formula?.display | ||
|
||
const applyFormula = (formula: string) => { | ||
if (attribute) { | ||
dataSet?.applyModelChange(() => { | ||
attribute.setDisplayExpression(formula) | ||
}, { | ||
// TODO Should also broadcast notify component edit formula notification | ||
notify: [ | ||
updateCasesNotification(dataSet), | ||
updateAttributesNotification([attribute], dataSet) | ||
], | ||
undoStringKey: "DG.Undo.caseTable.editAttributeFormula", | ||
redoStringKey: "DG.Redo.caseTable.editAttributeFormula", | ||
log: logStringifiedObjectMessage("Edit attribute formula: %@", | ||
{name: attribute.name, collection: dataSet?.getCollectionForAttribute(attributeId)?.name, formula}, | ||
"data") | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<DataSetContext.Provider value={dataSet}> | ||
<EditFormulaModal | ||
applyFormula={applyFormula} | ||
formulaPrompt={t("DG.AttrFormView.formulaPrompt")} | ||
isOpen={!!uiState.editFormulaAttributeId} | ||
onClose={() => uiState.setEditFormulaAttributeId()} | ||
titleInput={attribute?.name} | ||
titleLabel={t("DG.AttrFormView.attrNamePrompt")} | ||
titlePlaceholder={t("V3.AttrFormView.attrPlaceholder")} | ||
value={value} | ||
/> | ||
</DataSetContext.Provider> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
cursor: default; | ||
|
||
.formula-form-control { | ||
.title-label { | ||
width: 140px; | ||
} | ||
|
||
input { | ||
max-width: 270px; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.