Skip to content

Commit 4ae5875

Browse files
committed
Fix offline mode validations
1 parent ec2035a commit 4ae5875

File tree

6 files changed

+58
-15
lines changed

6 files changed

+58
-15
lines changed

src/CheckBoxFilter/Validate.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class Validate {
55
static validateProps(props: ContainerProps & { isWebModeler?: boolean }): ReactChild {
66
const errorMessages = [];
77

8-
if (props.filterBy === "XPath" && !props.constraint) {
8+
if (!window.mx.isOffline() && props.filterBy === "XPath" && !props.constraint) {
99
errorMessages.push("The checked 'XPath constraint' is required when 'Filter by' is set to 'XPath'");
1010
}
1111
if (props.filterBy === "attribute" && !props.attribute) {
@@ -14,7 +14,7 @@ export class Validate {
1414
if (props.filterBy === "attribute" && !props.attributeValue) {
1515
errorMessages.push("The checked 'Attribute value' is required when 'Filter by' is set to 'Attribute'");
1616
}
17-
if (props.unCheckedFilterBy === "XPath" && !props.unCheckedConstraint) {
17+
if (!window.mx.isOffline() && props.unCheckedFilterBy === "XPath" && !props.unCheckedConstraint) {
1818
errorMessages.push("The unchecked 'XPath constraint' is required when 'Filter by' is set to 'XPath'");
1919
}
2020
if (props.unCheckedFilterBy === "attribute" && !props.unCheckedAttribute) {
@@ -24,11 +24,19 @@ export class Validate {
2424
errorMessages.push("The unchecked 'Attribute value' is required when 'Filter by' is set to 'Attribute'");
2525
}
2626
if (!props.isWebModeler) {
27-
if (window.mx.isOffline() && props.filterBy === "XPath") {
28-
errorMessages.push("The checked 'Filter by' 'XPath' is not supported for offline application");
29-
}
30-
if (window.mx.isOffline() && props.unCheckedFilterBy === "XPath") {
31-
errorMessages.push("The unchecked 'Filter by' 'XPath' is not supported for offline application");
27+
if (window.mx.isOffline()) {
28+
if (props.filterBy === "XPath") {
29+
errorMessages.push("The checked 'Filter by' 'XPath' is not supported for offline application");
30+
}
31+
if (props.filterBy === "attribute" && props.attribute.indexOf("/") > -1) {
32+
errorMessages.push(`The checked 'Filter by' 'Attribute' over reference is not supported for offline application`);
33+
}
34+
if (props.unCheckedFilterBy === "XPath") {
35+
errorMessages.push("The unchecked 'Filter by' 'XPath' is not supported for offline application");
36+
}
37+
if (props.unCheckedFilterBy === "attribute" && props.unCheckedAttribute.indexOf("/") > -1) {
38+
errorMessages.push(`The unchecked 'Filter by' 'Attribute' over reference is not supported for offline application`);
39+
}
3240
}
3341
if (!props.mxObject && props.filterBy === "XPath" && props.constraint.indexOf("[%CurrentObject%]'") > -1) {
3442
errorMessages.push("The checked 'XPath constraint', requires a context object");

src/CheckBoxFilter/components/CheckBoxFilterContainer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ContainerProps extends WrapperProps {
2424
unCheckedConstraint: string;
2525
}
2626

27-
type FilterOptions = "attribute" | "XPath" | "None";
27+
type FilterOptions = "attribute" | "XPath" | "none";
2828

2929
export interface ContainerState {
3030
alertMessage: ReactChild;
@@ -203,7 +203,7 @@ export default class CheckboxFilterContainer extends Component<ContainerProps, C
203203
}
204204

205205
this.setState({
206-
alertMessage: errorMessage,
206+
alertMessage: errorMessage || this.state.alertMessage,
207207
listViewAvailable: !!targetListView,
208208
targetListView
209209
});

src/DropDownFilter/Validate.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class Validate {
66
const errorMessages: string[] = [];
77

88
props.filters.forEach((filter, index) => {
9-
if (filter.filterBy === "XPath" && !filter.constraint) {
9+
if (!window.mx.isOffline() && filter.filterBy === "XPath" && !filter.constraint) {
1010
errorMessages.push(`Filter position: {${index + 1 }} is missing XPath constraint`);
1111
}
1212
if (filter.filterBy === "attribute" && !filter.attribute) {
@@ -15,9 +15,18 @@ export class Validate {
1515
if (filter.filterBy === "attribute" && !filter.attributeValue) {
1616
errorMessages.push(`Filter position: {${index + 1 }} 'Attribute value' is required`);
1717
}
18-
if (!props.isWebModeler && filter.filterBy === "XPath" && filter.constraint.indexOf("[%CurrentObject%]'") > -1 && !props.mxObject) {
18+
if (!window.mx.isOffline() && !props.isWebModeler && filter.filterBy === "XPath" && filter.constraint.indexOf("[%CurrentObject%]'") > -1 && !props.mxObject) {
1919
errorMessages.push(`Filter position: {${index + 1 }} is XPath constraint, requires a context object`);
2020
}
21+
if (window.mx.isOffline()) {
22+
if (filter.filterBy === "attribute" && filter.attribute && filter.attribute.indexOf("/") > -1) {
23+
errorMessages.push(`Filter position: {${index + 1 }} 'Attribute' over reference is not supported in offline mode`);
24+
}
25+
if (filter.filterBy === "XPath") {
26+
errorMessages.push(`Filter position: {${index + 1 }}: 'Filter' on 'XPath' is not supported in offline mode`);
27+
}
28+
// The modeler handles 'XPath' offline validation
29+
}
2130
});
2231
if (props.filters.filter(filter => filter.isDefault).length > 1) {
2332
errorMessages.push("Should only have one filter set as default");

src/DropDownFilter/components/DropDownFilterContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default class DropDownFilterContainer extends Component<ContainerProps, C
219219
}
220220

221221
this.setState({
222-
alertMessage: errorMessage,
222+
alertMessage: errorMessage || this.state.alertMessage,
223223
listViewAvailable: !!targetListView,
224224
targetListView
225225
});

src/TextBoxSearch/Validate.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ReactChild, createElement } from "react";
2+
import { ContainerProps } from "./components/TextBoxSearchContainer";
3+
4+
export class Validate {
5+
static validateProps(props: ContainerProps & { isWebModeler?: boolean }): ReactChild {
6+
const errorMessages: string[] = [];
7+
8+
if (window.mx.isOffline()) {
9+
props.attributeList.forEach((searchAttribute, index) => {
10+
if (searchAttribute.attribute.indexOf("/") > -1) {
11+
errorMessages.push(`'Search attribute' at position {${index + 1}} over reference is not supported in offline application`);
12+
}
13+
});
14+
}
15+
16+
if (errorMessages.length) {
17+
return createElement("div", {},
18+
"Configuration error in widget:",
19+
errorMessages.map((message, key) => createElement("p", { key }, message))
20+
);
21+
}
22+
23+
return "";
24+
}
25+
}

src/TextBoxSearch/components/TextBoxSearchContainer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DataSourceHelper } from "../../Shared/DataSourceHelper/DataSourceHelper
77
import { GroupedOfflineConstraint, SharedUtils, WrapperProps } from "../../Shared/SharedUtils";
88

99
import { TextBoxSearch } from "./TextBoxSearch";
10+
import { Validate } from "../Validate";
1011
import { SharedContainerUtils } from "../../Shared/SharedContainerUtils";
1112
import { FormViewState } from "../../Shared/FormViewState";
1213

@@ -22,7 +23,7 @@ export interface SearchAttributes {
2223
}
2324

2425
export interface ContainerState {
25-
alertMessage?: string;
26+
alertMessage?: ReactNode;
2627
listViewAvailable: boolean;
2728
searchText: string;
2829
}
@@ -48,6 +49,7 @@ export default class SearchContainer extends Component<ContainerProps, Container
4849
});
4950

5051
this.state = {
52+
alertMessage: Validate.validateProps(this.props),
5153
searchText: this.getDefaultValue(),
5254
listViewAvailable: false
5355
};
@@ -61,7 +63,6 @@ export default class SearchContainer extends Component<ContainerProps, Container
6163
style: SharedUtils.parseStyle(this.props.style)
6264
},
6365
createElement(Alert, {
64-
bootstrapStyle: "danger",
6566
className: "widget-text-box-search-alert"
6667
}, this.state.alertMessage),
6768
this.renderTextBoxSearch()
@@ -145,7 +146,7 @@ export default class SearchContainer extends Component<ContainerProps, Container
145146
}
146147

147148
private connectToListView() {
148-
let alertMessage = "";
149+
let alertMessage = this.state.alertMessage || "";
149150

150151
try {
151152
this.dataSourceHelper = DataSourceHelper.getInstance(this.widgetDom, this.props.entity);

0 commit comments

Comments
 (0)