Skip to content

Commit

Permalink
Merge pull request #14 from GridProtectionAlliance/TDAP-30
Browse files Browse the repository at this point in the history
Name checking requirements updated to avoid some confusion TDAP-30
  • Loading branch information
clackner-gpa authored Jul 5, 2024
2 parents 9fb2bca + 27ff40e commit e16912e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions TrenDAP/wwwroot/TypeScript/Features/DataSets/DataSets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const DataSets: React.FunctionComponent = (props: {}) => {
<div className="card-header">
<div className="row">
<div className="col">
<h4>My DataSets</h4>
<h4>My Data Sets</h4>
</div>
<div className="col">
<button className="btn btn-primary pull-right"
Expand Down Expand Up @@ -147,7 +147,7 @@ const DataSets: React.FunctionComponent = (props: {}) => {
<div className="card">
<div className="card-header">
<h4>
Shared DataSets
Shared Data Sets
</h4>
</div>
<div className="card-body">
Expand Down
16 changes: 9 additions & 7 deletions TrenDAP/wwwroot/TypeScript/Features/DataSets/EditDataSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const EditDataSet: React.FunctionComponent<{}> = (props) => {
}, [dataSetStatus]);

React.useEffect(() => {
if (dataSetStatus !== 'idle') return; //SelectNewDataSet
if (dataSetStatus !== 'idle') return;
const id = (props['useParams']?.id ?? -1);
if (id < 0) setDataSet(SelectNewDataSet());
else setDataSet(dataSets.find(set => set.ID == id));
Expand Down Expand Up @@ -101,11 +101,11 @@ const EditDataSet: React.FunctionComponent<{}> = (props) => {
if (dataSet == null) return;
const w = [];
if (dataSet.Context == 'Relative' && dataSet.RelativeWindow == 'Day' && dataSet.RelativeValue < 7)
w.push("With the current Time Context and Day of Week Filter it is possible for the dataset to be empty at times.")
w.push("With the current Time Context and Day of Week Filter it is possible for the data set to be empty at times.")
if (dataSet.Context == 'Relative' && dataSet.RelativeWindow == 'Week' && dataSet.RelativeValue < 53)
w.push("With the current Time Context and Week of Year Filter it is possible for the dataset to be empty at times.")
w.push("With the current Time Context and Week of Year Filter it is possible for the data set to be empty at times.")
if (dataSet.Context == 'Relative' && dataSet.RelativeWindow == 'Day' && dataSet.RelativeValue < 366)
w.push("With the current Time Context and Week of Year Filter it is possible for the dataset to be empty at times.")
w.push("With the current Time Context and Week of Year Filter it is possible for the data set to be empty at times.")
setWarning(w);
}, [dataSet]);

Expand All @@ -114,10 +114,12 @@ const EditDataSet: React.FunctionComponent<{}> = (props) => {
const e = [];
if (dataSet.Name == null || dataSet.Name.trim().length == 0)
e.push("A Name has to be entered.")
if (dataSet.Name != null && dataSet.Name.length > 200)
else if (dataSet.Name.length > 200)
e.push("Name has to be less than 200 characters.");
if (dataSet.Name != null && dataSets.findIndex(ds => ds.ID !== dataSet.ID && ds.Name.toLowerCase() == dataSet.Name.toLowerCase()) > -1)
e.push("A DataSet with this name already exists.");
else if (dataSets.findIndex(ds => (ds.Public || ds.User === userName) && ds.ID !== dataSet.ID && ds.Name.toLowerCase() == dataSet.Name.toLowerCase()) > -1)
e.push("A Data Set with this name already exists.");
else if (dataSet.Public && dataSets.findIndex(ds => ds.ID !== dataSet.ID && ds.Name.toLowerCase() == dataSet.Name.toLowerCase()) > -1)
e.push("A Data Set with this name was already created by another user.");
if (dataSet.Context == 'Fixed Dates' && moment(dataSet.From).isAfter(moment(dataSet.To)))
e.push("A valid Timeframe has to be selected.")
if (dataSet.Hours == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface IProps {
}

const DataSetSettingsTab: React.FunctionComponent<IProps> = (props: IProps) => {
const [nameFeedback, setNameFeedback] = React.useState<string>("A Data Set with this name already exists.");
const dispatch = useAppDispatch();
const dataSets = useAppSelector(SelectDataSets);
const dataSetStatus = useAppSelector(SelectDataSetsStatus);
Expand All @@ -49,9 +50,20 @@ const DataSetSettingsTab: React.FunctionComponent<IProps> = (props: IProps) => {
}, [dataSetStatus]);

function valid(field: keyof (TrenDAP.iDataSet)): boolean {
if (field == 'Name')
return props.DataSet.Name != null && props.DataSet.Name.trim().length > 0 &&
props.DataSet.Name.length <= 200 && dataSets.find(ws => ws.Name.toLowerCase() == props.DataSet.Name.toLowerCase() && ws.ID != props.DataSet.ID) == null
if (field == 'Name') {
if (props.DataSet.Name == null || props.DataSet.Name.trim().length == 0 || props.DataSet.Name.length > 200) {
setNameFeedback("Name less than 200 Characters is required.")
return false;
}
else if (dataSets.findIndex(ds => (ds.Public || ds.User === userName) && ds.ID !== props.DataSet.ID && ds.Name.toLowerCase() == props.DataSet.Name.toLowerCase()) > -1) {
setNameFeedback("A Data Set with this name already exists.")
return false;
}
else if (props.DataSet.Public && dataSets.findIndex(ds => ds.ID !== props.DataSet.ID && ds.Name.toLowerCase() == props.DataSet.Name.toLowerCase()) > -1) {
setNameFeedback("A Data Set with this name was already created by another user.");
return false;
} else return true;
}
else
return true;
}
Expand All @@ -72,7 +84,7 @@ const DataSetSettingsTab: React.FunctionComponent<IProps> = (props: IProps) => {

return (
<>
<Input<TrenDAP.iDataSet> Record={props.DataSet} Field="Name" Setter={(record) => props.SetDataSet(record)} Valid={valid} Feedback={"A Unique Name has to be specified"} />
<Input<TrenDAP.iDataSet> Record={props.DataSet} Field="Name" Setter={(record) => props.SetDataSet(record)} Valid={valid} Feedback={nameFeedback} />
<RelativeDateRangePicker Record={props.DataSet} Setter={(record) => props.SetDataSet(record)} />
<EnumCheckBoxes<TrenDAP.iDataSet> Record={props.DataSet} Field="Hours" Label="Hour of Day" Setter={(record) => props.SetDataSet(record)} Enum={Array.from({ length: 24 }, (_, i) => i.toString())} />
<EnumCheckBoxes<TrenDAP.iDataSet> Record={props.DataSet} Field="Days" Label="Day of Week" Setter={(record) => props.SetDataSet(record)} Enum={['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']} IsDisabled={validDay} />
Expand Down

0 comments on commit e16912e

Please sign in to comment.