Removed summary length validation, added validation for REFERENCE_END types in the normal interview tree
This commit is contained in:
parent
6f7003ba62
commit
38bf5e0d2f
2 changed files with 12 additions and 55 deletions
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -132,14 +133,19 @@ public class InterviewTemplateCommands
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Validate that any references with reference end steps have an after reference step
|
|
||||||
|
|
||||||
List<string> errors = [];
|
List<string> errors = [];
|
||||||
List<string> warnings = [];
|
List<string> warnings = [];
|
||||||
template.interview.Validate(ref errors, ref warnings, "interview", template.definitions, 0, 0);
|
template.interview.Validate(ref errors, ref warnings, "interview", template.definitions);
|
||||||
foreach (KeyValuePair<string, InterviewStep> definition in template.definitions)
|
foreach (KeyValuePair<string, InterviewStep> definition in template.definitions)
|
||||||
{
|
{
|
||||||
definition.Value.Validate(ref errors, ref warnings, "definitions." + definition.Key, template.definitions, 0, 0);
|
definition.Value.Validate(ref errors, ref warnings, "definitions." + definition.Key, template.definitions);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InterviewStep> allSteps = new();
|
||||||
|
template.interview.GetAllSteps(ref allSteps);
|
||||||
|
if (allSteps.Any(s => s.stepType is StepType.REFERENCE_END))
|
||||||
|
{
|
||||||
|
errors.Add("The normal interview tree cannot contain any steps of the 'REFERENCE_END' type, these are only allowed in the 'definitions'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors.Count != 0)
|
if (errors.Count != 0)
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class InterviewStep
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets all steps in the interview tree, including after-reference-steps but not referenced steps
|
// Gets all steps in the interview tree, including after-reference-steps but not referenced steps
|
||||||
private void GetAllSteps(ref List<InterviewStep> allSteps)
|
public void GetAllSteps(ref List<InterviewStep> allSteps)
|
||||||
{
|
{
|
||||||
allSteps.Add(this);
|
allSteps.Add(this);
|
||||||
foreach (KeyValuePair<string, InterviewStep> step in steps)
|
foreach (KeyValuePair<string, InterviewStep> step in steps)
|
||||||
|
@ -281,42 +281,8 @@ public class InterviewStep
|
||||||
ref List<string> warnings,
|
ref List<string> warnings,
|
||||||
string stepID,
|
string stepID,
|
||||||
Dictionary<string, InterviewStep> definitions,
|
Dictionary<string, InterviewStep> definitions,
|
||||||
int summaryFieldCount = 0,
|
|
||||||
int summaryMaxLength = 0,
|
|
||||||
InterviewStep parent = null)
|
InterviewStep parent = null)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(summaryField))
|
|
||||||
{
|
|
||||||
++summaryFieldCount;
|
|
||||||
summaryMaxLength += summaryField.Length;
|
|
||||||
switch (stepType)
|
|
||||||
{
|
|
||||||
case StepType.BUTTONS:
|
|
||||||
case StepType.TEXT_SELECTOR:
|
|
||||||
// Get the longest button/selector text
|
|
||||||
if (steps.Count > 0)
|
|
||||||
{
|
|
||||||
summaryMaxLength += steps.Max(kv => kv.Key.Length);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case StepType.USER_SELECTOR:
|
|
||||||
case StepType.ROLE_SELECTOR:
|
|
||||||
case StepType.MENTIONABLE_SELECTOR:
|
|
||||||
case StepType.CHANNEL_SELECTOR:
|
|
||||||
// Approximate length of a mention
|
|
||||||
summaryMaxLength += 23;
|
|
||||||
break;
|
|
||||||
case StepType.TEXT_INPUT:
|
|
||||||
summaryMaxLength += Math.Min(maxLength ?? 1024, 1024);
|
|
||||||
break;
|
|
||||||
case StepType.INTERVIEW_END:
|
|
||||||
case StepType.ERROR:
|
|
||||||
case StepType.REFERENCE_END:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (answerDelimiter != null && string.IsNullOrWhiteSpace(summaryField))
|
if (answerDelimiter != null && string.IsNullOrWhiteSpace(summaryField))
|
||||||
{
|
{
|
||||||
warnings.Add("An answer-delimiter has no effect without a summary-field.\n\n> " + stepID + ".answer-delimiter");
|
warnings.Add("An answer-delimiter has no effect without a summary-field.\n\n> " + stepID + ".answer-delimiter");
|
||||||
|
@ -372,21 +338,6 @@ public class InterviewStep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addSummary ?? false)
|
|
||||||
{
|
|
||||||
summaryMaxLength += message?.Length ?? 0;
|
|
||||||
summaryMaxLength += heading?.Length ?? 0;
|
|
||||||
if (summaryFieldCount > 25)
|
|
||||||
{
|
|
||||||
errors.Add("A summary cannot contain more than 25 fields, but you have " + summaryFieldCount + " fields in this branch.\n\n> " + stepID);
|
|
||||||
}
|
|
||||||
else if (summaryMaxLength >= 6000)
|
|
||||||
{
|
|
||||||
warnings.Add("A summary cannot contain more than 6000 characters, but this branch may reach " + summaryMaxLength + " characters.\n" +
|
|
||||||
"Use the \"max-length\" parameter to limit text input field lengths, or shorten other parts of the summary message.\n\n> " + stepID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent?.stepType is not StepType.BUTTONS && buttonStyle != null)
|
if (parent?.stepType is not StepType.BUTTONS && buttonStyle != null)
|
||||||
{
|
{
|
||||||
warnings.Add("Button styles have no effect on child steps of a '" + parent?.stepType + "' step.\n\n> " + stepID + ".button-style");
|
warnings.Add("Button styles have no effect on child steps of a '" + parent?.stepType + "' step.\n\n> " + stepID + ".button-style");
|
||||||
|
@ -414,7 +365,7 @@ public class InterviewStep
|
||||||
|
|
||||||
foreach (KeyValuePair<string, InterviewStep> step in steps)
|
foreach (KeyValuePair<string, InterviewStep> step in steps)
|
||||||
{
|
{
|
||||||
step.Value.Validate(ref errors, ref warnings, FormatJSONKey(stepID + ".steps", step.Key), definitions, summaryFieldCount, summaryMaxLength, this);
|
step.Value.Validate(ref errors, ref warnings, FormatJSONKey(stepID + ".steps", step.Key), definitions, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue