feat(governance): avoid showing untitled proposals (#3851)

This commit is contained in:
Sam Keen 2023-05-19 16:19:28 +01:00 committed by GitHub
parent ff3519279d
commit 5bd18cc127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 9 deletions

View File

@ -124,7 +124,7 @@ describe('Proposal header', () => {
}) })
); );
expect(screen.getByTestId('proposal-title')).toHaveTextContent( expect(screen.getByTestId('proposal-title')).toHaveTextContent(
'Unknown proposal' 'New asset proposal'
); );
expect(screen.getByTestId('proposal-type')).toHaveTextContent('New asset'); expect(screen.getByTestId('proposal-type')).toHaveTextContent('New asset');
expect(screen.getByTestId('proposal-details')).toHaveTextContent( expect(screen.getByTestId('proposal-details')).toHaveTextContent(

View File

@ -21,6 +21,7 @@ export const ProposalHeader = ({
let details: ReactNode; let details: ReactNode;
let proposalType = ''; let proposalType = '';
let fallbackTitle = '';
const title = proposal?.rationale.title.trim(); const title = proposal?.rationale.title.trim();
@ -29,6 +30,7 @@ export const ProposalHeader = ({
switch (change?.__typename) { switch (change?.__typename) {
case 'NewMarket': { case 'NewMarket': {
proposalType = 'NewMarket'; proposalType = 'NewMarket';
fallbackTitle = t('NewMarketProposal');
details = ( details = (
<> <>
<span> <span>
@ -50,6 +52,7 @@ export const ProposalHeader = ({
} }
case 'UpdateMarket': { case 'UpdateMarket': {
proposalType = 'UpdateMarket'; proposalType = 'UpdateMarket';
fallbackTitle = t('UpdateMarketProposal');
details = ( details = (
<> <>
<span>{t('Market change')}:</span>{' '} <span>{t('Market change')}:</span>{' '}
@ -60,6 +63,7 @@ export const ProposalHeader = ({
} }
case 'NewAsset': { case 'NewAsset': {
proposalType = 'NewAsset'; proposalType = 'NewAsset';
fallbackTitle = t('NewAssetProposal');
details = ( details = (
<> <>
<span>{t('Symbol')}:</span> <Lozenge>{change.symbol}.</Lozenge>{' '} <span>{t('Symbol')}:</span> <Lozenge>{change.symbol}.</Lozenge>{' '}
@ -81,6 +85,7 @@ export const ProposalHeader = ({
} }
case 'UpdateNetworkParameter': { case 'UpdateNetworkParameter': {
proposalType = 'NetworkParameter'; proposalType = 'NetworkParameter';
fallbackTitle = t('NetworkParameterProposal');
details = ( details = (
<> <>
<span>{t('Change')}:</span>{' '} <span>{t('Change')}:</span>{' '}
@ -95,11 +100,13 @@ export const ProposalHeader = ({
} }
case 'NewFreeform': { case 'NewFreeform': {
proposalType = 'Freeform'; proposalType = 'Freeform';
fallbackTitle = t('FreeformProposal');
details = <span />; details = <span />;
break; break;
} }
case 'UpdateAsset': { case 'UpdateAsset': {
proposalType = 'UpdateAsset'; proposalType = 'UpdateAsset';
fallbackTitle = t('UpdateAssetProposal');
details = ( details = (
<> <>
<span>{t('AssetID')}:</span>{' '} <span>{t('AssetID')}:</span>{' '}
@ -115,10 +122,14 @@ export const ProposalHeader = ({
<div data-testid="proposal-title"> <div data-testid="proposal-title">
{isListItem ? ( {isListItem ? (
<header> <header>
<SubHeading title={titleContent || t('Unknown proposal')} /> <SubHeading
title={titleContent || fallbackTitle || t('Unknown proposal')}
/>
</header> </header>
) : ( ) : (
<Heading title={titleContent || t('Unknown proposal')} /> <Heading
title={titleContent || fallbackTitle || t('Unknown proposal')}
/>
)} )}
</div> </div>

View File

@ -49,6 +49,7 @@ export const ProposeFreeform = () => {
formState: { errors }, formState: { errors },
setValue, setValue,
watch, watch,
trigger,
} = useForm<FreeformProposalFormFields>(); } = useForm<FreeformProposalFormFields>();
const { finalizedProposal, submit, Dialog } = useProposalSubmit(); const { finalizedProposal, submit, Dialog } = useProposalSubmit();
@ -85,7 +86,13 @@ export const ProposeFreeform = () => {
await submit(assembleProposal(fields)); await submit(assembleProposal(fields));
}; };
const viewJson = () => { const viewJson = async () => {
const isValid = await trigger();
if (!isValid) {
return;
}
const formData = watch(); const formData = watch();
downloadJson( downloadJson(
JSON.stringify(assembleProposal(formData)), JSON.stringify(assembleProposal(formData)),

View File

@ -89,6 +89,7 @@ export const ProposeNetworkParameter = () => {
formState: { errors }, formState: { errors },
setValue, setValue,
watch, watch,
trigger,
} = useForm<NetworkParameterProposalFormFields>(); } = useForm<NetworkParameterProposalFormFields>();
const { finalizedProposal, submit, Dialog } = useProposalSubmit(); const { finalizedProposal, submit, Dialog } = useProposalSubmit();
@ -148,7 +149,13 @@ export const ProposeNetworkParameter = () => {
await submit(assembleProposal(fields)); await submit(assembleProposal(fields));
}; };
const viewJson = () => { const viewJson = async () => {
const isValid = await trigger();
if (!isValid) {
return;
}
const formData = watch(); const formData = watch();
downloadJson( downloadJson(
JSON.stringify(assembleProposal(formData)), JSON.stringify(assembleProposal(formData)),

View File

@ -61,6 +61,7 @@ export const ProposeNewAsset = () => {
formState: { errors }, formState: { errors },
setValue, setValue,
watch, watch,
trigger,
} = useForm<NewAssetProposalFormFields>(); } = useForm<NewAssetProposalFormFields>();
const { finalizedProposal, submit, Dialog } = useProposalSubmit(); const { finalizedProposal, submit, Dialog } = useProposalSubmit();
@ -117,7 +118,13 @@ export const ProposeNewAsset = () => {
await submit(assembleProposal(fields)); await submit(assembleProposal(fields));
}; };
const viewJson = () => { const viewJson = async () => {
const isValid = await trigger();
if (!isValid) {
return;
}
const formData = watch(); const formData = watch();
downloadJson( downloadJson(
JSON.stringify(assembleProposal(formData)), JSON.stringify(assembleProposal(formData)),

View File

@ -59,6 +59,7 @@ export const ProposeNewMarket = () => {
formState: { errors }, formState: { errors },
setValue, setValue,
watch, watch,
trigger,
} = useForm<NewMarketProposalFormFields>(); } = useForm<NewMarketProposalFormFields>();
const { finalizedProposal, submit, Dialog } = useProposalSubmit(); const { finalizedProposal, submit, Dialog } = useProposalSubmit();
@ -107,7 +108,13 @@ export const ProposeNewMarket = () => {
await submit(assembleProposal(fields)); await submit(assembleProposal(fields));
}; };
const viewJson = () => { const viewJson = async () => {
const isValid = await trigger();
if (!isValid) {
return;
}
const formData = watch(); const formData = watch();
downloadJson( downloadJson(
JSON.stringify(assembleProposal(formData)), JSON.stringify(assembleProposal(formData)),

View File

@ -59,6 +59,7 @@ export const ProposeUpdateAsset = () => {
formState: { errors }, formState: { errors },
setValue, setValue,
watch, watch,
trigger,
} = useForm<UpdateAssetProposalFormFields>(); } = useForm<UpdateAssetProposalFormFields>();
const { finalizedProposal, submit, Dialog } = useProposalSubmit(); const { finalizedProposal, submit, Dialog } = useProposalSubmit();
@ -107,7 +108,13 @@ export const ProposeUpdateAsset = () => {
await submit(assembleProposal(fields)); await submit(assembleProposal(fields));
}; };
const viewJson = () => { const viewJson = async () => {
const isValid = await trigger();
if (!isValid) {
return;
}
const formData = watch(); const formData = watch();
downloadJson( downloadJson(
JSON.stringify(assembleProposal(formData)), JSON.stringify(assembleProposal(formData)),

View File

@ -106,6 +106,7 @@ export const ProposeUpdateMarket = () => {
formState: { errors }, formState: { errors },
setValue, setValue,
watch, watch,
trigger,
} = useForm<UpdateMarketProposalFormFields>(); } = useForm<UpdateMarketProposalFormFields>();
const { finalizedProposal, submit, Dialog } = useProposalSubmit(); const { finalizedProposal, submit, Dialog } = useProposalSubmit();
@ -157,7 +158,13 @@ export const ProposeUpdateMarket = () => {
await submit(assembleProposal(fields)); await submit(assembleProposal(fields));
}; };
const viewJson = () => { const viewJson = async () => {
const isValid = await trigger();
if (!isValid) {
return;
}
const formData = watch(); const formData = watch();
downloadJson( downloadJson(
JSON.stringify(assembleProposal(formData)), JSON.stringify(assembleProposal(formData)),