feat: add Url field preview in settings (#2402)
* feat: add Url field preview in settings Closes #2326 * feat: add Date field type in settings (#2414) Closes #2331
This commit is contained in:
@ -50,7 +50,7 @@ export const URLV2Display = ({ value }: URLV2DisplayProps) => {
|
||||
: 'https://' + value.link
|
||||
: '';
|
||||
|
||||
const displayedValue = value?.text ?? '';
|
||||
const displayedValue = value?.text || value?.link || '';
|
||||
|
||||
const type = checkUrlType(absoluteUrl);
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import { usePersistField } from '../../hooks/usePersistField';
|
||||
import { entityFieldsFamilySelector } from '../../states/selectors/entityFieldsFamilySelector';
|
||||
import { assertFieldMetadata } from '../../types/guards/assertFieldMetadata';
|
||||
import { isFieldURL } from '../../types/guards/isFieldURL';
|
||||
import { isFieldURLValue } from '../../types/guards/isFieldURLValue';
|
||||
|
||||
export const useURLField = () => {
|
||||
const { entityId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
||||
@ -23,12 +24,13 @@ export const useURLField = () => {
|
||||
fieldName: fieldName,
|
||||
}),
|
||||
);
|
||||
const fieldUrlValue = isFieldURLValue(fieldValue) ? fieldValue : '';
|
||||
|
||||
const fieldInitialValue = useFieldInitialValue();
|
||||
|
||||
const initialValue = fieldInitialValue?.isEmpty
|
||||
? ''
|
||||
: fieldInitialValue?.value ?? fieldValue;
|
||||
: fieldInitialValue?.value ?? fieldUrlValue;
|
||||
|
||||
const persistField = usePersistField();
|
||||
|
||||
@ -42,7 +44,7 @@ export const useURLField = () => {
|
||||
|
||||
return {
|
||||
fieldDefinition,
|
||||
fieldValue,
|
||||
fieldValue: fieldUrlValue,
|
||||
initialValue,
|
||||
setFieldValue,
|
||||
hotkeyScope,
|
||||
|
||||
@ -28,7 +28,9 @@ export const useURLV2Field = () => {
|
||||
|
||||
const initialValue: FieldURLV2Value = fieldInitialValue?.isEmpty
|
||||
? { link: '', text: '' }
|
||||
: { link: fieldInitialValue?.value ?? '', text: '' } ?? fieldValue;
|
||||
: fieldInitialValue?.value
|
||||
? { link: fieldInitialValue.value, text: '' }
|
||||
: fieldValue;
|
||||
|
||||
const persistField = usePersistField();
|
||||
|
||||
|
||||
@ -19,6 +19,8 @@ import { isFieldRelation } from '../../types/guards/isFieldRelation';
|
||||
import { isFieldRelationValue } from '../../types/guards/isFieldRelationValue';
|
||||
import { isFieldText } from '../../types/guards/isFieldText';
|
||||
import { isFieldURL } from '../../types/guards/isFieldURL';
|
||||
import { isFieldURLV2 } from '../../types/guards/isFieldURLV2';
|
||||
import { isFieldURLV2Value } from '../../types/guards/isFieldURLV2Value';
|
||||
import { entityFieldsFamilyState } from '../entityFieldsFamilyState';
|
||||
|
||||
const isValueEmpty = (value: unknown) => !assertNotNull(value) || value === '';
|
||||
@ -104,6 +106,13 @@ export const isEntityFieldEmptyFamilySelector = selectorFamily({
|
||||
);
|
||||
}
|
||||
|
||||
if (isFieldURLV2(fieldDefinition)) {
|
||||
const fieldName = fieldDefinition.metadata.fieldName;
|
||||
const fieldValue = get(entityFieldsFamilyState(entityId))?.[fieldName];
|
||||
|
||||
return !isFieldURLV2Value(fieldValue) || isValueEmpty(fieldValue?.link);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Entity field type not supported in isEntityFieldEmptyFamilySelector : ${fieldDefinition.type}}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user