Skip to content

Commit

Permalink
fix json policy serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Oct 16, 2020
1 parent 7da30bd commit 7f48a65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ import { SerializedPolicy } from '../../../../../common/types';
import { useFormContext } from '../../../../shared_imports';

interface Props {
legacyPolicy: SerializedPolicy;
close: () => void;
policyName: string;
}

export const PolicyJsonFlyout: React.FunctionComponent<Props> = ({ policyName, close }) => {
export const PolicyJsonFlyout: React.FunctionComponent<Props> = ({
policyName,
close,
legacyPolicy,
}) => {
/**
* policy === undefined: we are checking validity
* policy === null: we have determined the policy is invalid
Expand All @@ -45,13 +50,20 @@ export const PolicyJsonFlyout: React.FunctionComponent<Props> = ({ policyName, c
const subscription = form.subscribe(async (formUpdate) => {
setPolicy(undefined);
if (await formUpdate.validate()) {
setPolicy(formUpdate.data.format());
const p = formUpdate.data.format() as SerializedPolicy;
setPolicy({
...legacyPolicy,
phases: {
...legacyPolicy.phases,
hot: p.phases.hot,
},
});
} else {
setPolicy(null);
}
});
return subscription.unsubsribe;
}, [form]);
return subscription.unsubscribe;
}, [form, legacyPolicy]);

let content: React.ReactNode;
switch (policy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
{isShowingPolicyJsonFlyout ? (
<PolicyJsonFlyout
policyName={policy.name || ''}
legacyPolicy={legacySerializePolicy(policy, existingPolicy?.policy)}
close={() => setIsShowingPolicyJsonFlyout(false)}
/>
) : null}
Expand Down

0 comments on commit 7f48a65

Please sign in to comment.