@box/metadata-template-editor 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/metadata-template-editor-modal.js +1 -1
- package/dist/chunks/metadata-template-editor.js +1 -1
- package/dist/esm/lib/components/unsaved-changes-modal/unsaved-changes-modal.js +1 -0
- package/dist/esm/lib/messages.js +1 -1
- package/dist/types/lib/components/metadata-template-editor-modal/index.d.ts +1 -1
- package/dist/types/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.d.ts +17 -10
- package/dist/types/lib/components/unsaved-changes-modal/unsaved-changes-modal.d.ts +12 -0
- package/dist/types/lib/messages.d.ts +5 -0
- package/dist/types/lib/metadata-template-editor.d.ts +1 -28
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as MetadataTemplateEditorMode}from"./types.js";import messages_default from"../esm/lib/messages.js";import{t as MetadataTemplateEditor}from"./metadata-template-editor.js";import{Modal}from"@box/blueprint-web";import{useIntl}from"react-intl";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import{
|
|
1
|
+
import{s as MetadataTemplateEditorMode}from"./types.js";import messages_default from"../esm/lib/messages.js";import{UnsavedChangesModal}from"../esm/lib/components/unsaved-changes-modal/unsaved-changes-modal.js";import{t as MetadataTemplateEditor}from"./metadata-template-editor.js";import{IconButton,Modal}from"@box/blueprint-web";import{useIntl}from"react-intl";import{ChevronLeft}from"@box/blueprint-web-assets/icons/Medium";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import{useEffect,useId,useState}from"react";import clsx from"clsx";import '../styles/metadata-template-editor-modal.css';var metadata_template_editor_modal_module_default={modal:`_modal_7kuew_1`,modalScrollableContainer:`_modalScrollableContainer_7kuew_6`,modalBody:`_modalBody_7kuew_12`,modalBodyCentered:`_modalBodyCentered_7kuew_20`,modalContentWidth:`_modalContentWidth_7kuew_25`};function MetadataTemplateEditorModal({open,onOpenChange,onTemplateLoad,onValidationChange,onCancel,onBack,title,...editorProps}){let intl=useIntl(),formId=useId(),[isSubmitting,setIsSubmitting]=useState(!1),[isDirty,setIsDirty]=useState(!1),[loadedTemplateName,setLoadedTemplateName]=useState(void 0),[pendingClose,setPendingClose]=useState(null),isEditMode=editorProps.mode===MetadataTemplateEditorMode.Edit,isReadOnlyMode=editorProps.mode===MetadataTemplateEditorMode.ReadOnly,close=intent=>{intent===`back`?onBack?.():onCancel?.(),onOpenChange(!1)},attemptClose=intent=>{isDirty?setPendingClose(intent):close(intent)};useEffect(()=>{open||(setIsDirty(!1),setLoadedTemplateName(void 0),setPendingClose(null))},[open]);let handleOpenChange=newOpen=>{isSubmitting||(newOpen?onOpenChange(newOpen):attemptClose(`dismiss`))},handleTemplateLoad=template=>{setLoadedTemplateName(template.displayName),onTemplateLoad?.(template)},wrapSubmit=callback=>async(...args)=>{setIsSubmitting(!0);try{await callback(...args),onOpenChange(!1)}finally{setIsSubmitting(!1)}},wrappedEditorProps;wrappedEditorProps=isEditMode?{...editorProps,onEditTemplate:wrapSubmit(editorProps.onEditTemplate)}:isReadOnlyMode?editorProps:{...editorProps,onCreateTemplate:wrapSubmit(editorProps.onCreateTemplate)};let isSaveDisabled=isSubmitting||isEditMode&&!isDirty,isBodyCentered=(isEditMode||isReadOnlyMode)&&!loadedTemplateName,defaultTitle;defaultTitle=isReadOnlyMode?loadedTemplateName?intl.formatMessage(messages_default.viewTitle,{templateName:loadedTemplateName}):``:isEditMode&&loadedTemplateName?intl.formatMessage(messages_default.editTitle,{templateName:loadedTemplateName}):intl.formatMessage(messages_default.createTitle);let modalTitle=title??defaultTitle;return jsx(Modal,{open,onOpenChange:handleOpenChange,children:jsxs(Modal.Content,{size:`large`,className:metadata_template_editor_modal_module_default.modal,children:[jsx(Modal.Header,{backButton:onBack?jsx(IconButton,{"aria-label":intl.formatMessage(messages_default.backAriaLabel),icon:ChevronLeft,onClick:()=>attemptClose(`back`),disabled:isSubmitting}):void 0,children:modalTitle}),jsx(Modal.ScrollableContainer,{className:metadata_template_editor_modal_module_default.modalScrollableContainer,children:jsxs(Modal.Body,{className:clsx(metadata_template_editor_modal_module_default.modalBody,{[metadata_template_editor_modal_module_default.modalBodyCentered]:isBodyCentered}),children:[jsx(`div`,{className:metadata_template_editor_modal_module_default.modalContentWidth,children:jsx(MetadataTemplateEditor,{...wrappedEditorProps,formId,hideActions:!0,onDirtyStateChange:setIsDirty,onValidationChange,onTemplateLoad:handleTemplateLoad})}),pendingClose&&jsx(UnsavedChangesModal,{onKeepEditing:()=>setPendingClose(null),onDiscard:()=>{setPendingClose(null),close(pendingClose)}})]})}),jsx(Modal.Footer,{children:isReadOnlyMode?jsx(Modal.Footer.PrimaryButton,{onClick:()=>attemptClose(`dismiss`),size:`large`,children:intl.formatMessage(messages_default.close)}):jsxs(Fragment,{children:[jsx(Modal.Footer.SecondaryButton,{onClick:()=>attemptClose(`dismiss`),size:`large`,disabled:isSubmitting,children:intl.formatMessage(messages_default.cancel)}),jsx(Modal.Footer.PrimaryButton,{variant:`primary`,type:`submit`,form:formId,loading:isSubmitting,loadingAriaLabel:intl.formatMessage(messages_default.submitting),disabled:isSaveDisabled,children:intl.formatMessage(messages_default.save)})]})}),jsx(Modal.Close,{"aria-label":intl.formatMessage(messages_default.closeAriaLabel),disabled:isSubmitting})]})})}export{MetadataTemplateEditorModal as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as MetadataTemplateEditorMode}from"./types.js";import{EditorConfigContext}from"../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";import"../esm/lib/utils/constants.js";import
|
|
1
|
+
import{s as MetadataTemplateEditorMode}from"./types.js";import{EditorConfigContext}from"../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";import"../esm/lib/utils/constants.js";import messages_default from"../esm/lib/messages.js";import{t as MetadataTemplateEditorForm}from"./metadata-template-editor-form.js";import{UnsavedChangesModal}from"../esm/lib/components/unsaved-changes-modal/unsaved-changes-modal.js";import{useMetadataTemplateFormSchema}from"../esm/lib/hooks/useMetadataTemplateFormSchema.js";import{convertApiMetadataTemplateFieldToLocalConfiguratorField}from"../esm/lib/utils/template-type-conversion/convertTemplateFieldToLocalConfigurator.js";import{generateJSONPatchTemplateOperations}from"../esm/lib/utils/template-type-conversion/generateJSONPatchTemplateOperations.js";import{mapFieldsWithUniqueKeys}from"../esm/lib/utils/template-type-conversion/mapFieldsWithUniqueKeys.js";import{EmptyState,LoadingIndicator,Text,useNotification}from"@box/blueprint-web";import{useIntl}from"react-intl";import{jsx,jsxs}from"react/jsx-runtime";import{useCallback,useEffect,useMemo,useState}from"react";import{ArrowsRotating}from"@box/blueprint-web-assets/icons/Line";import{ErrorState404}from"@box/blueprint-web-assets/illustrations/Medium";import{Formik}from"formik";import '../styles/metadata-template-editor.css';var metadata_template_editor_module_default={loading:`_loading_fd3t9_1`,error:`_error_fd3t9_8`},DEFAULT_VALUES={displayName:``,templateKey:``,fields:[],hidden:!1};function MetadataTemplateEditor({onCancel,onDirtyStateChange,onValidationChange,onSubmitError,onTemplateLoad,taxonomyOptions,fetchTaxonomies,fetchTaxonomyByKey,disabledFieldTypes,taxonomyInitialStateLabels,formId,hideActions=!1,isVisibilityToggleAllowed=!1,fieldExtensions,...modeProps}){let schema=useMetadataTemplateFormSchema(),{formatMessage}=useIntl(),{addNotification}=useNotification(),isEditMode=modeProps.mode===MetadataTemplateEditorMode.Edit,isReadOnlyMode=modeProps.mode===MetadataTemplateEditorMode.ReadOnly,[isDirty,setIsDirty]=useState(!1),[isUnsavedChangesModalOpen,setIsUnsavedChangesModalOpen]=useState(!1),handleCancel=useCallback(()=>{isDirty?setIsUnsavedChangesModalOpen(!0):onCancel?.()},[isDirty,onCancel]),handleDirtyStateChange=useCallback(dirty=>{setIsDirty(dirty),onDirtyStateChange?.(dirty)},[onDirtyStateChange]),[isLoading,setIsLoading]=useState(isEditMode||isReadOnlyMode),[hasFetchError,setHasFetchError]=useState(!1),[retryCount,setRetryCount]=useState(0),[fetchedValues,setFetchedValues]=useState(void 0),fetchTemplate=isEditMode||isReadOnlyMode?modeProps.fetchTemplate:void 0,handleRetry=()=>{setRetryCount(c=>c+1)};useEffect(()=>{if(!fetchTemplate)return;let cancelled=!1;return setIsLoading(!0),setHasFetchError(!1),setFetchedValues(void 0),(async()=>{try{let response=await fetchTemplate();cancelled||setFetchedValues(response)}catch{cancelled||setHasFetchError(!0)}finally{cancelled||setIsLoading(!1)}})(),()=>{cancelled=!0}},[fetchTemplate,retryCount]),useEffect(()=>{fetchedValues!==void 0&&onTemplateLoad?.(fetchedValues)},[fetchedValues,onTemplateLoad]);let createNamespace=isEditMode||isReadOnlyMode?void 0:modeProps.namespace,mergedInitialValues=useMemo(()=>fetchedValues?{displayName:fetchedValues.displayName,templateKey:fetchedValues.templateKey,namespace:fetchedValues.namespace,hidden:fetchedValues.hidden,fields:fetchedValues.fields.map(field=>convertApiMetadataTemplateFieldToLocalConfiguratorField(field))}:{...DEFAULT_VALUES,namespace:createNamespace??``},[fetchedValues,createNamespace]),editorConfigValue=useMemo(()=>({disabledFieldTypes,taxonomyInitialStateLabels}),[disabledFieldTypes,taxonomyInitialStateLabels]);return isLoading?jsx(`div`,{className:metadata_template_editor_module_default.loading,children:jsx(LoadingIndicator,{size:`large`,"aria-label":formatMessage(messages_default.loading)})}):hasFetchError?jsx(`div`,{className:metadata_template_editor_module_default.error,children:jsx(EmptyState,{body:jsx(Text,{as:`p`,children:formatMessage(messages_default.fetchError)}),illustration:ErrorState404,size:`large`,children:jsx(EmptyState.PrimaryAction,{startIcon:ArrowsRotating,onClick:handleRetry,children:formatMessage(messages_default.reload)})})}):jsxs(EditorConfigContext.Provider,{value:editorConfigValue,children:[jsx(Formik,{initialValues:mergedInitialValues,validationSchema:isReadOnlyMode?void 0:schema,onSubmit:async values=>{if(!isReadOnlyMode)try{if(isEditMode){let patchItems=generateJSONPatchTemplateOperations(mergedInitialValues,values);await modeProps.onEditTemplate(patchItems,{namespaceFQN:mergedInitialValues.namespace,templateKey:mergedInitialValues.templateKey})}else{let convertedFields=mapFieldsWithUniqueKeys(values.fields),createBody={namespace:values.namespace,templateKey:values.templateKey,displayName:values.displayName,hidden:values.hidden,fields:convertedFields};await modeProps.onCreateTemplate(createBody)}addNotification({sensitivity:`foreground`,variant:`success`,styledText:formatMessage(messages_default.saveSuccessNotification),typeIconAriaLabel:formatMessage(messages_default.notificationSuccessIconAriaLabel),closeButtonAriaLabel:formatMessage(messages_default.notificationCloseButtonAriaLabel)})}catch(error){let errorMessage;if(error instanceof Error&&`status`in error){let{status}=error;errorMessage=formatMessage(status===409?messages_default.displayNameUsedBefore:messages_default.saveErrorNotification)}else errorMessage=formatMessage(messages_default.saveErrorNotification);addNotification({sensitivity:`foreground`,variant:`error`,styledText:errorMessage,typeIconAriaLabel:formatMessage(messages_default.notificationErrorIconAriaLabel),closeButtonAriaLabel:formatMessage(messages_default.notificationCloseButtonAriaLabel)});try{onSubmitError?.(error)}catch{}throw error}},children:jsx(MetadataTemplateEditorForm,{formId,onCancel:handleCancel,taxonomyOptions,fetchTaxonomies,fetchTaxonomyByKey,hideActions,isEditMode,isVisibilityToggleAllowed,readOnly:isReadOnlyMode,onDirtyStateChange:handleDirtyStateChange,onValidationChange,fieldExtensions})}),isUnsavedChangesModalOpen&&jsx(UnsavedChangesModal,{onKeepEditing:()=>setIsUnsavedChangesModalOpen(!1),onDiscard:()=>{setIsUnsavedChangesModalOpen(!1),onCancel?.()}})]})}export{MetadataTemplateEditor as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import ConfirmationModal from"../metadata-field-configurator/components/confirmation-modal/confirmation-modal.js";import messages_default from"../../messages.js";import{useIntl}from"react-intl";import{jsx}from"react/jsx-runtime";function UnsavedChangesModal({onKeepEditing,onDiscard}){let{formatMessage}=useIntl();return jsx(ConfirmationModal,{onClose:onKeepEditing,onConfirm:onDiscard,title:formatMessage(messages_default.unsavedChangesTitle),body:formatMessage(messages_default.unsavedChangesBody),confirmLabel:formatMessage(messages_default.unsavedChangesDiscard),cancelLabel:formatMessage(messages_default.unsavedChangesKeepEditing)})}export{UnsavedChangesModal};
|
package/dist/esm/lib/messages.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineMessages}from"react-intl";var messages_default=defineMessages({createTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.createTitle`,defaultMessage:`New Metadata Template`},editTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.editTitle`,defaultMessage:`Edit "{templateName}" Metadata Template`},templateName:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.templateName.label`,defaultMessage:`Template Name`},templateNameDescription:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.templateName.description`,defaultMessage:`Display name of the template shown to users`},hideTemplate:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.hideTemplate`,defaultMessage:`Hide Template`},hideTemplateInfo:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.hideTemplate.info`,defaultMessage:`When hidden, the template is still available via the Box API`},hideTemplateInfoAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.hideTemplate.infoAriaLabel`,defaultMessage:`More information about hiding the template`},cancel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.cancel`,defaultMessage:`Cancel`},save:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.save`,defaultMessage:`Save`},fields:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fields.label`,defaultMessage:`Fields`},fieldsAddFirst:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fields.description`,defaultMessage:`Add your first field to the Template:`},fieldsLearnMore:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fields.learnMore`,defaultMessage:`Learn more about Metadata Field Types`},fieldRequired:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fieldRequired`,defaultMessage:`This field is required`},forbiddenDisplayName:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.forbiddenDisplayName`,defaultMessage:`This display name is forbidden. Please choose another one.`},invalidCharacters:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.invalidCharacters`,defaultMessage:`The field contains illegal characters.`},fieldNameTooLong:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fieldNameTooLong`,defaultMessage:`The field name is too long.`},displayNameUsedBefore:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.displayNameUsedBefore`,defaultMessage:`This display name has already been used before. Please choose another one.`},submitting:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.submitting`,defaultMessage:`Submitting...`},closeAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.closeAriaLabel`,defaultMessage:`Close metadata template editor`},saveSuccessNotification:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.saveSuccessNotification`,defaultMessage:`Template saved successfully.`},saveErrorNotification:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.saveErrorNotification`,defaultMessage:`Failed to save template. Please try again.`},notificationSuccessIconAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.notificationSuccessIconAriaLabel`,defaultMessage:`Success`},notificationErrorIconAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.notificationErrorIconAriaLabel`,defaultMessage:`Error`},notificationCloseButtonAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.notificationCloseButtonAriaLabel`,defaultMessage:`Close notification`},loading:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.loading`,defaultMessage:`Loading template…`},fetchError:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fetchError`,defaultMessage:`Something went wrong. Please reload to try again.`},reload:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.reload`,defaultMessage:`Reload`},unsavedChangesTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesTitle`,defaultMessage:`Unsaved Changes`},unsavedChangesBody:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesBody`,defaultMessage:`You have unsaved changes. If you leave now, your changes will be lost.`},unsavedChangesDiscard:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesDiscard`,defaultMessage:`Leave Without Saving`},unsavedChangesKeepEditing:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesKeepEditing`,defaultMessage:`Keep Editing`},close:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.close`,defaultMessage:`Close`},viewTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.viewTitle`,defaultMessage:`{templateName}`},noFields:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.noFields`,defaultMessage:`This template contains no fields.`}});export{messages_default as default};
|
|
1
|
+
import{defineMessages}from"react-intl";var messages_default=defineMessages({createTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.createTitle`,defaultMessage:`New Metadata Template`},editTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.editTitle`,defaultMessage:`Edit "{templateName}" Metadata Template`},templateName:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.templateName.label`,defaultMessage:`Template Name`},templateNameDescription:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.templateName.description`,defaultMessage:`Display name of the template shown to users`},hideTemplate:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.hideTemplate`,defaultMessage:`Hide Template`},hideTemplateInfo:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.hideTemplate.info`,defaultMessage:`When hidden, the template is still available via the Box API`},hideTemplateInfoAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.hideTemplate.infoAriaLabel`,defaultMessage:`More information about hiding the template`},cancel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.cancel`,defaultMessage:`Cancel`},save:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.save`,defaultMessage:`Save`},fields:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fields.label`,defaultMessage:`Fields`},fieldsAddFirst:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fields.description`,defaultMessage:`Add your first field to the Template:`},fieldsLearnMore:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fields.learnMore`,defaultMessage:`Learn more about Metadata Field Types`},fieldRequired:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fieldRequired`,defaultMessage:`This field is required`},forbiddenDisplayName:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.forbiddenDisplayName`,defaultMessage:`This display name is forbidden. Please choose another one.`},invalidCharacters:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.invalidCharacters`,defaultMessage:`The field contains illegal characters.`},fieldNameTooLong:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fieldNameTooLong`,defaultMessage:`The field name is too long.`},displayNameUsedBefore:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.displayNameUsedBefore`,defaultMessage:`This display name has already been used before. Please choose another one.`},submitting:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.submitting`,defaultMessage:`Submitting...`},closeAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.closeAriaLabel`,defaultMessage:`Close metadata template editor`},backAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.backAriaLabel`,defaultMessage:`Back`},saveSuccessNotification:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.saveSuccessNotification`,defaultMessage:`Template saved successfully.`},saveErrorNotification:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.saveErrorNotification`,defaultMessage:`Failed to save template. Please try again.`},notificationSuccessIconAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.notificationSuccessIconAriaLabel`,defaultMessage:`Success`},notificationErrorIconAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.notificationErrorIconAriaLabel`,defaultMessage:`Error`},notificationCloseButtonAriaLabel:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.notificationCloseButtonAriaLabel`,defaultMessage:`Close notification`},loading:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.loading`,defaultMessage:`Loading template…`},fetchError:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.fetchError`,defaultMessage:`Something went wrong. Please reload to try again.`},reload:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.reload`,defaultMessage:`Reload`},unsavedChangesTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesTitle`,defaultMessage:`Unsaved Changes`},unsavedChangesBody:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesBody`,defaultMessage:`You have unsaved changes. If you leave now, your changes will be lost.`},unsavedChangesDiscard:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesDiscard`,defaultMessage:`Leave Without Saving`},unsavedChangesKeepEditing:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.unsavedChangesKeepEditing`,defaultMessage:`Keep Editing`},close:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.close`,defaultMessage:`Close`},viewTitle:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.viewTitle`,defaultMessage:`{templateName}`},noFields:{id:`groupSharedFeatures.metadataTemplateEditor.templateForm.noFields`,defaultMessage:`This template contains no fields.`}});export{messages_default as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { MetadataTemplateEditorModal } from './metadata-template-editor-modal';
|
|
1
|
+
export { MetadataTemplateEditorModal, type MetadataTemplateEditorModalProps, } from './metadata-template-editor-modal';
|
package/dist/types/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export type MetadataTemplateEditorModalProps = MetadataTemplateEditorProps & {
|
|
|
3
3
|
/** Controls whether the modal is open. */
|
|
4
4
|
open: boolean;
|
|
5
5
|
/**
|
|
6
|
-
* Called
|
|
7
|
-
* Use this to update the `open` prop in the parent.
|
|
6
|
+
* Called whenever the modal should change open state: after a close intent settles
|
|
7
|
+
* and after a successful save. Use this to update the `open` prop in the parent.
|
|
8
8
|
*/
|
|
9
9
|
onOpenChange: (open: boolean) => void;
|
|
10
10
|
/**
|
|
@@ -12,21 +12,28 @@ export type MetadataTemplateEditorModalProps = MetadataTemplateEditorProps & {
|
|
|
12
12
|
* @default "New Metadata Template"
|
|
13
13
|
*/
|
|
14
14
|
title?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Shows a header back button, for hosts that opened the editor from a view the user
|
|
17
|
+
* should return to. Once the unsaved-changes guard passes it is called in place of
|
|
18
|
+
* `onCancel`, then the modal closes as usual. Omit to hide the button.
|
|
19
|
+
*/
|
|
20
|
+
onBack?: () => void;
|
|
15
21
|
};
|
|
16
22
|
/**
|
|
17
23
|
* Modal wrapper around `MetadataTemplateEditor`.
|
|
18
24
|
*
|
|
19
25
|
* Renders the full template editor inside a Blueprint `Modal`, with Cancel and
|
|
20
|
-
* Save buttons promoted to the modal footer.
|
|
21
|
-
* after a successful submission or when the user cancels.
|
|
26
|
+
* Save buttons promoted to the modal footer.
|
|
22
27
|
*
|
|
23
28
|
* The footer Save button is disabled while a submission is in progress. In **edit mode**
|
|
24
29
|
* it is additionally disabled until the user makes at least one change (`dirty`).
|
|
25
30
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
31
|
+
* Three ways out, see `CloseIntent`: a dismiss settles with `onCancel`, the header back
|
|
32
|
+
* button settles with `onBack`, and a successful save closes with neither. The first two
|
|
33
|
+
* run the "unsaved changes" guard on a dirty form before settling; a save does not.
|
|
34
|
+
*
|
|
35
|
+
* While a save is in flight every exit is locked, because the submit callbacks cannot be
|
|
36
|
+
* cancelled. Hosts must settle the returned Promise or the modal stays open.
|
|
30
37
|
*
|
|
31
38
|
* @example
|
|
32
39
|
* ```tsx
|
|
@@ -40,7 +47,7 @@ export type MetadataTemplateEditorModalProps = MetadataTemplateEditorProps & {
|
|
|
40
47
|
* onSubmitError={err => logger.error('save failed', err)}
|
|
41
48
|
* />
|
|
42
49
|
*
|
|
43
|
-
* // Edit flow
|
|
50
|
+
* // Edit flow: dynamic title, error callback
|
|
44
51
|
* <MetadataTemplateEditorModal
|
|
45
52
|
* mode={MetadataTemplateEditorMode.Edit}
|
|
46
53
|
* open={open}
|
|
@@ -52,5 +59,5 @@ export type MetadataTemplateEditorModalProps = MetadataTemplateEditorProps & {
|
|
|
52
59
|
* />
|
|
53
60
|
* ```
|
|
54
61
|
*/
|
|
55
|
-
export declare function MetadataTemplateEditorModal({ open, onOpenChange, onTemplateLoad, onValidationChange, onCancel, title, ...editorProps }: MetadataTemplateEditorModalProps): import("react/jsx-runtime").JSX.Element;
|
|
62
|
+
export declare function MetadataTemplateEditorModal({ open, onOpenChange, onTemplateLoad, onValidationChange, onCancel, onBack, title, ...editorProps }: MetadataTemplateEditorModalProps): import("react/jsx-runtime").JSX.Element;
|
|
56
63
|
export default MetadataTemplateEditorModal;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type UnsavedChangesModalProps = {
|
|
2
|
+
/** The user chose to stay on the form. The close that opened this is abandoned. */
|
|
3
|
+
onKeepEditing: () => void;
|
|
4
|
+
/** The user chose to lose their edits. The caller may now close. */
|
|
5
|
+
onDiscard: () => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* "Unsaved changes" confirmation, rendered by whoever owns the close trigger that
|
|
9
|
+
* hit a dirty form. Holds only the copy, so the wording stays consistent between
|
|
10
|
+
* the bare editor and the editor modal.
|
|
11
|
+
*/
|
|
12
|
+
export declare function UnsavedChangesModal({ onKeepEditing, onDiscard }: Readonly<UnsavedChangesModalProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -261,33 +261,6 @@ type ReadOnlyModeProps = {
|
|
|
261
261
|
namespace?: never;
|
|
262
262
|
};
|
|
263
263
|
export type MetadataTemplateEditorProps = MetadataTemplateEditorCommonProps & (CreateModeProps | EditModeProps | ReadOnlyModeProps);
|
|
264
|
-
/**
|
|
265
|
-
* Imperative handle exposed by `MetadataTemplateEditor` via `ref`.
|
|
266
|
-
*
|
|
267
|
-
* Allows a parent (e.g. `MetadataTemplateEditorModal`) to delegate its own
|
|
268
|
-
* cancel / close triggers to the editor so that the "unsaved changes" guard
|
|
269
|
-
* and the `ConfirmationModal` live in exactly one place.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```tsx
|
|
273
|
-
* const editorRef = useRef<MetadataTemplateEditorHandle>(null);
|
|
274
|
-
*
|
|
275
|
-
* // Delegate the modal's footer Cancel and shell close to the editor:
|
|
276
|
-
* <MetadataTemplateEditorModal … /> // internally calls editorRef.current.requestClose()
|
|
277
|
-
*
|
|
278
|
-
* // Or wire it up manually:
|
|
279
|
-
* <button onClick={() => editorRef.current?.requestClose()}>Cancel</button>
|
|
280
|
-
* <MetadataTemplateEditor ref={editorRef} … />
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
export type MetadataTemplateEditorHandle = {
|
|
284
|
-
/**
|
|
285
|
-
* Triggers the editor's cancel flow from outside the component.
|
|
286
|
-
* If the form is dirty, opens the "unsaved changes" confirmation modal.
|
|
287
|
-
* Otherwise calls `onCancel` immediately.
|
|
288
|
-
*/
|
|
289
|
-
requestClose: () => void;
|
|
290
|
-
};
|
|
291
264
|
/**
|
|
292
265
|
* Full metadata template creation / editing form.
|
|
293
266
|
*
|
|
@@ -349,5 +322,5 @@ export type MetadataTemplateEditorHandle = {
|
|
|
349
322
|
* </button>
|
|
350
323
|
* ```
|
|
351
324
|
*/
|
|
352
|
-
export declare
|
|
325
|
+
export declare function MetadataTemplateEditor({ onCancel, onDirtyStateChange, onValidationChange, onSubmitError, onTemplateLoad, taxonomyOptions, fetchTaxonomies, fetchTaxonomyByKey, disabledFieldTypes, taxonomyInitialStateLabels, formId, hideActions, isVisibilityToggleAllowed, fieldExtensions, ...modeProps }: MetadataTemplateEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
353
326
|
export default MetadataTemplateEditor;
|