diff --git a/openmetadata-ui-core-components/src/main/resources/ui/src/components/application/file-upload/file-upload.tsx b/openmetadata-ui-core-components/src/main/resources/ui/src/components/application/file-upload/file-upload.tsx index d7221354fa1a..674b9674ce74 100644 --- a/openmetadata-ui-core-components/src/main/resources/ui/src/components/application/file-upload/file-upload.tsx +++ b/openmetadata-ui-core-components/src/main/resources/ui/src/components/application/file-upload/file-upload.tsx @@ -21,8 +21,6 @@ import { ProgressBar } from '@/components/base/progress-indicators/progress-indi import { FeaturedIcon } from '@/components/foundations/featured-icon/featured-icon'; import { cx } from '@/utils/cx'; import { FileIcon as FileTypeIcon } from '@untitledui/file-icons'; - -export { FileIcon } from '@untitledui/file-icons'; import { CheckCircle, Trash01, @@ -37,6 +35,8 @@ import type { } from 'react'; import { useId, useRef, useState } from 'react'; +export { FileIcon } from '@untitledui/file-icons'; + export const getReadableFileSize = (bytes: number): string => { if (bytes === 0) { return '0 KB'; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/ContextCenterHeader/ContextCenterHeader.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/ContextCenterHeader/ContextCenterHeader.component.tsx index fc08127e4410..6f5cac9e3709 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/ContextCenterHeader/ContextCenterHeader.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/ContextCenterHeader/ContextCenterHeader.component.tsx @@ -28,6 +28,7 @@ const ContextCenterHeader: FC = ({ breadcrumbs, title, subtitle, + className = '', hasPermission = true, onCreateArticle, onUploadFile, @@ -76,7 +77,7 @@ const ContextCenterHeader: FC = ({ /> )} - + {breadcrumbInsideCard && (
void; onUploadFile?: () => void; /** Replaces the default action buttons with a custom slot */ diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/CreateMemoryModal/CreateMemoryModal.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/CreateMemoryModal/CreateMemoryModal.component.tsx index f9598feeaa38..7e6d562b34ea 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/CreateMemoryModal/CreateMemoryModal.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/CreateMemoryModal/CreateMemoryModal.component.tsx @@ -11,6 +11,7 @@ * limitations under the License. */ import { + Alert, Badge, BadgeWithButton, Button, @@ -25,22 +26,36 @@ import { TextArea, Typography, } from '@openmetadata/ui-core-components'; -import { Lightbulb03, Plus, Share07, Trash01, X } from '@untitledui/icons'; +import { + Database01, + Edit01, + FileLock02, + Lightbulb03, + Lock01, + Plus, + Share07, + Trash01, + X, +} from '@untitledui/icons'; import { ConfigProvider } from 'antd'; import { DefaultOptionType } from 'antd/lib/select'; import { AxiosError } from 'axios'; import { compare } from 'fast-json-patch'; -import { FC, useCallback, useEffect, useRef, useState } from 'react'; +import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import UserPopOverCard from '../../../components/common/PopOverCard/UserPopOverCard'; import { DataAssetOption } from '../../../components/DataAssets/DataAssetAsyncSelectList/DataAssetAsyncSelectList.interface'; import DataAssetSelectList from '../../../components/DataAssets/DataAssetAsyncSelectList/DataAssetSelectList'; import TagSelectForm from '../../../components/Tag/TagsSelectForm/TagsSelectForm.component'; -import { MEMORY_TYPE_OPTIONS } from '../../../constants/ContextCenter.constants'; +import { + MEMORY_TYPE_OPTIONS, + VISIBILITY_OPTIONS, +} from '../../../constants/ContextCenter.constants'; import { SearchIndex } from '../../../enums/search.enum'; import { LabelType, MemoryType, + ShareVisibility, State, TagLabel, TagSource, @@ -50,10 +65,14 @@ import { deleteContextMemory, updateContextMemory, } from '../../../rest/contextMemoryAPI'; -import { formatDate } from '../../../utils/date-time/DateTimeUtils'; +import { + formatDate, + getShortRelativeTime, +} from '../../../utils/date-time/DateTimeUtils'; import searchClassBase from '../../../utils/SearchClassBase'; +import { getErrorText } from '../../../utils/StringsUtils'; import tagClassBase from '../../../utils/TagClassBase'; -import { showErrorToast, showSuccessToast } from '../../../utils/ToastUtils'; +import { showSuccessToast } from '../../../utils/ToastUtils'; import { CreateMemoryModalProps } from './CreateMemoryModal.interface'; const LinkedAssetCard: FC<{ @@ -136,6 +155,12 @@ const LinkedAssetsReadOnly: FC<{ assets: DataAssetOption[] }> = ({ ); }; +const VISIBILITY_ICON_MAP = { + Share07: , + Database01: , + FileLock02: , +}; + const CreateMemoryModal: FC = ({ memoryToEdit, isOpen, @@ -144,15 +169,18 @@ const CreateMemoryModal: FC = ({ onUpdated, onDeleted, viewOnly = false, + canDelete = false, + currentUserName, }) => { const { t } = useTranslation(); const modalContainerRef = useRef(null); - const isEditMode = Boolean(memoryToEdit) && !viewOnly; + const [isViewOnly, setIsViewOnly] = useState(viewOnly); + const isEditMode = Boolean(memoryToEdit) && !isViewOnly; let modalTitle = t('label.add-entity', { entity: t('label.memory') }); if (isEditMode) { modalTitle = t('label.edit-entity', { entity: t('label.memory') }); - } else if (viewOnly) { + } else if (isViewOnly) { modalTitle = memoryToEdit?.title || t('label.edit-entity', { entity: t('label.memory') }); @@ -165,19 +193,35 @@ const CreateMemoryModal: FC = ({ const [title, setTitle] = useState(''); const [memory, setMemory] = useState(''); const [memoryType, setMemoryType] = useState(''); + const [visibility, setVisibility] = useState( + ShareVisibility.Shared + ); + const [isEditingVisibility, setIsEditingVisibility] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [isDeleting, setIsDeleting] = useState(false); + const [modalError, setModalError] = useState(''); const [linkedAssets, setLinkedAssets] = useState([]); - const [selectedTags, setSelectedTags] = useState([]); const [showTagForm, setShowTagForm] = useState(false); + const isOwner = useMemo( + () => + memoryToEdit?.owners?.some((owner) => owner.name === currentUserName) ?? + false, + [memoryToEdit, currentUserName] + ); + + useEffect(() => { + setIsViewOnly(viewOnly); + }, [viewOnly]); + useEffect(() => { if (memoryToEdit) { setTitle(memoryToEdit.title ?? ''); setMemory(memoryToEdit.answer || memoryToEdit.question); setMemoryType(memoryToEdit.memoryType ?? ''); + setVisibility(memoryToEdit.visibility ?? ShareVisibility.Shared); setSelectedTags(memoryToEdit.tags ?? []); const assetOptions: DataAssetOption[] = ( memoryToEdit.relatedEntities ?? [] @@ -192,19 +236,26 @@ const CreateMemoryModal: FC = ({ setTitle(''); setMemory(''); setMemoryType(''); + setVisibility(ShareVisibility.Shared); setSelectedTags([]); setLinkedAssets([]); } setShowTagForm(false); + setModalError(''); + setIsEditingVisibility(false); }, [memoryToEdit]); const handleClose = () => { setTitle(''); setMemory(''); setMemoryType(''); + setVisibility(ShareVisibility.Shared); setLinkedAssets([]); setSelectedTags([]); setShowTagForm(false); + setModalError(''); + setIsEditingVisibility(false); + setIsViewOnly(viewOnly); onClose(); }; @@ -250,6 +301,7 @@ const CreateMemoryModal: FC = ({ } setIsSubmitting(true); + setModalError(''); try { const relatedEntities = linkedAssets .filter((a) => a.reference?.id && a.reference?.type) @@ -271,6 +323,7 @@ const CreateMemoryModal: FC = ({ displayName: r.displayName, fullyQualifiedName: r.fullyQualifiedName, })); + const hasExistingShareConfig = memoryToEdit.visibility !== undefined; const original = { title: memoryToEdit.title ?? '', summary: memoryToEdit.summary ?? '', @@ -279,6 +332,9 @@ const CreateMemoryModal: FC = ({ memoryType: memoryToEdit.memoryType, tags: memoryToEdit.tags ?? [], relatedEntities: originalRelatedEntities, + ...(hasExistingShareConfig + ? { shareConfig: { visibility: memoryToEdit.visibility } } + : {}), }; const updated = { title: title.trim(), @@ -288,11 +344,14 @@ const CreateMemoryModal: FC = ({ memoryType: memoryType || undefined, tags: selectedTags, relatedEntities, + ...(hasExistingShareConfig || visibility !== ShareVisibility.Shared + ? { shareConfig: { visibility } } + : {}), }; const patch = compare(original, updated); await updateContextMemory(memoryToEdit.id, patch); showSuccessToast( - t('server.entity-updated-successfully', { entity: t('label.memory') }) + t('server.entity-updated-success', { entity: t('label.memory') }) ); onUpdated?.(); } else { @@ -309,6 +368,7 @@ const CreateMemoryModal: FC = ({ ...(memoryType ? { memoryType } : {}), ...(selectedTags.length > 0 ? { tags: selectedTags } : {}), ...(relatedEntities.length > 0 ? { relatedEntities } : {}), + shareConfig: { visibility }, }); showSuccessToast( @@ -318,7 +378,9 @@ const CreateMemoryModal: FC = ({ } handleClose(); } catch (err) { - showErrorToast(err as AxiosError); + setModalError( + getErrorText(err as AxiosError, t('server.unexpected-error')) + ); } finally { setIsSubmitting(false); } @@ -329,6 +391,7 @@ const CreateMemoryModal: FC = ({ return; } setIsDeleting(true); + setModalError(''); try { await deleteContextMemory(memoryToEdit.id); showSuccessToast( @@ -337,12 +400,20 @@ const CreateMemoryModal: FC = ({ onDeleted?.(); handleClose(); } catch (err) { - showErrorToast(err as AxiosError); + setModalError( + getErrorText(err as AxiosError, t('server.unexpected-error')) + ); } finally { setIsDeleting(false); } }; + const handleSwitchToEdit = () => { + setIsViewOnly(false); + }; + + const visibilityOption = VISIBILITY_OPTIONS.find((o) => o.id === visibility); + return ( = ({ {/* Scrollable body */}
+ {/* Read-only banner for non-owners */} + {isViewOnly && !isOwner && !canDelete && memoryToEdit && ( +
+ +
+ + {t('label.cant-edit-this-memory')} + + + {t('message.context-memory-read-only-description', { + creatorName: + memoryToEdit.owners?.[0]?.name ?? + memoryToEdit.updatedBy, + })} + +
+
+ )} + + {/* Inline error alert */} + {modalError && ( + setModalError('')} + /> + )} + {/* Section 1: Title */}
= ({ size="text-sm" weight="medium"> {t('label.memory')} - {!viewOnly && ( + {!isViewOnly && ( * )} - {!viewOnly && ( + {!isViewOnly && ( {t('message.what-should-ask-collate-remember')} @@ -433,7 +543,7 @@ const CreateMemoryModal: FC = ({