fix: apply field name automatically to Apply to Fields in global variable (#7195)
* added referenceField to GlobalVariableModal to show the field that created * Added the display name of the input to global variable modal --------- Co-authored-by: cristhianzl <cristhian.lousa@gmail.com>
This commit is contained in:
parent
67b6ce58e5
commit
ec78119b3a
2 changed files with 18 additions and 2 deletions
|
|
@ -24,6 +24,7 @@ export default function GlobalVariableModal({
|
||||||
children,
|
children,
|
||||||
asChild,
|
asChild,
|
||||||
initialData,
|
initialData,
|
||||||
|
referenceField,
|
||||||
open: myOpen,
|
open: myOpen,
|
||||||
setOpen: mySetOpen,
|
setOpen: mySetOpen,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
|
@ -31,6 +32,7 @@ export default function GlobalVariableModal({
|
||||||
children?: JSX.Element;
|
children?: JSX.Element;
|
||||||
asChild?: boolean;
|
asChild?: boolean;
|
||||||
initialData?: GlobalVariable;
|
initialData?: GlobalVariable;
|
||||||
|
referenceField?: string;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
setOpen?: (a: boolean | ((o?: boolean) => boolean)) => void;
|
setOpen?: (a: boolean | ((o?: boolean) => boolean)) => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
|
@ -61,6 +63,9 @@ export default function GlobalVariableModal({
|
||||||
setAvailableFields(
|
setAvailableFields(
|
||||||
sortByName(fields.concat(initialData?.default_fields ?? [])),
|
sortByName(fields.concat(initialData?.default_fields ?? [])),
|
||||||
);
|
);
|
||||||
|
if (referenceField && fields.includes(referenceField)) {
|
||||||
|
setFields([referenceField]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [globalVariables, componentFields, initialData]);
|
}, [globalVariables, componentFields, initialData]);
|
||||||
|
|
||||||
|
|
@ -106,7 +111,7 @@ export default function GlobalVariableModal({
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitForm() {
|
function submitForm() {
|
||||||
if (!initialData) {
|
if (!initialData || !initialData.id) {
|
||||||
handleSaveVariable();
|
handleSaveVariable();
|
||||||
} else {
|
} else {
|
||||||
updateVariable({
|
updateVariable({
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,18 @@ export default function InputGlobalComponent({
|
||||||
options={globalVariables?.map((variable) => variable.name) ?? []}
|
options={globalVariables?.map((variable) => variable.name) ?? []}
|
||||||
optionsPlaceholder={"Global Variables"}
|
optionsPlaceholder={"Global Variables"}
|
||||||
optionsIcon="Globe"
|
optionsIcon="Globe"
|
||||||
optionsButton={<GeneralGlobalVariableModal />}
|
optionsButton={
|
||||||
|
<GlobalVariableModal referenceField={display_name} disabled={disabled}>
|
||||||
|
<CommandItem value="doNotFilter-addNewVariable">
|
||||||
|
<ForwardedIconComponent
|
||||||
|
name="Plus"
|
||||||
|
className={cn("mr-2 h-4 w-4 text-primary")}
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<span>Add New Variable</span>
|
||||||
|
</CommandItem>
|
||||||
|
</GlobalVariableModal>
|
||||||
|
}
|
||||||
optionButton={(option) => (
|
optionButton={(option) => (
|
||||||
<GeneralDeleteConfirmationModal
|
<GeneralDeleteConfirmationModal
|
||||||
option={option}
|
option={option}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue