Skip to content

Commit

Permalink
Update & Improve Predicate Names
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkue committed Aug 28, 2024
1 parent 94fbd50 commit 59aa167
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 49 deletions.
22 changes: 14 additions & 8 deletions frontend/src/components/TimeDurationInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export function formatSeconds(
export default function TimeDurationInput({
durationSeconds,
onChange,
placeholder
}: {
durationSeconds: number;
onChange: (newSeconds: number | undefined) => unknown;
placeholder?: string;
}) {
const [unit, setUnit] = useState<(typeof TIME_DURATION_UNITS)[number]>(
getFittingUnit(durationSeconds),
Expand All @@ -82,7 +84,8 @@ export default function TimeDurationInput({
);
}, [durationSeconds]);

function handleValueChange(inputValue: string) {
function handleValueChange(inputValue: string, useUnit = unit) {
inputValue = inputValue.toLowerCase();
if (
inputValue === "∞" ||
inputValue === "inf" ||
Expand All @@ -106,7 +109,7 @@ export default function TimeDurationInput({
const val = parseFloat(inputValue);
if (!isNaN(val)) {
setValue(val);
onChange(val * unitFactorFromSeconds(unit));
onChange(val * unitFactorFromSeconds(useUnit));
setValueString(val.toString());
} else {
setValueString("");
Expand All @@ -116,7 +119,7 @@ export default function TimeDurationInput({

return (
<div className="flex gap-x-2 items-center">
<Input
<Input placeholder={placeholder}
className="w-full"
onBlur={(ev) => {
handleValueChange(ev.currentTarget.value);
Expand All @@ -133,12 +136,15 @@ export default function TimeDurationInput({
options={TIME_DURATION_UNITS.map((u) => ({ value: u, label: u }))}
onChange={(newUnitIn) => {
const newUnit = newUnitIn as (typeof TIME_DURATION_UNITS)[number];
const convertedValue =
value *
(unitFactorFromSeconds(unit) / unitFactorFromSeconds(newUnit));
setValue(convertedValue);
setValueString(convertedValue.toString());
console.log({newUnit,value,unit})
// const convertedValue =
// value *
// (unitFactorFromSeconds(unit) / unitFactorFromSeconds(newUnit));
// setValue(convertedValue);
// setValueString(convertedValue.toString());
setUnit(newUnit);
handleValueChange(value.toString(),newUnit);

}}
name={"Unit"}
value={unit}
Expand Down
48 changes: 24 additions & 24 deletions frontend/src/routes/visual-editor/helper/box/FilterChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,66 +159,66 @@ export default function FilterChooser({
}
options={[
{
label: "Object associated with Event",
label: "E2O: Event-To-Object Relationship",
value: "O2E",
},
{
label: "Object associated with Object",
label: "O2O: Object-To-Object Relationship",
value: "O2O",
},
{
label: "Time between Events",
label: "TBE: Time between Events",
value: "TimeBetweenEvents",
},
// {
// label: "Variables not equal",
// value: "NotEqual",
// },
{
label: "Variables not equal",
value: "NotEqual",
},
{
label: "CEL Script (Basic Filter)",
value: "BasicFilterCEL",
},
{
label: "Event Attribute Value",
label: "EAE/EAR: Event Attribute Value",
value: "EventAttributeValueFilter",
},
{
label: "Object Attribute Value",
label: "OAE/OAR: Object Attribute Value",
value: "ObjectAttributeValueFilter",
},
{
label: "BasicCEL: Basic CEL Script",
value: "BasicFilterCEL",
},
...(alertState.type !== "filter" ||
alertState.mode !== "edit" ||
alertState.wasSizeFilter
? [
{
label: "Number of Child Bindings",
label: "CBS: Child Bindings Set Size",
value: "NumChilds",
},
{
label: "Child Binding Sets Equal",
label: "CBE: Child Binding Sets Equal",
value: "BindingSetEqual",
},
{
label: "Child Binding Set Projects Equal",
value: "BindingSetProjectionEqual",
label: "CBPS: Projected Child Bindings Set Size",
value: "NumChildsProj",
},
{
label: "Number of Projected Child Bindings",
value: "NumChildsProj",
label: "CBPE: Projected Child Binding Sets Equal",
value: "BindingSetProjectionEqual",
},
{
label: "CEL Script (Advanced Filter/Constraint)",
label: "AdvCEL: Advanced CEL Script",
value: "AdvancedCEL",
},
]
: []),

...(alertState.type === "constraint"
? [
{ label: "Child Satisfied (SAT)", value: "SAT" },
{ label: "Child not Satisfied (NOT)", value: "NOT" },
{ label: "Logic AND", value: "AND" },
{ label: "Logic OR", value: "OR" },
{ label: "SAT: All Child Bindings Satisfied", value: "SAT" },
{ label: "NOT: Logic NOT", value: "NOT" },
{ label: "OR: Logic OR", value: "OR" },
{ label: "AND: Logic AND", value: "AND" },
]
: []),
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ export default function FilterOrConstraintEditor<
case "O2E":
return (
<>
<EventVarSelector
eventVars={availableEventVars}
value={value.event}
onChange={(newV) => {
if (newV !== undefined) {
value.event = newV;
updateValue({ ...value });
}
}}
/>
<ObjectVarSelector
objectVars={availableObjectVars}
value={value.object}
Expand All @@ -57,16 +67,6 @@ export default function FilterOrConstraintEditor<
}
}}
/>
<EventVarSelector
eventVars={availableEventVars}
value={value.event}
onChange={(newV) => {
if (newV !== undefined) {
value.event = newV;
updateValue({ ...value });
}
}}
/>
<Input
className="w-full"
placeholder="Qualifier"
Expand Down Expand Up @@ -218,7 +218,7 @@ export default function FilterOrConstraintEditor<
}
}}
/>
<TimeDurationInput
<TimeDurationInput placeholder="Minimum Duration/Delay (Optional)"
durationSeconds={value.min_seconds ?? -Infinity}
onChange={(newVal) => {
if (newVal !== undefined && isFinite(newVal)) {
Expand All @@ -230,7 +230,7 @@ export default function FilterOrConstraintEditor<
}
}}
/>
<TimeDurationInput
<TimeDurationInput placeholder="Maximum Duration/Delay (Optional)"
durationSeconds={value.max_seconds ?? Infinity}
onChange={(newVal) => {
if (newVal !== undefined && isFinite(newVal)) {
Expand All @@ -257,7 +257,7 @@ export default function FilterOrConstraintEditor<
}
}}
/>
<Input
<Input placeholder="Minimal Count (Optional)"
type="number"
value={value.min ?? ""}
onChange={(ev) => {
Expand All @@ -271,7 +271,7 @@ export default function FilterOrConstraintEditor<
}}
/>

<Input
<Input placeholder="Maximal Count (Optional)"
type="number"
value={value.max ?? ""}
onChange={(ev) => {
Expand Down Expand Up @@ -1056,6 +1056,7 @@ function ChildSetSelector({
}
}}
name={"Child Set"}
title="Child Set"
value={value ?? ""}
/>
);
Expand All @@ -1071,7 +1072,7 @@ function AttributeNameSelector({
availableAttributes: string[];
}) {
return (
<Combobox
<Combobox title="Attribute Name"
options={availableAttributes.map((v) => ({
label: v,
value: v,
Expand Down Expand Up @@ -1122,6 +1123,7 @@ function AttributeValueFilterSelector({
}
}}
name={"Attribute Type"}
title="Attribute Type"
value={value?.type ?? "String"}
/>
{value?.type === "Boolean" && (
Expand All @@ -1137,7 +1139,7 @@ function AttributeValueFilterSelector({
)}
{(value?.type === "Float" || value?.type === "Integer") && (
<div className="flex items-center gap-x-2">
<Input
<Input title="Minimum (Optional)" placeholder="Minimum (Optional)"
type="number"
step={value.type === "Integer" ? 1 : undefined}
value={value.min+ ""}
Expand All @@ -1153,7 +1155,7 @@ function AttributeValueFilterSelector({
/>
{"-"}

<Input
<Input title="Maximum (Optional)" placeholder="Maximum (Optional)"
type="number"
step={value.type === "Integer" ? 1 : undefined}
value={value.max+ ""}
Expand Down

0 comments on commit 59aa167

Please sign in to comment.