Skip to content

Commit 252ff4e

Browse files
committed
TS: some minor cleaning up.
1 parent c969e3d commit 252ff4e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/renderer/src/components/views/SimulationExperimentView.vue

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
<ScrollPanel class="h-full">
7171
<Fieldset legend="Input parameters">
7272
<InputWidget
73-
v-for="(input, index) in (uiJson as any).input"
73+
v-for="(input, index) in uiJson.input"
7474
v-model="interactiveInputValues[index]!"
7575
v-show="interactiveShowInput[index]"
7676
:key="`input_${index}`"
7777
:name="input.name"
78-
:maximumValue="input.maximumValue"
79-
:minimumValue="input.minimumValue"
80-
:possibleValues="input.possibleValues"
81-
:stepValue="input.stepValue"
78+
:maximumValue="isScalarInput(input) ? input.maximumValue : undefined"
79+
:minimumValue="isScalarInput(input) ? input.minimumValue : undefined"
80+
:possibleValues="isDiscreteInput(input) ? input.possibleValues : undefined"
81+
:stepValue="isScalarInput(input) ? input.stepValue : undefined"
8282
:class="index !== 0 ? 'mt-6' : ''"
8383
@change="updateInteractiveSimulation"
8484
/>
@@ -88,7 +88,7 @@
8888
<div class="flex flex-col grow gap-2 h-full min-h-0">
8989
<IssuesView v-show="interactiveInstanceIssues.length !== 0" :leftMargin="false" :width="width" :height="actualHeight" :issues="interactiveInstanceIssues" />
9090
<GraphPanelWidget v-show="interactiveInstanceIssues.length === 0"
91-
v-for="(_plot, index) in (uiJson as any).output.plots"
91+
v-for="(_plot, index) in uiJson.output.plots"
9292
:key="`plot_${index}`"
9393
class="flex-1 w-full min-h-0"
9494
:margins="interactiveCompMargins"
@@ -175,6 +175,16 @@ function populateParameters(parameters: vue.Ref<string[]>, instanceTask: locSedA
175175
parameters.value.sort((parameter1: string, parameter2: string) => parameter1.localeCompare(parameter2));
176176
}
177177
178+
// Type guards.
179+
180+
function isScalarInput(input: locApi.IUiJsonInput): input is locApi.IUiJsonScalarInput {
181+
return 'maximumValue' in input && 'minimumValue' in input;
182+
}
183+
184+
function isDiscreteInput(input: locApi.IUiJsonInput): input is locApi.IUiJsonDiscreteInput {
185+
return 'possibleValues' in input;
186+
}
187+
178188
// Standard mode.
179189
180190
const standardDocument = props.file.document();

src/renderer/src/libopencor/locApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ export {
161161

162162
export {
163163
type IUiJson,
164+
type IUiJsonDiscreteInput,
164165
type IUiJsonDiscreteInputPossibleValue,
165166
type IUiJsonInput,
166167
type IUiJsonOutput,
167168
type IUiJsonOutputData,
168169
type IUiJsonOutputPlot,
169170
type IUiJsonOutputPlotAdditionalTrace,
170171
type IUiJsonParameter,
172+
type IUiJsonScalarInput,
171173
uiJsonIssues
172174
} from './locUiJsonApi.ts';
173175

src/renderer/src/libopencor/locUiJsonApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IUiJson {
1212

1313
export type IUiJsonInput = IUiJsonDiscreteInput | IUiJsonScalarInput;
1414

15-
interface IUiJsonDiscreteInput {
15+
export interface IUiJsonDiscreteInput {
1616
defaultValue: number;
1717
id: string;
1818
name: string;
@@ -25,7 +25,7 @@ export interface IUiJsonDiscreteInputPossibleValue {
2525
value: number;
2626
}
2727

28-
interface IUiJsonScalarInput {
28+
export interface IUiJsonScalarInput {
2929
defaultValue: number;
3030
id: string;
3131
maximumValue: number;

0 commit comments

Comments
 (0)