-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #696 from near/develop
Off cycle release
- Loading branch information
Showing
5 changed files
with
135 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const { data, onSubmit, onCancel, cancelLabel, entityType, schema } = props; | ||
const capitalize = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : s); | ||
const capitalizedEntityType = capitalize(entityType); | ||
if (!schema || !entityType) { | ||
return <>Missing properties schema or entityType</>; | ||
} | ||
const displayedSchema = Object.keys(schema) | ||
.filter((key) => schema[key]?.displayType !== "hidden") | ||
.reduce((acc, key) => { | ||
if (key) acc[key] = schema[key]; | ||
return acc; | ||
}, {}); | ||
const onSubmitDefault = (formValues) => { | ||
const { name, ...rest } = formValues; | ||
const entity = { [name]: rest }; | ||
Social.set({ [entityType]: entity }, { force: true }); | ||
}; | ||
const onSubmitFunction = onSubmit ?? onSubmitDefault; | ||
|
||
const inputsValidator = (formValues) => | ||
formValues !== null && | ||
typeof formValues === "object" && | ||
!Array.isArray(formValues) && | ||
Object.keys(schema).every((key) => { | ||
const val = schema[key]; | ||
const required = val?.inputProps?.required; | ||
return !required || typeof formValues[key] === "string"; | ||
}); | ||
|
||
const actionType = data ? (data.accountId == context.accountId ? "Edit" : "Fork") : "Create"; | ||
|
||
return ( | ||
<Widget | ||
src="devhub.near/widget/devhub.components.organism.Configurator" | ||
props={{ | ||
heading: `${actionType} ${capitalizedEntityType}`, | ||
fullWidth: true, | ||
isActive: true, | ||
isUnlocked: true, | ||
isValid: inputsValidator, | ||
onSubmit: onSubmitFunction, | ||
schema: displayedSchema, | ||
submitIcon: { | ||
type: "bootstrap_icon", | ||
variant: "bi-rocket-takeoff-fill", | ||
}, | ||
submitLabel: data ? "Save" : "Launch", | ||
onCancel: onCancel, | ||
cancelLabel: cancelLabel, | ||
externalState: data, | ||
}} | ||
/> | ||
); |
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
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