Skip to content
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

fix(metadata): Disable updates to metadata #3376

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
54b4e38
fix(metadata): Disable updates to metadata
joshmarnold Jul 25, 2023
853d4d1
fix(metadata): Disable updates to metadata
joshmarnold Jul 25, 2023
b3bf5ad
fix(metadata): Disable updates to metadata
joshmarnold Jul 26, 2023
66ced6d
fix(metadata): Disable updates to metadata
joshmarnold Jul 26, 2023
bd22736
fix(metadata): Disable updates to metadata
joshmarnold Jul 26, 2023
b00d3e0
fix(metadata): Disable updates to metadata
joshmarnold Jul 26, 2023
ca8e8fc
fix(metadata): Disable updates to metadata
joshmarnold Jul 26, 2023
255ebf5
fix(metadata): Disable updates to metadata
joshmarnold Jul 27, 2023
3876b2e
fix(metadata): Disable updates to metadata
joshmarnold Jul 27, 2023
ec98e5a
fix(metadata): Disable updates to metadata
joshmarnold Jul 31, 2023
ae1efb8
fix(metadata): Disable updates to metadata
joshmarnold Aug 1, 2023
91062a8
fix(metadata): Disable updates to metadata
joshmarnold Aug 2, 2023
4a6a954
fix(metadata): Disable updates to metadata
joshmarnold Aug 2, 2023
e56de3b
fix(metadata): Disable updates to metadata
joshmarnold Aug 3, 2023
3c06a6a
fix(metadata): Disable updates to metadata
joshmarnold Aug 7, 2023
9d109ee
fix(metadata): Disable updates to metadata
joshmarnold Aug 9, 2023
496f857
fix(metadata): Disable updates to metadata
joshmarnold Aug 10, 2023
8166c3a
fix(metadata): Disable updates to metadata
joshmarnold Aug 10, 2023
8537652
fix(metadata): Disable updates to metadata
joshmarnold Aug 17, 2023
1241fe7
Merge branch 'master' into WEBAPP-17450
joshmarnold Aug 21, 2023
c826ee1
fix(metadata): Disable updates to metadata
joshmarnold Aug 21, 2023
f71d399
fix(metadata): Disable updates to metadata
joshmarnold Aug 21, 2023
c55f430
fix(metadata): Disable updates to metadata
joshmarnold Aug 22, 2023
d1a4709
fix(metadata): Disable updates to metadata
joshmarnold Aug 22, 2023
b831683
fix(metadata): Disable updates to metadata
joshmarnold Aug 22, 2023
8d8cbb7
Merge branch 'master' into WEBAPP-17450
joshmarnold Aug 22, 2023
85586c4
fix(metadata): Disable updates to metadata
joshmarnold Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/src/MetadataExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ class MetadataExamples extends React.PureComponent {
canAdd
editors={this.state.editors}
isCascadingPolicyApplicable
isFolderMetadata
onAdd={this.onAdd}
onModification={this.onModification}
onRemove={this.onRemove}
Expand All @@ -1053,6 +1054,7 @@ class MetadataExamples extends React.PureComponent {
<MetadataInstanceEditor
canAdd
editors={this.state.editors}
isFolderMetadata
onAdd={this.onAdd}
onModification={this.onModification}
onRemove={this.onRemove}
Expand All @@ -1067,6 +1069,7 @@ class MetadataExamples extends React.PureComponent {
<div className="metadata-container">
<MetadataInstanceEditor
canAdd
isFolderMetadata
onAdd={this.onAdd}
onModification={this.onModification}
onRemove={this.onRemove}
Expand All @@ -1082,6 +1085,7 @@ class MetadataExamples extends React.PureComponent {
<MetadataInstanceEditor
canAdd
editors={this.state.editors}
isFolderMetadata
onAdd={this.onAdd}
onModification={this.onModification}
onRemove={this.onRemove}
Expand Down
2 changes: 2 additions & 0 deletions src/common/types/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type MetadataInstance = {
cascadePolicy?: MetadataCascadePolicy,
data: MetadataFields,
id: string,
isCascadingPolicyApplicable?: boolean,
isFolderMetadata?: boolean,
};

type MetadataInstanceV2 = {
Expand Down
5 changes: 3 additions & 2 deletions src/features/metadata-instance-editor/CascadePolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ const CascadePolicy = ({
shouldShowCascadeOptions,
}: Props) => {
const readOnlyState = isCascadingEnabled ? (
<div className="metadata-cascade-notice">
<div className="metadata-cascade-notice" data-testid="metadata-cascade-notice">
<FormattedMessage {...messages.metadataCascadePolicyEnabledInfo} />
</div>
) : null;

return canEdit ? (
<>
<div className="metadata-cascade-editor">
<div className="metadata-cascade-editor" data-testid="metadata-cascade-policy">
<div className="metadata-cascade-enable">
<div>
<FormattedMessage tagName="strong" {...messages.enableCascadePolicy} />
Expand All @@ -47,6 +47,7 @@ const CascadePolicy = ({
className={`metadata-cascade-toggle ${
isCascadingEnabled ? 'cascade-on' : 'cascade-off'
}`}
data-testid={`metadata-cascade-toggle-${isCascadingEnabled ? 'on' : 'off'}`}
isOn={isCascadingEnabled}
label=""
onChange={e => onCascadeToggle(e.target.checked)}
Expand Down
75 changes: 34 additions & 41 deletions src/features/metadata-instance-editor/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ type Props = {
hasError: boolean,
id: string,
intl: Object,
isCascadingPolicyApplicable?: boolean,
isCascadingPolicyApplicable: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this intentional? metadata.js is still using isCascadingPolicyApplicable?: boolean,

isDirty: boolean,
isFolderMetadata?: boolean,
isOpen: boolean,
onModification?: (id: string, isDirty: boolean, type?: string) => void,
onRemove?: (id: string) => void,
Expand Down Expand Up @@ -102,6 +103,8 @@ class Instance extends React.PureComponent<Props, State> {
static defaultProps = {
data: {},
isDirty: false,
isCascadingPolicyApplicable: false,
tjuanitas marked this conversation as resolved.
Show resolved Hide resolved
isFolderMetadata: false,
};

constructor(props: Props) {
Expand Down Expand Up @@ -200,14 +203,7 @@ class Instance extends React.PureComponent<Props, State> {
* @return {void}
*/
onSave = (): void => {
const {
cascadePolicy,
data: originalData,
id,
isDirty,
isCascadingPolicyApplicable,
onSave,
}: Props = this.props;
const { cascadePolicy = {}, data: originalData, id, isDirty, onSave, isFolderMetadata }: Props = this.props;
const { data: currentData, errors, isCascadingEnabled, isCascadingOverwritten }: State = this.state;

if (!this.isEditing() || !isDirty || !onSave || Object.keys(errors).length) {
Expand All @@ -219,19 +215,16 @@ class Instance extends React.PureComponent<Props, State> {
isEditing: false,
shouldShowCascadeOptions: false,
});
onSave(
id,
this.createJSONPatch(currentData, originalData),
isCascadingPolicyApplicable
? {
canEdit: cascadePolicy ? cascadePolicy.canEdit : false,
id: cascadePolicy ? cascadePolicy.id : undefined,
isEnabled: isCascadingEnabled,
overwrite: isCascadingOverwritten,
}
: undefined,
cloneDeep(currentData),
);

const cascadePolicyData = {
...cascadePolicy,
isEnabled: isFolderMetadata ? isCascadingEnabled : false,
overwrite: isCascadingOverwritten,
};

const clonedCurrentData = cloneDeep(currentData);
const JSONPatch = this.createJSONPatch(clonedCurrentData, originalData);
onSave(id, JSONPatch, cascadePolicyData, clonedCurrentData);
};

/**
Expand Down Expand Up @@ -351,10 +344,10 @@ class Instance extends React.PureComponent<Props, State> {
* @return {Object} - react title element
*/
getTitle(): React.Node {
const { cascadePolicy = {}, hasError, isCascadingPolicyApplicable, template }: Props = this.props;
const { cascadePolicy = {}, hasError, template }: Props = this.props;
const isProperties = template.templateKey === TEMPLATE_CUSTOM_PROPERTIES;

const type = isCascadingPolicyApplicable && cascadePolicy.id ? 'cascade' : 'default';
tjuanitas marked this conversation as resolved.
Show resolved Hide resolved
const type = cascadePolicy?.id ? 'cascade' : 'default';

return (
<span className="metadata-instance-editor-instance-title">
Expand All @@ -363,6 +356,7 @@ class Instance extends React.PureComponent<Props, State> {
className={classNames('metadata-instance-editor-instance-title-text', {
'metadata-instance-editor-instance-has-error': hasError,
})}
data-testid={hasError ? 'metadata-instance-has-error' : undefined}
>
{isProperties ? <FormattedMessage {...messages.customTitle} /> : template.displayName}
</span>
Expand Down Expand Up @@ -398,8 +392,8 @@ class Instance extends React.PureComponent<Props, State> {
* Get the delete confirmation message base on the template key
*/
getConfirmationMessage(): React.Node {
const { template, isCascadingPolicyApplicable }: Props = this.props;
const isFile = !isCascadingPolicyApplicable;
const { template, isFolderMetadata }: Props = this.props;
const isFile = !isFolderMetadata;
return this.renderDeleteMessage(isFile, template);
}

Expand Down Expand Up @@ -440,10 +434,7 @@ class Instance extends React.PureComponent<Props, State> {
* @return {boolean} true if cascading policy is enabled
*/
isCascadingEnabled(props: Props) {
if (props.cascadePolicy) {
return !!props.cascadePolicy.id;
}
return false;
return !!props?.cascadePolicy?.id;
}

/**
Expand Down Expand Up @@ -531,6 +522,7 @@ class Instance extends React.PureComponent<Props, State> {
*/
canEdit(): boolean {
const { canEdit, onModification, onRemove, onSave }: Props = this.props;

return (
canEdit &&
typeof onRemove === 'function' &&
Expand Down Expand Up @@ -579,7 +571,7 @@ class Instance extends React.PureComponent<Props, State> {
};

render() {
const { cascadePolicy = {}, isDirty, isCascadingPolicyApplicable, isOpen, template }: Props = this.props;
const { isDirty, isFolderMetadata, isOpen, template }: Props = this.props;
const { fields = [] } = template;
const {
data,
Expand All @@ -590,8 +582,7 @@ class Instance extends React.PureComponent<Props, State> {
shouldShowCascadeOptions,
isCascadingOverwritten,
}: State = this.state;
const isProperties = template.templateKey === TEMPLATE_CUSTOM_PROPERTIES;
const isEditing = this.isEditing();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine the performance impact is minor but consider that you are now calling isEditing() n times instead of storing the result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, I think the original is cleaner too

const isCustomInstance = template.templateKey === TEMPLATE_CUSTOM_PROPERTIES;

if (!template || isHidden(template)) {
return null;
Expand All @@ -601,7 +592,7 @@ class Instance extends React.PureComponent<Props, State> {
const animationDuration = (fields.length + 1) * 50;

return (
<div ref={this.collapsibleRef}>
<div ref={this.collapsibleRef} data-testid="metadata-instance">
<Collapsible
animationDuration={animationDuration}
buttonProps={{
Expand All @@ -626,27 +617,29 @@ class Instance extends React.PureComponent<Props, State> {
<LoadingIndicatorWrapper isLoading={isBusy}>
<Form onValidSubmit={isDirty ? this.onSave : noop}>
<div className="metadata-instance-editor-instance">
{isCascadingPolicyApplicable && (
{/* policies aren't enabled on custom instances but we show this anyway to display a message to inform the user */}
{isFolderMetadata && (
<CascadePolicy
canEdit={isEditing && !!cascadePolicy.canEdit}
canEdit={this.isEditing()}
isCascadingEnabled={isCascadingEnabled}
isCascadingOverwritten={isCascadingOverwritten}
isCustomMetadata={isProperties}
isCustomMetadata={isCustomInstance}
onCascadeModeChange={this.onCascadeModeChange}
onCascadeToggle={this.onCascadeToggle}
shouldShowCascadeOptions={shouldShowCascadeOptions}
/>
)}
{isProperties ? (

{isCustomInstance ? (
<CustomInstance
canEdit={isEditing}
canEdit={this.isEditing()}
data={data}
onFieldChange={this.onFieldChange}
onFieldRemove={this.onFieldRemove}
/>
) : (
<TemplatedInstance
canEdit={isEditing}
canEdit={this.isEditing()}
data={data}
errors={errors}
onFieldChange={this.onFieldChange}
Expand All @@ -655,7 +648,7 @@ class Instance extends React.PureComponent<Props, State> {
/>
)}
</div>
{isEditing && (
{this.isEditing() && (
<Footer
onCancel={this.onCancel}
onRemove={this.onConfirmRemove}
Expand Down
5 changes: 4 additions & 1 deletion src/features/metadata-instance-editor/Instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { JSONPatchOperations } from '../../common/types/api';
type Props = {
editors?: Array<MetadataEditor>,
isCascadingPolicyApplicable?: boolean,
isFolderMetadata?: boolean,
onModification?: (id: string, isDirty: boolean) => void,
onRemove?: (id: string) => void,
onSave?: (
Expand All @@ -20,8 +21,9 @@ type Props = {
};

const Instances = ({
isCascadingPolicyApplicable = false,
editors = [],
isCascadingPolicyApplicable = false,
isFolderMetadata = false,
onModification,
onRemove,
onSave,
Expand All @@ -46,6 +48,7 @@ const Instances = ({
onSave={onSave}
onRemove={onRemove}
template={template}
isFolderMetadata={isFolderMetadata}
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Props = {
editors?: Array<MetadataEditor>,
isCascadingPolicyApplicable?: boolean,
isDropdownBusy?: boolean,
isFolderMetadata?: boolean,
onAdd?: (template: MetadataTemplate) => void,
onModification?: (id: string, isDirty: boolean) => void,
onRemove?: (id: string) => void,
Expand All @@ -37,6 +38,7 @@ const MetadataInstanceEditor = ({
canAdd,
isCascadingPolicyApplicable = false,
isDropdownBusy,
isFolderMetadata = false,
editors = [],
onModification,
onRemove,
Expand All @@ -63,6 +65,7 @@ const MetadataInstanceEditor = ({
<Instances
editors={editors}
isCascadingPolicyApplicable={isCascadingPolicyApplicable}
isFolderMetadata={isFolderMetadata}
onModification={onModification}
onRemove={onRemove}
onSave={onSave}
Expand Down
Loading
Loading