Skip to content

Commit f1a8241

Browse files
committed
Refines config loading and message defaults
Omits runtime config injection during local development and warns if unavailable Provides default message for safer editing Loosens schema constraints to allow indefinite message display
1 parent 9ae46d2 commit f1a8241

File tree

6 files changed

+67
-16
lines changed

6 files changed

+67
-16
lines changed

editor/index.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
<link rel="stylesheet" href="/src/index.css" />
99
<!-- Runtime configuration for Azure App Service -->
1010
<script>
11-
// Load runtime config with cache-busting timestamp
12-
const script = document.createElement('script');
13-
script.src = '/runtime-config.js?v=' + Date.now();
14-
document.head.appendChild(script);
11+
// Load runtime config with cache-busting timestamp (only in production)
12+
if (window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
13+
const script = document.createElement('script');
14+
script.src = '/runtime-config.js?v=' + Date.now();
15+
script.onerror = function() {
16+
console.warn('Runtime config not available - using build-time environment variables');
17+
};
18+
document.head.appendChild(script);
19+
}
1520
</script>
1621
</head>
1722
<body>

editor/src/components/MessageEditor.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { Message } from '../types';
33

44
interface MessageEditorProps {
55
title: string;
6-
message: Message;
6+
message: Message | undefined;
77
onChange: (message: Message) => void;
88
}
99

1010
export const MessageEditor: React.FC<MessageEditorProps> = ({ title, message, onChange }) => {
11+
// Provide default empty message if undefined
12+
const currentMessage: Message = message || { header: '', description: '', seconds: -1 };
13+
1114
const update = (patch: Partial<Message>) => {
12-
onChange({ ...message, ...patch });
15+
onChange({ ...currentMessage, ...patch });
1316
};
1417

1518
return (
@@ -21,7 +24,7 @@ export const MessageEditor: React.FC<MessageEditorProps> = ({ title, message, on
2124
Header
2225
<input
2326
type="text"
24-
value={message.header}
27+
value={currentMessage.header}
2528
onChange={e => update({ header: e.target.value })}
2629
placeholder="Enter message header..."
2730
/>
@@ -33,7 +36,7 @@ export const MessageEditor: React.FC<MessageEditorProps> = ({ title, message, on
3336
Description
3437
<input
3538
type="text"
36-
value={message.description || ''}
39+
value={currentMessage.description || ''}
3740
onChange={e => update({ description: e.target.value })}
3841
placeholder="Optional supporting text..."
3942
/>
@@ -45,7 +48,7 @@ export const MessageEditor: React.FC<MessageEditorProps> = ({ title, message, on
4548
Display Duration
4649
<select
4750
className="cond-input"
48-
value={message.seconds || 0}
51+
value={currentMessage.seconds || 0}
4952
onChange={e => update({ seconds: Number(e.target.value) })}
5053
>
5154
<option value={0}>Hidden</option>

editor/src/components/TreeView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react';
22
import { ScriptData, Activity, Step } from '../types';
33

44
// Convert PascalCase to readable title (e.g., "RangeAnalysisScriptedStep" -> "Range Analysis Scripted Step")
5-
const formatNodeType = (nodeType: string): string => {
5+
const formatNodeType = (nodeType: string | undefined): string => {
6+
if (!nodeType) return 'Unknown Type';
67
return nodeType
78
.replace(/([A-Z])/g, ' $1') // Add space before capital letters
89
.trim(); // Remove leading space

editor/src/factories.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,53 @@ export function createMessage(partial: Partial<Message> = {}): Message {
1010
}
1111

1212
export function createActivity(opts: any): ScriptedActivity {
13-
return opts as ScriptedActivity;
13+
const activity = {
14+
nodeType: opts.nodeType || 'RangeAnalysisScriptedActivity',
15+
id: opts.id,
16+
introMessage: opts.introMessage || {
17+
header: opts.introHeader || '',
18+
description: opts.introDescription || '',
19+
seconds: -1
20+
},
21+
endMessage: opts.endMessage || {
22+
header: '',
23+
description: '',
24+
seconds: -1
25+
},
26+
steps: opts.steps || []
27+
};
28+
29+
return activity as ScriptedActivity;
1430
}
1531

1632
export function createStep(opts: any): ScriptedStep {
17-
return opts as ScriptedStep;
33+
const step = {
34+
nodeType: opts.nodeType || 'RangeAnalysisScriptedStep',
35+
id: opts.id,
36+
introMessage: opts.introMessage || {
37+
header: opts.introHeader || '',
38+
description: opts.introDescription || '',
39+
seconds: -1
40+
},
41+
successMessage: opts.successMessage || {
42+
header: '',
43+
description: '',
44+
seconds: -1
45+
},
46+
failMessage: opts.failMessage || {
47+
header: '',
48+
description: '',
49+
seconds: -1
50+
},
51+
logic: opts.logic || {
52+
// Default logic based on step type
53+
...(opts.nodeType === 'PerformanceCenterScriptedStep' ? {
54+
nodeType: 'PerformanceCenterScriptedLogic'
55+
} : {
56+
nodeType: 'RangeAnalysisScriptedLogic'
57+
})
58+
}
59+
};
60+
61+
return step as ScriptedStep;
1862
}

editor/src/schema/app-scripting.schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"properties": {
7878
"header": {
7979
"type": "string",
80-
"minLength": 1,
8180
"description": "Primary message header text displayed to the user."
8281
},
8382
"description": {
@@ -87,7 +86,7 @@
8786
},
8887
"seconds": {
8988
"type": "integer",
90-
"minimum": 0,
89+
"minimum": -1,
9190
"default": 3,
9291
"description": "Seconds to display message on screen. Use -1 to require user to click button to dismiss message."
9392
}

schema/1.0.0/app-scripting.schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"properties": {
7878
"header": {
7979
"type": "string",
80-
"minLength": 1,
8180
"description": "Primary message header text displayed to the user."
8281
},
8382
"description": {
@@ -87,7 +86,7 @@
8786
},
8887
"seconds": {
8988
"type": "integer",
90-
"minimum": 0,
89+
"minimum": -1,
9190
"default": 3,
9291
"description": "Seconds to display message on screen. Use -1 to require user to click button to dismiss message."
9392
}

0 commit comments

Comments
 (0)