Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX changes to create intervention policy #4879

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const InterventionPolicyOperation: Operation = {
description: 'Create intervention policy',
displayName: 'Create intervention policy',
isRunnable: true,
inputs: [{ type: 'modelId', label: 'Model' }],
inputs: [
{ type: 'modelId', label: 'Model' },
{ type: 'documentId', label: 'Document', isOptional: true }
],
outputs: [{ type: 'policyInterventionId', label: 'Intervention Policy' }],
action: () => {},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@
<section>
<div class="flex align-items-center flex-wrap gap-2">
Set
<Dropdown
:model-value="intervention.type"
@change="onSemanticChange"
:options="interventionSemanticOptions"
option-label="label"
option-value="value"
/>
<Dropdown
:model-value="intervention.appliedTo"
@change="onAppliedToParameterChange"
:options="semanticOptions"
option-label="label"
option-value="value"
placeholder="Select"
/>

<section>
<Dropdown
class="type-menu"
:model-value="intervention.type"
@change="onSemanticChange"
:options="interventionSemanticOptions"
option-label="label"
option-value="value"
/>
<Dropdown
class="applied-to-menu"
:model-value="intervention.appliedTo"
@change="onAppliedToParameterChange"
:options="semanticOptions"
option-label="label"
option-value="value"
placeholder="Select"
/>
</section>
<!-- Static -->
<template v-if="interventionType === 'static'">
to
Expand Down Expand Up @@ -118,7 +121,7 @@
@update:model-value="(val) => onUpdateThreshold(val, 0)"
placeholder="threshold"
/>
.
{{ dynamicInterventionUnits }}.
</template>
</div>
</section>
Expand Down Expand Up @@ -149,8 +152,8 @@ import Divider from 'primevue/divider';
const emit = defineEmits(['update', 'delete', 'add']);
const props = defineProps<{
intervention: Intervention;
parameterOptions: { label: string; value: string }[];
stateOptions: { label: string; value: string }[];
parameterOptions: { label: string; value: string; units?: string }[];
stateOptions: { label: string; value: string; units?: string }[];
}>();

const interventionSemanticOptions = [
Expand All @@ -175,6 +178,19 @@ const interventionType = computed(() => {
return 'static';
});

const dynamicInterventionUnits = computed(() => {
let units = '';
const type = props.intervention.type;
const appliedTo = props.intervention.appliedTo;

if (type === InterventionSemanticType.Parameter) {
units = props.parameterOptions.find((parameter) => parameter.label === appliedTo)?.units ?? '';
} else {
units = props.stateOptions.find((state) => state.label === appliedTo)?.units ?? '';
}
return units;
});

const comparisonOperations = [
{ label: 'increases to above', value: true },
{ label: 'decreases to below', value: false }
Expand Down Expand Up @@ -289,6 +305,15 @@ const debounceUpdateState = debounce((intervention) => {
}
}

.type-menu {
border-radius: 5px 0 0 5px;
background: var(--surface-200);
}

.applied-to-menu {
border-radius: 0 5px 5px 0;
}
asylves1 marked this conversation as resolved.
Show resolved Hide resolved

.intervention-card {
background-color: var(--surface-50);
border: 1px solid var(--surface-border-light);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
>
<template #content>
<section>
<nav class="inline-flex">
<!-- Disabled until Backend code is complete -->
<!-- <Button class="flex-1 mr-1" outlined severity="secondary" label="Extract from inputs" /> -->
<Button
class="flex-1 ml-1"
label="Create New"
:disabled="!model?.id"
@click="createNewInterventionPolicy"
/>
</nav>
<tera-input-text v-model="filterInterventionsText" placeholder="Filter" />
<ul v-if="!isFetchingPolicies">
<li v-for="policy in interventionPoliciesFiltered" :key="policy.id">
Expand Down Expand Up @@ -145,6 +155,14 @@
@close-modal="showSaveModal = false"
@on-save="onSaveAsInterventionPolicy"
/>
<tera-save-asset-modal
initial-name="New Intervention Policy"
:is-visible="showCreatePolicyModal"
:asset-type="AssetType.InterventionPolicy"
:asset="newBlankInterventionPolicy"
@close-modal="showCreatePolicyModal = false"
@on-save="onSaveAsInterventionPolicy"
/>
blanchco marked this conversation as resolved.
Show resolved Hide resolved
</template>

<script setup lang="ts">
Expand Down Expand Up @@ -205,7 +223,14 @@ const knobs = ref<BasicKnobs>({
}
});

const newBlankInterventionPolicy = ref({
name: '',
modelId: '',
interventions: []
});
asylves1 marked this conversation as resolved.
Show resolved Hide resolved

const showSaveModal = ref(false);
const showCreatePolicyModal = ref(false);
const isSidebarOpen = ref(true);
const filterInterventionsText = ref('');
const model = ref<Model | null>(null);
Expand Down Expand Up @@ -249,15 +274,17 @@ const parameterOptions = computed(() => {
if (!model.value) return [];
return getParameters(model.value).map((parameter) => ({
label: parameter.id,
value: parameter.id
value: parameter.id,
units: parameter.units?.expression
}));
});

const stateOptions = computed(() => {
if (!model.value) return [];
return getStates(model.value).map((state) => ({
label: state.id,
value: state.id
value: state.id,
units: state.units?.expression
}));
});

Expand Down Expand Up @@ -426,6 +453,12 @@ const onSaveInterventionPolicy = async () => {
}
};

const createNewInterventionPolicy = () => {
if (!model.value?.id) return;
newBlankInterventionPolicy.value.modelId = model.value?.id;
asylves1 marked this conversation as resolved.
Show resolved Hide resolved
showCreatePolicyModal.value = true;
};

watch(
() => knobs.value,
async () => {
Expand Down