-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
22 changed files
with
345 additions
and
857 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/components/documentBuilder/edit/DocumentOptions.module.scss
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from "react"; | ||
import { | ||
type SelectStringOption, | ||
type SetActiveField, | ||
} from "@/components/formBuilder/formBuilderTypes"; | ||
import FieldEditor from "./FieldEditor"; | ||
import { | ||
moveStringInArray, | ||
getNormalizedUiOrder, | ||
} from "@/components/formBuilder/formBuilderHelpers"; | ||
import { type Schema } from "@/types/schemaTypes"; | ||
import FieldTemplate from "@/components/form/FieldTemplate"; | ||
import LayoutWidget from "@/components/LayoutWidget"; | ||
import { findLast } from "lodash"; | ||
|
||
export const ActiveField: React.FC<{ | ||
name: string; | ||
activeField: string; | ||
setActiveField: SetActiveField; | ||
fieldTypes: SelectStringOption[]; | ||
schema: Schema; | ||
uiOrder: string[]; | ||
propertyKeys: string[]; | ||
setUiOrder: (uiOrder: string[]) => Promise<void | string[]>; | ||
}> = ({ | ||
name, | ||
activeField, | ||
setActiveField, | ||
fieldTypes, | ||
schema, | ||
uiOrder, | ||
propertyKeys, | ||
setUiOrder, | ||
}) => { | ||
const moveProperty = async (direction: "up" | "down") => { | ||
const nextUiOrder = moveStringInArray( | ||
getNormalizedUiOrder(propertyKeys, uiOrder), | ||
activeField, | ||
direction, | ||
); | ||
await setUiOrder(nextUiOrder); | ||
}; | ||
|
||
// The uiOrder field may not be initialized yet | ||
const order = uiOrder ?? ["*"]; | ||
const canMoveUp = | ||
order.length > 2 | ||
? order[0] !== activeField | ||
: propertyKeys[0] !== activeField; | ||
const canMoveDown = | ||
order.length === propertyKeys.length + 1 | ||
? order.at(-2) !== activeField | ||
: Array.isArray(order) && | ||
findLast(propertyKeys, (key) => !order.includes(key)) !== activeField; | ||
|
||
return ( | ||
<> | ||
<h6>Current Field</h6> | ||
|
||
{Boolean(schema?.properties?.[activeField]) && ( | ||
<FieldEditor | ||
name={name} | ||
propertyName={activeField} | ||
setActiveField={setActiveField} | ||
fieldTypes={fieldTypes} | ||
/> | ||
)} | ||
|
||
{(canMoveUp || canMoveDown) && ( | ||
<FieldTemplate | ||
name="layoutButtons" | ||
label="Field Order" | ||
as={LayoutWidget} | ||
canMoveUp={canMoveUp} | ||
moveUp={async () => { | ||
await moveProperty("up"); | ||
}} | ||
canMoveDown={canMoveDown} | ||
moveDown={async () => { | ||
await moveProperty("down"); | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.