import { Icon, Pill, Switch, Text } from '@src/alchemy-components'; import { ConfirmationModal } from '@src/app/sharedV2/modals/ConfirmationModal'; import { AllowedValue, StructuredPropertyEntity } from '@src/types.generated'; import { Collapse } from 'antd'; import React, { useState } from 'react'; import { useUpdateStructuredPropertyMutation } from '@src/graphql/structuredProperties.generated'; import { CollapseHeader, StyledCollapse, StyledFormItem, TogglesContainer } from './styledComponents'; import { getDisplayName, canBeAssetBadge, StructuredProp } from './utils'; const SCHEMA_FIELD_URN = 'urn:li:entityType:datahub.schemaField'; interface Props { formValues: StructuredProp | undefined; handleDisplaySettingChange: (settingField: string, value: boolean) => void; selectedValueType: string; refetchProperties: () => void; allowedValues?: AllowedValue[]; badgeProperty?: StructuredPropertyEntity; } const DisplayPreferences = ({ formValues, handleDisplaySettingChange, selectedValueType, refetchProperties, allowedValues, badgeProperty, }: Props) => { const [updateProperty] = useUpdateStructuredPropertyMutation(); const [showReplaceBadge, setShowReplaceBadge] = useState(false); const handleReplaceClose = () => { setShowReplaceBadge(false); }; function updateBadgePropertyToOff() { if (badgeProperty) { updateProperty({ variables: { input: { urn: badgeProperty.urn, settings: { showAsAssetBadge: false } } }, }).then(() => refetchProperties()); } } const hasAssetBadgeEnabled = formValues?.settings?.showAsAssetBadge; const showInColumnsTable = formValues?.settings?.showInColumnsTable; const hasColumnEntityType = formValues?.entityTypes?.includes(SCHEMA_FIELD_URN); return ( <> ( )} expandIconPosition="end" defaultActiveKey={[1]} > Display Preferences } forceRender > handleDisplaySettingChange('isHidden', e.target.checked)} labelHoverText="If enabled, this property will be hidden everywhere" data-testid="structured-props-hide-switch" /> handleDisplaySettingChange('showInSearchFilters', e.target.checked)} isDisabled={formValues?.settings?.isHidden} labelHoverText="If enabled, this property will appear in search filters" /> handleDisplaySettingChange('showInAssetSummary', e.target.checked)} isDisabled={formValues?.settings?.isHidden} labelHoverText="If enabled, this property will appear in asset sidebar" /> { if (badgeProperty && e.target.checked) setShowReplaceBadge(true); else handleDisplaySettingChange('showAsAssetBadge', e.target.checked); }} isDisabled={ !hasAssetBadgeEnabled && (formValues?.settings?.isHidden || !canBeAssetBadge(selectedValueType, allowedValues)) } labelHoverText="If enabled, this property will appear as asset badge" disabledHoverText="Only Text or Number property types with allowed values defined can appear as an asset badge." /> handleDisplaySettingChange('showInColumnsTable', e.target.checked)} isDisabled={ !showInColumnsTable && (formValues?.settings?.isHidden || !hasColumnEntityType) } labelHoverText="If enabled, this property will appear as a column in the Columns table for Datasets" disabledHoverText="Property must apply to Columns in order to show in columns table." data-testid="structured-props-show-in-columns-table-switch" /> {badgeProperty && ( { handleDisplaySettingChange('showAsAssetBadge', true); setShowReplaceBadge(false); updateBadgePropertyToOff(); }} confirmButtonText="Update" modalTitle="Update Property" modalText={

Another property  is already being shown on asset previews, but only one property is allowed at a time. Do you want to replace the current property? This will hide PropVal on all asset previews.

} /> )} ); }; export default DisplayPreferences;