-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Parameterized Input Support (#9911)
This adds support for string and number parameters in criteria. I've tried to make the UI passable, but it's not perfect (particularly, I think the text boxes should expand to fit contents, it lacks signal when there's an issue, like an empty parameter, and the results page should probably put boxes around the parameter values). I'd like to follow up with a separate change to polish all that off, since this one is a bit big already. One notable adjustment, I made the parameter path field into a list so that one parameter can affect multiple values in a validator plan (useful if the thing you're validating requires multiple checks, like custom functions are created and called).
- Loading branch information
Showing
22 changed files
with
473 additions
and
52 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 |
---|---|---|
|
@@ -220,4 +220,4 @@ export const Input = (props: InputProps) => { | |
} | ||
</div> | ||
); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,106 @@ | ||
import { getCatalogCriteriaWithId } from "../state/helpers"; | ||
import { CriteriaInstance, CriteriaParameterValue } from "../types/criteria"; | ||
import { DebouncedInput } from "./DebouncedInput"; | ||
import { logDebug } from "../services/loggingService"; | ||
import { setParameterValue } from "../transforms/setParameterValue"; | ||
import { classList } from "react-common/components/util"; | ||
import { splitCriteriaTemplate } from "../utils"; | ||
// eslint-disable-next-line import/no-internal-modules | ||
import css from "./styling/CriteriaInstanceDisplay.module.scss"; | ||
|
||
interface InlineInputSegmentProps { | ||
initialValue: string; | ||
instance: CriteriaInstance; | ||
param: CriteriaParameterValue; | ||
shouldExpand: boolean; | ||
numeric: boolean; | ||
} | ||
const InlineInputSegment: React.FC<InlineInputSegmentProps> = ({ | ||
initialValue, | ||
instance, | ||
param, | ||
shouldExpand, | ||
numeric, | ||
}) => { | ||
function onChange(newValue: string) { | ||
setParameterValue(instance.instanceId, param.name, newValue); | ||
} | ||
|
||
return ( | ||
<DebouncedInput | ||
className={classList( | ||
css["inline-input"], | ||
numeric ? css["number-input"] : css["string-input"], | ||
shouldExpand ? css["long"] : undefined, | ||
)} | ||
initialValue={initialValue} | ||
onChange={onChange} | ||
preserveValueOnBlur={true} | ||
placeholder={numeric ? "0" : param.name} | ||
title={param.name} | ||
autoComplete={false} | ||
type = {numeric ? "number" : "text"} | ||
/> | ||
); | ||
}; | ||
|
||
interface CriteriaInstanceDisplayProps { | ||
criteriaInstance: CriteriaInstance; | ||
} | ||
|
||
export const CriteriaInstanceDisplay: React.FC<CriteriaInstanceDisplayProps> = ({ criteriaInstance }) => { | ||
const catalogCriteria = getCatalogCriteriaWithId(criteriaInstance.catalogCriteriaId); | ||
if (!catalogCriteria) { | ||
return null; | ||
} | ||
|
||
function getParameterSegmentDisplay(paramName: string): JSX.Element | null { | ||
if (!paramName) { | ||
return null; | ||
} | ||
|
||
const paramDef = catalogCriteria?.params?.find(p => p.name === paramName); | ||
const paramInstance = criteriaInstance?.params?.find(p => p.name === paramName); | ||
if (!paramDef || !paramInstance) { | ||
logDebug(`Missing info for '${paramName}': paramDef=${paramDef}, paramInstance=${paramInstance}`); | ||
return null; | ||
} | ||
|
||
if (paramDef.type === "block") { | ||
// TODO | ||
return null; | ||
} else { | ||
return ( | ||
<InlineInputSegment | ||
initialValue={paramInstance.value} | ||
param={paramInstance} | ||
instance={criteriaInstance} | ||
shouldExpand={paramDef.type === "longString"} | ||
numeric={paramDef.type === "number"} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
function getPlainTextSegmentDisplay(text: string): JSX.Element | null { | ||
return text ? <div className={css["text-segment"]}>{text}</div> : null; | ||
} | ||
|
||
const templateSegments = splitCriteriaTemplate(catalogCriteria.template); | ||
const display = templateSegments.map(s => | ||
s.type === "plain-text" ? getPlainTextSegmentDisplay(s.content) : getParameterSegmentDisplay(s.content) | ||
); | ||
|
||
return catalogCriteria ? ( | ||
<div className={css["criteria-instance-display"]}> | ||
<div className={css["segment-container"]}> | ||
{display.map((part, i) => ( | ||
<span className={css["segment"]} key={i}> | ||
{part} | ||
</span> | ||
))} | ||
</div> | ||
<div className={css["criteria-description"]}>{catalogCriteria.description}</div> | ||
</div> | ||
) : null; | ||
}; |
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.