-
Notifications
You must be signed in to change notification settings - Fork 344
feat(metadata-instance-editor): support for cascade extraction #4616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5bb0d7f
feat(metadata-instance-editor): support cascade extraction
alexkirillovtech 1d2a0a6
feat(metadata-instance-editor): improve tests
alexkirillovtech 57c7dfc
feat(metadata-instance-editor): import order
alexkirillovtech f2100c9
feat(metadata-instance-editor): update comments
alexkirillovtech 3c3f3e1
feat(metadata-instance-editor): messages in tests
alexkirillovtech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
86 changes: 86 additions & 0 deletions
86
src/features/metadata-instance-editor/CustomExtractAgentInstanceBody.js
This file contains hidden or 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,86 @@ | ||
| // @flow | ||
| import * as React from 'react'; | ||
| import { FormattedMessage, useIntl } from 'react-intl'; | ||
|
|
||
| import { ActionableInlineNotice } from '@box/blueprint-web'; | ||
| // $FlowFixMe - blueprint-web-assets icons not typed for Flow | ||
| import { Lock } from '@box/blueprint-web-assets/icons/Line'; | ||
|
|
||
| import TemplatedInstance from './TemplatedInstance'; | ||
| import CustomInstance from './CustomInstance'; | ||
|
|
||
| import { getCustomExtractAgentId } from './metadataUtil'; | ||
|
|
||
| import type { MetadataFields, MetadataTemplate } from '../../common/types/metadata'; | ||
|
|
||
| import { TEMPLATE_CUSTOM_PROPERTIES } from './constants'; | ||
|
|
||
| import messages from './messages'; | ||
|
|
||
| import './CustomExtractAgentInstanceBody.scss'; | ||
|
|
||
| type Props = { | ||
| // Raw agent configuration value from the cascade policy (e.g. `extract_agent_<id>`). | ||
| // The navigable numeric id is extracted from this value via getCustomExtractAgentId. | ||
| agentConfiguration?: string, | ||
| data: MetadataFields, | ||
| isEditing: boolean, | ||
| onManageExtractAgent?: (agentId: string) => void, | ||
| template: MetadataTemplate, | ||
| }; | ||
|
|
||
| /** | ||
| * Presentational interior for a metadata instance managed by a custom Box AI | ||
| * extract agent. In read-only (view) mode it shows the field values without edit | ||
| * controls; when the user enters edit mode it replaces the form with an informational | ||
| * notice and a button to manage the agent (instead of allowing inline edits). | ||
| * | ||
| * The "manage agent" button is only shown when a navigable numeric agent id can be | ||
| * resolved from the configuration; otherwise the notice is shown without an action. | ||
| */ | ||
| const CustomExtractAgentInstanceBody = ({ | ||
| agentConfiguration, | ||
| data, | ||
| isEditing, | ||
| onManageExtractAgent, | ||
| template, | ||
| }: Props) => { | ||
| const { formatMessage } = useIntl(); | ||
| const isProperties = template.templateKey === TEMPLATE_CUSTOM_PROPERTIES; | ||
| const customExtractAgentId = getCustomExtractAgentId(agentConfiguration); | ||
|
|
||
| if (isEditing) { | ||
| return ( | ||
| <div className="metadata-instance-editor-custom-extract-agent"> | ||
| <ActionableInlineNotice | ||
| icon={Lock} | ||
| iconAriaLabel={formatMessage(messages.customExtractAgentNoticeIconAriaLabel)} | ||
| text={formatMessage(messages.customExtractAgentNoticeDescription)} | ||
| > | ||
| {!!customExtractAgentId && onManageExtractAgent && ( | ||
| <ActionableInlineNotice.PrimaryAction | ||
| onClick={() => onManageExtractAgent(customExtractAgentId)} | ||
| > | ||
| {formatMessage(messages.customExtractAgentManageButton)} | ||
| </ActionableInlineNotice.PrimaryAction> | ||
| )} | ||
| </ActionableInlineNotice> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="metadata-instance-editor-instance"> | ||
| <div className="metadata-cascade-notice"> | ||
| <FormattedMessage {...messages.metadataCascadePolicyEnabledInfo} /> | ||
| </div> | ||
| {isProperties ? ( | ||
| <CustomInstance canEdit={false} data={data} /> | ||
| ) : ( | ||
| <TemplatedInstance canEdit={false} data={data} errors={{}} template={template} /> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default CustomExtractAgentInstanceBody; | ||
3 changes: 3 additions & 0 deletions
3
src/features/metadata-instance-editor/CustomExtractAgentInstanceBody.scss
This file contains hidden or 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,3 @@ | ||
| .metadata-instance-editor-custom-extract-agent { | ||
| padding: var(--bp-space-020); | ||
| } |
146 changes: 146 additions & 0 deletions
146
src/features/metadata-instance-editor/EditableInstanceBody.js
This file contains hidden or 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,146 @@ | ||
| // @flow | ||
| import * as React from 'react'; | ||
| import noop from 'lodash/noop'; | ||
|
|
||
| import type { AgentType } from '@box/box-ai-agent-selector'; | ||
|
|
||
| import Form from '../../components/form-elements/form/Form'; | ||
| import LoadingIndicatorWrapper from '../../components/loading-indicator/LoadingIndicatorWrapper'; | ||
| import CascadePolicy from './CascadePolicy'; | ||
| import TemplatedInstance from './TemplatedInstance'; | ||
| import CustomInstance from './CustomInstance'; | ||
| import MetadataInstanceConfirmDialog from './MetadataInstanceConfirmDialog'; | ||
| import Footer from './Footer'; | ||
|
|
||
| import type { | ||
| MetadataCascadePolicy, | ||
| MetadataFields, | ||
| MetadataTemplate, | ||
| MetadataFieldValue, | ||
| } from '../../common/types/metadata'; | ||
|
|
||
| type Props = { | ||
| canUseAIFolderExtraction: boolean, | ||
| cascadePolicy: MetadataCascadePolicy, | ||
| confirmationMessage: React.Node, | ||
| data: MetadataFields, | ||
| errors: { [string]: React.Node }, | ||
| isAIFolderExtractionEnabled: boolean, | ||
| isBusy: boolean, | ||
| isCascadingEnabled: boolean, | ||
| isCascadingOverwritten: boolean, | ||
| isCascadingPolicyApplicable?: boolean, | ||
| isDirty: boolean, | ||
| isEditing: boolean, | ||
| isExistingCascadePolicy: boolean, | ||
| isProperties: boolean, | ||
| onAIAgentSelect: (agent: AgentType | null) => void, | ||
| onAIFolderExtractionToggle: (value: boolean) => void, | ||
| onCancel: () => void, | ||
| onCascadeModeChange: (value: boolean) => void, | ||
| onCascadeToggle: (value: boolean) => void, | ||
| onConfirmCancel: () => void, | ||
| onConfirmRemove: () => void, | ||
| onFieldChange: (key: string, value: MetadataFieldValue, type: string) => void, | ||
| onFieldRemove: (key: string) => void, | ||
| onRemove: () => void, | ||
| onSave: () => void, | ||
| shouldConfirmRemove: boolean, | ||
| shouldShowCascadeOptions: boolean, | ||
| template: MetadataTemplate, | ||
| }; | ||
|
|
||
| /** | ||
| * Presentational interior for an editable metadata instance: the confirm-remove | ||
| * dialog, the form with cascade policy + fields, and the save/remove footer. | ||
| * All state and handlers are owned by the parent Instance and supplied via props. | ||
| */ | ||
| const EditableInstanceBody = ({ | ||
| canUseAIFolderExtraction, | ||
| cascadePolicy = {}, | ||
| confirmationMessage, | ||
| data, | ||
| errors, | ||
| isAIFolderExtractionEnabled, | ||
| isBusy, | ||
| isCascadingEnabled, | ||
| isCascadingOverwritten, | ||
| isCascadingPolicyApplicable, | ||
| isDirty, | ||
| isEditing, | ||
| isExistingCascadePolicy, | ||
| isProperties, | ||
| onAIAgentSelect, | ||
| onAIFolderExtractionToggle, | ||
| onCancel, | ||
| onCascadeModeChange, | ||
| onCascadeToggle, | ||
| onConfirmCancel, | ||
| onConfirmRemove, | ||
| onFieldChange, | ||
| onFieldRemove, | ||
| onRemove, | ||
| onSave, | ||
| shouldConfirmRemove, | ||
| shouldShowCascadeOptions, | ||
| template, | ||
| }: Props) => { | ||
| if (shouldConfirmRemove) { | ||
| return ( | ||
| <LoadingIndicatorWrapper isLoading={isBusy}> | ||
| <MetadataInstanceConfirmDialog | ||
| confirmationMessage={confirmationMessage} | ||
| onCancel={onConfirmCancel} | ||
| onConfirm={onRemove} | ||
| /> | ||
| </LoadingIndicatorWrapper> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <LoadingIndicatorWrapper isLoading={isBusy}> | ||
| <Form onValidSubmit={isDirty ? onSave : noop}> | ||
| <div className="metadata-instance-editor-instance"> | ||
| {isCascadingPolicyApplicable && ( | ||
| <CascadePolicy | ||
| cascadePolicyConfiguration={cascadePolicy?.cascadePolicyConfiguration} | ||
| canEdit={isEditing && !!cascadePolicy.canEdit} | ||
| canUseAIFolderExtraction={canUseAIFolderExtraction} | ||
| isAIFolderExtractionEnabled={isAIFolderExtractionEnabled} | ||
| isCascadingEnabled={isCascadingEnabled} | ||
| isCascadingOverwritten={isCascadingOverwritten} | ||
| isCustomMetadata={isProperties} | ||
| isExistingCascadePolicy={isExistingCascadePolicy} | ||
| onAIAgentSelect={onAIAgentSelect} | ||
| onAIFolderExtractionToggle={onAIFolderExtractionToggle} | ||
| onCascadeModeChange={onCascadeModeChange} | ||
| onCascadeToggle={onCascadeToggle} | ||
| shouldShowCascadeOptions={shouldShowCascadeOptions} | ||
| /> | ||
| )} | ||
| {isProperties ? ( | ||
| <CustomInstance | ||
| canEdit={isEditing} | ||
| data={data} | ||
| onFieldChange={onFieldChange} | ||
| onFieldRemove={onFieldRemove} | ||
| /> | ||
| ) : ( | ||
| <TemplatedInstance | ||
| canEdit={isEditing} | ||
| data={data} | ||
| errors={errors} | ||
| isDisabled={isAIFolderExtractionEnabled} | ||
| onFieldChange={onFieldChange} | ||
| onFieldRemove={onFieldRemove} | ||
| template={template} | ||
| /> | ||
| )} | ||
| </div> | ||
| {isEditing && <Footer onCancel={onCancel} onRemove={onConfirmRemove} showSave={isDirty} />} | ||
| </Form> | ||
| </LoadingIndicatorWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default EditableInstanceBody; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.