forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add configurable field limit to JSONFormWidget (appsmithorg#38856)
- Loading branch information
1 parent
3ab237d
commit ae21fa0
Showing
5 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
ARRAY_ITEM_KEY, | ||
DataType, | ||
FieldType, | ||
MAX_ALLOWED_FIELDS, | ||
ROOT_SCHEMA_KEY, | ||
} from "../constants"; | ||
import schemaTestData from "../schemaTestData"; | ||
|
@@ -469,7 +470,7 @@ describe(".dynamicPropertyPathListFromSchema", () => { | |
}); | ||
|
||
describe(".computeSchema", () => { | ||
it("returns LIMIT_EXCEEDED state when source data exceeds limit", () => { | ||
it("returns LIMIT_EXCEEDED state when source data exceeds default limit", () => { | ||
const sourceData = { | ||
number: 10, | ||
text: "text", | ||
|
@@ -542,6 +543,7 @@ describe(".computeSchema", () => { | |
currSourceData: sourceData, | ||
widgetName: "JSONForm1", | ||
fieldThemeStylesheets: {} as FieldThemeStylesheet, | ||
maxAllowedFields: MAX_ALLOWED_FIELDS, | ||
}); | ||
|
||
expect(response.status).toEqual(ComputedSchemaStatus.LIMIT_EXCEEDED); | ||
|
@@ -556,6 +558,7 @@ describe(".computeSchema", () => { | |
const response = computeSchema({ | ||
currSourceData: sourceData, | ||
widgetName: "JSONForm1", | ||
maxAllowedFields: MAX_ALLOWED_FIELDS, | ||
fieldThemeStylesheets: {} as FieldThemeStylesheet, | ||
}); | ||
|
||
|
@@ -565,6 +568,74 @@ describe(".computeSchema", () => { | |
}); | ||
}); | ||
|
||
it("respects custom maxAllowedFields when higher than default", () => { | ||
const sourceData = { | ||
number: 10, | ||
text: "text", | ||
object1: { | ||
number: 10, | ||
text: "text", | ||
obj: { | ||
arr: { | ||
number: 10, | ||
text: "text", | ||
arr: ["a", "b"], | ||
obj: { | ||
a: 10, | ||
c: 20, | ||
}, | ||
}, | ||
}, | ||
}, | ||
object2: { | ||
number: 10, | ||
text: "text", | ||
obj: { | ||
arr: { | ||
number: 10, | ||
text: "text", | ||
arr: ["a", "b"], | ||
obj: { | ||
a: 10, | ||
c: 20, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const response = computeSchema({ | ||
currSourceData: sourceData, | ||
widgetName: "TestWidget", | ||
maxAllowedFields: 60, | ||
fieldThemeStylesheets: {} as FieldThemeStylesheet, | ||
}); | ||
|
||
expect(response.status).not.toEqual(ComputedSchemaStatus.LIMIT_EXCEEDED); | ||
}); | ||
|
||
it("respects custom maxAllowedFields when lower than default", () => { | ||
const sourceData = { | ||
name: "John", | ||
age: 30, | ||
email: "[email protected]", | ||
address: { | ||
street: "123 Main St", | ||
city: "Springfield", | ||
country: "USA", | ||
}, | ||
}; | ||
|
||
const response = computeSchema({ | ||
currSourceData: sourceData, | ||
widgetName: "TestWidget", | ||
maxAllowedFields: 5, | ||
fieldThemeStylesheets: {} as FieldThemeStylesheet, | ||
}); | ||
|
||
expect(response.status).toEqual(ComputedSchemaStatus.LIMIT_EXCEEDED); | ||
}); | ||
|
||
it("returns UNCHANGED status when prev and curr source data are same", () => { | ||
const currSourceData = { | ||
obj: { | ||
|
@@ -587,6 +658,7 @@ describe(".computeSchema", () => { | |
prevSourceData, | ||
widgetName: "JSONForm1", | ||
fieldThemeStylesheets: {} as FieldThemeStylesheet, | ||
maxAllowedFields: MAX_ALLOWED_FIELDS, | ||
}); | ||
|
||
expect(response.status).toEqual(ComputedSchemaStatus.UNCHANGED); | ||
|
@@ -599,6 +671,7 @@ describe(".computeSchema", () => { | |
currSourceData: schemaTestData.initialDataset.dataSource, | ||
widgetName: "JSONForm1", | ||
fieldThemeStylesheets: schemaTestData.fieldThemeStylesheets, | ||
maxAllowedFields: MAX_ALLOWED_FIELDS, | ||
}); | ||
|
||
const expectedDynamicPropertyPathList = [ | ||
|
@@ -630,6 +703,7 @@ describe(".computeSchema", () => { | |
currSourceData: schemaTestData.initialDataset.dataSource, | ||
currentDynamicPropertyPathList: existingDynamicBindingPropertyPathList, | ||
widgetName: "JSONForm1", | ||
maxAllowedFields: MAX_ALLOWED_FIELDS, | ||
fieldThemeStylesheets: schemaTestData.fieldThemeStylesheets, | ||
}); | ||
|
||
|
@@ -659,6 +733,7 @@ describe(".computeSchema", () => { | |
currentDynamicPropertyPathList: existingDynamicBindingPropertyPathList, | ||
widgetName: "JSONForm1", | ||
fieldThemeStylesheets: schemaTestData.fieldThemeStylesheets, | ||
maxAllowedFields: MAX_ALLOWED_FIELDS, | ||
}); | ||
|
||
expect(response.status).toEqual(ComputedSchemaStatus.UPDATED); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters