-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move store setup to standalone function (#4799)
move store setup to standalone function
- Loading branch information
Showing
2 changed files
with
52 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,49 @@ | ||
import { TemplateStoreProps, InitialTemplateStoreProps } from "./types"; | ||
import { Language } from "../types/form-builder-types"; | ||
import { defaultForm } from "./defaults"; | ||
import { initializeGroups } from "@formBuilder/components/shared/right-panel/treeview/util/initializeGroups"; | ||
import { orderGroups } from "@lib/utils/form-builder/orderUsingGroupsLayout"; | ||
|
||
export const initStore = (initProps?: Partial<InitialTemplateStoreProps>) => { | ||
const DEFAULT_PROPS: TemplateStoreProps = { | ||
id: "", | ||
lang: (initProps?.locale as Language) || "en", | ||
translationLanguagePriority: (initProps?.locale as Language) || "en", | ||
focusInput: false, | ||
hasHydrated: false, | ||
form: defaultForm, | ||
isPublished: false, | ||
name: "", | ||
securityAttribute: "Protected A", | ||
formPurpose: "", | ||
publishReason: "", | ||
publishFormType: "", | ||
publishDesc: "", | ||
closingDate: initProps?.closingDate, | ||
changeKey: String(new Date().getTime()), | ||
allowGroupsFlag: initProps?.allowGroupsFlag || false, | ||
}; | ||
|
||
// Ensure any required properties by Form Builder are defaulted by defaultForm | ||
if (initProps?.form) { | ||
initProps.form = { | ||
...defaultForm, | ||
...initProps?.form, | ||
}; | ||
|
||
initProps.form = initializeGroups(initProps.form, initProps?.allowGroupsFlag || false); | ||
|
||
// Ensure order by groups layout | ||
if (!initProps.form.groupsLayout) { | ||
/* No need to order as the groups layout does not exist */ | ||
initProps.form.groupsLayout = []; | ||
} else { | ||
initProps.form.groups = orderGroups(initProps.form.groups, initProps.form.groupsLayout); | ||
} | ||
} | ||
|
||
return { | ||
...DEFAULT_PROPS, | ||
...initProps, | ||
}; | ||
}; |
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