-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- only primary links for now - need for a global strat for validation. This will come later
- Loading branch information
Showing
4 changed files
with
103 additions
and
4 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
6 changes: 3 additions & 3 deletions
6
...nt/src/modules/object-record/record-field/form-types/components/FormAddressFieldInput.tsx
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
58 changes: 58 additions & 0 deletions
58
...ront/src/modules/object-record/record-field/form-types/components/FormLinksFieldInput.tsx
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,58 @@ | ||
import { FormFieldInputContainer } from '@/object-record/record-field/form-types/components/FormFieldInputContainer'; | ||
import { FormNestedFieldInputContainer } from '@/object-record/record-field/form-types/components/FormNestedFieldInputContainer'; | ||
import { FormTextFieldInput } from '@/object-record/record-field/form-types/components/FormTextFieldInput'; | ||
import { VariablePickerComponent } from '@/object-record/record-field/form-types/types/VariablePickerComponent'; | ||
import { FieldLinksDraftValue } from '@/object-record/record-field/types/FieldInputDraftValue'; | ||
import { FieldLinksValue } from '@/object-record/record-field/types/FieldMetadata'; | ||
import { InputLabel } from '@/ui/input/components/InputLabel'; | ||
|
||
type FormLinksFieldInputProps = { | ||
label?: string; | ||
defaultValue?: FieldLinksValue; | ||
onPersist: (value: FieldLinksValue) => void; | ||
VariablePicker?: VariablePickerComponent; | ||
readonly?: boolean; | ||
}; | ||
|
||
export const FormLinksFieldInput = ({ | ||
label, | ||
defaultValue, | ||
onPersist, | ||
readonly, | ||
VariablePicker, | ||
}: FormLinksFieldInputProps) => { | ||
const handleChange = | ||
(field: keyof FieldLinksDraftValue) => (updatedLinksPart: string) => { | ||
const updatedLinks = { | ||
primaryLinkLabel: defaultValue?.primaryLinkLabel ?? '', | ||
primaryLinkUrl: defaultValue?.primaryLinkUrl ?? '', | ||
[field]: updatedLinksPart, | ||
}; | ||
// We need to validate the links and display an error message if the links are not valid | ||
onPersist(updatedLinks); | ||
}; | ||
|
||
return ( | ||
<FormFieldInputContainer> | ||
{label ? <InputLabel>{label}</InputLabel> : null} | ||
<FormNestedFieldInputContainer> | ||
<FormTextFieldInput | ||
label="Primary Link Label" | ||
defaultValue={defaultValue?.primaryLinkLabel} | ||
onPersist={handleChange('primaryLinkLabel')} | ||
placeholder={'Primary Link Label'} | ||
readonly={readonly} | ||
VariablePicker={VariablePicker} | ||
/> | ||
<FormTextFieldInput | ||
label="Primary Link URL" | ||
defaultValue={defaultValue?.primaryLinkUrl} | ||
onPersist={handleChange('primaryLinkUrl')} | ||
placeholder={'Primary Link URL'} | ||
readonly={readonly} | ||
VariablePicker={VariablePicker} | ||
/> | ||
</FormNestedFieldInputContainer> | ||
</FormFieldInputContainer> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
...ect-record/record-field/form-types/components/__stories__/FormLinksFieldInput.stories.tsx
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,31 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { within } from '@storybook/test'; | ||
import { FormLinksFieldInput } from '../FormLinksFieldInput'; | ||
|
||
const meta: Meta<typeof FormLinksFieldInput> = { | ||
title: 'UI/Data/Field/Form/Input/FormLinksFieldInput', | ||
component: FormLinksFieldInput, | ||
args: {}, | ||
argTypes: {}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof FormLinksFieldInput>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
label: 'Domain Name', | ||
defaultValue: { | ||
primaryLinkLabel: 'Google', | ||
primaryLinkUrl: 'https://www.google.com', | ||
}, | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
await canvas.findByText('Domain Name'); | ||
await canvas.findByText('Primary Link Label'); | ||
await canvas.findByText('Google'); | ||
}, | ||
}; |