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

Pre prod to Main 0.6.2 #108

Merged
merged 14 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
module.exports = {
async up(knex) {
try {
const strapiInstance = global.strapi;
let result =[];
try {
result = await knex.raw('update governance_action_types set gov_action_type_name =\'Info Action\' where id = 1');
console.log("Update name Info to Info Action");
} catch (error) {
console.error('Error creating PK:', error);
}
try {
result = await knex.raw('update governance_action_types set gov_action_type_name =\'Treasury requests\' where id = 2');
console.log("Update name Treasury to Treasury requests");
} catch (error) {
console.error('Error creating PK:', error);
}
try {
result = await knex.raw('insert into governance_action_types values(3,\'Updates to the Constitution\',NOW(),NOW(),NOW(),1,1)');
console.log("Insert Updates to the Constitution with id 3.");
} catch (error) {
console.error('Error creating PK:', error);
}
console.log('Migration 20250502_2 completed!');
} catch (error) {
console.error('Error running migration:', error);
}
}
}
async up(knex) {
try {
// Check if the row with id = 1 exists and if the value needs to be updated
const row1 = await knex('governance_action_types')
.where({ id: 1 })
.first();

if (row1 && row1.gov_action_type_name !== 'Info Action') {
await knex('governance_action_types')
.where({ id: 1 })
.update({
gov_action_type_name: 'Info Action',
published_at: knex.fn.now() // Ensure published_at is set
});
console.log("Updated name 'Info' to 'Info Action' for id = 1 and set published_at.");
} else {
console.log("No update needed for id = 1. Value is already correct or row does not exist.");
}

// Check if the row with id = 2 exists and if the value needs to be updated
const row2 = await knex('governance_action_types')
.where({ id: 2 })
.first();

if (row2 && row2.gov_action_type_name !== 'Treasury requests') {
await knex('governance_action_types')
.where({ id: 2 })
.update({
gov_action_type_name: 'Treasury requests',
published_at: knex.fn.now() // Ensure published_at is set
});
console.log("Updated name 'Treasury' to 'Treasury requests' for id = 2 and set published_at.");
} else {
console.log("No update needed for id = 2. Value is already correct or row does not exist.");
}

// Check if the row with id = 3 already exists before inserting
const row3 = await knex('governance_action_types')
.where({ id: 3 })
.first();

if (!row3) {
await knex('governance_action_types').insert({
id: 3,
gov_action_type_name: 'Updates to the Constitution',
created_at: knex.fn.now(),
updated_at: knex.fn.now(),
published_at: knex.fn.now(), // Ensure published_at is set
created_by_id: 1,
updated_by_id: 1,
});
console.log("Inserted 'Updates to the Constitution' with id = 3 and set published_at.");
} else {
console.log("Row with id = 3 already exists. No insert needed.");
}

console.log('Migration 20250502_2 completed!');
} catch (error) {
console.error('Error running migration:', error);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
async up(knex) {
try {
// Check if the row with id = 4 already exists before inserting
const row3 = await knex('governance_action_types')
.where({ id: 4 })
.first();

if (!row3) {
await knex('governance_action_types').insert({
id: 3,
gov_action_type_name: 'Motion of No Confidence',
created_at: knex.fn.now(),
updated_at: knex.fn.now(),
published_at: knex.fn.now(), // Ensure published_at is set
created_by_id: 1,
updated_by_id: 1,
});
console.log("Inserted 'Motion of No Confidence' with id = 4 and set published_at.");
} else {
console.log("Row with id = 4 already exists. No insert needed.");
}

console.log('Migration 20252002_1 completed!');
} catch (error) {
console.error('Error running migration:', error);
}
},
};
9 changes: 9 additions & 0 deletions pdf-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
As a minor extension, we also keep a semantic version for the `UNRELEASED`
changes.

## [v0.6.2](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/0.6.2) 2025-02-19
### Fixed
- [Fix Inaccurate Validation and UI Issues in Constitution Type Proposal Form](https://github.com/IntersectMBO/govtool/issues/2965)
- [Fixed stucking After Deselecting Guardrails Script with Invalid URL](https://github.com/IntersectMBO/govtool/issues/2992)
- [Fixed reflection of Updated Constitution URL, Gradual Script Hash, and URL on Proposal Edit](https://github.com/IntersectMBO/govtool/issues/2967)
- [Added test IDs for PDF components](https://github.com/IntersectMBO/govtool/issues/2988)
- [Fixed Cursor Jumping to End & No Soft Line Breaks](https://github.com/IntersectMBO/govtool/issues/3019)


## [v0.6.1](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/0.6.1) 2025-02-12
### Fixed
- [Test ID for Sort Button](https://github.com/IntersectMBO/govtool/issues/2838)
Expand Down
2 changes: 1 addition & 1 deletion pdf-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pdf-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@intersect.mbo/pdf-ui",
"version": "0.6.1",
"version": "0.6.2",
"description": "Proposal discussion ui",
"main": "./src/index.js",
"exports": {
Expand Down
18 changes: 7 additions & 11 deletions pdf-ui/src/components/CommentCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,18 @@ const CommentCard = ({ comment, proposal }) => {
}
};

const handleKeyDown = (event) => {
if (event.key === 'Enter') {
event.preventDefault();
}
};

const handleChange = (event) => {
const handleChange = (event) => {
let value = event.target.value;
if (value.startsWith(' ')) {
value = value.trimStart();
}
value = value.replace(/ +/g, ' ');


if (value.length <= subcommentMaxLength) {
setSubcommentText(value);
}
};
const handleBlur = (event) => {
const cleanedValue = event.target.value.replace(/[^\S\n]+/g, ' ').trim();
setSubcommentText(cleanedValue);
};

useEffect(() => {
if (showSubcomments) {
Expand Down Expand Up @@ -391,6 +386,7 @@ const CommentCard = ({ comment, proposal }) => {
value={subcommentText || ''}
variant='outlined'
onChange={(e) => handleChange(e)}
onBlur={handleBlur}
inputProps={{
maxLength: subcommentMaxLength,
onKeyDown: handleKeyDown,
Expand Down
35 changes: 12 additions & 23 deletions pdf-ui/src/components/CreateGovernanceActionDialog/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,7 @@ const CreateGovernanceActionDialog = ({ open = false, onClose = false }) => {
setIsContinueDisabled(false);
}
}
if (proposalData?.gov_action_type_id==3){
if ((proposalData?.proposal_constitution_content?.prop_constitution_url =='')
||
constitutionErrors.prop_constitution_url
||
constitutionErrors.prop_guardrails_script_url
) {
return setIsContinueDisabled(true);
} else {
setIsContinueDisabled(false);
}
}

const selectedLabel = governanceActionTypes.find(
(option) => option?.value === proposalData?.gov_action_type_id
)?.label;
Expand All @@ -124,22 +113,22 @@ const CreateGovernanceActionDialog = ({ open = false, onClose = false }) => {
setIsContinueDisabled(false);
}
}
} else {
setIsContinueDisabled(false);
}
}
if (selectedType == 3){
if ((proposalData?.proposal_constitution_content?.prop_constitution_url =='')
||
constitutionErrors.prop_constitution_url
||
constitutionErrors.prop_guardrails_script_url
) {
if(!proposalData.proposal_constitution_content.prop_constitution_url || constitutionErrors.prop_constitution_url)
return setIsContinueDisabled(true);
} else {
if(proposalData.proposal_constitution_content.prop_have_guardrails_script)
{
if(constitutionErrors.prop_guardrails_script_url || constitutionErrors.prop_guardrails_script_hash)
return setIsContinueDisabled(true);
}
else {
setIsContinueDisabled(false);
}
}

else {
setIsContinueDisabled(false);
}
} else {
setIsContinueDisabled(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTheme } from '@emotion/react';
import { useEffect } from 'react';
import { Box, TextField, FormControlLabel, Checkbox } from '@mui/material';
import { isValidURLFormat } from '../../lib/utils';
import { isValidURLFormat,isValidURLLength } from '../../lib/utils';

const ConstitutionManager = ({
proposalData,
Expand All @@ -20,6 +20,8 @@ const ConstitutionManager = ({
pk.prop_guardrails_script_hash ="";
}
setProposalData({...proposalData, proposal_constitution_content: pk});
setConstitutionManagerErrors((prev) => ({...prev, ["prop_guardrails_script_url"] : null }));
setConstitutionManagerErrors((prev) => ({...prev, ["prop_guardrails_script_hash"] : null }));
};
const handleUrlChange = (url_text) => {
constcheckLinkValue(url_text,'prop_constitution_url');
Expand All @@ -33,27 +35,40 @@ const ConstitutionManager = ({
pk.prop_guardrails_script_url = url_text;
setProposalData({...proposalData, proposal_constitution_content: pk});
}

const handleHashChange = (hash_text) => {
// test hash value
constcheckHashValue(hash_text,"prop_guardrails_script_hash");
let pk = proposalData.proposal_constitution_content;
pk.prop_guardrails_script_hash = hash_text;
setProposalData({...proposalData, proposal_constitution_content: pk});
}
const constcheckLinkValue = (prop_value, prop_name) => {
const isValid = isValidURLFormat(prop_value);
const isValid1 = isValidURLLength(prop_value);
setConstitutionManagerErrors((prev) => ({
...prev,
[prop_name] :isValid ? false : 'Invalid URL format'}));
[prop_name] :isValid ? (isValid1 === true)? null: "Url longer than 128 char" : 'Invalid URL format'}));
}
const constcheckHashValue = (prop_value, prop_name) => {
let isValid = false;
if(prop_value)
isValid = prop_value?.length > 0 ? true : false;
setConstitutionManagerErrors((prev) => ({
...prev,
[prop_name] :isValid ? null : 'Invalid HASH value'}));
}

useEffect(() => {
let pk = proposalData.proposal_constitution_content;
if(pk != undefined)
{
console.log(pk);
if(Boolean(pk.prop_constitution_url))
constcheckLinkValue(pk.prop_constitution_url,'prop_constitution_url')
if(Boolean(pk.prop_guardrails_script_url))
{
constcheckLinkValue(pk.prop_guardrails_script_url,'prop_guardrails_script_url')
constcheckHashValue(pk.prop_guardrails_script_hash,"prop_guardrails_script_hash")
}
}
}, [proposalData]);
return (
Expand All @@ -77,7 +92,7 @@ const ConstitutionManager = ({
sx: {
backgroundColor: 'transparent',
},
'data-testid': `prop=constitution-url-text-error`,
'data-testid': `prop-constitution-url-text-error`,
}}
/>
</Box>
Expand Down Expand Up @@ -160,6 +175,14 @@ const ConstitutionManager = ({
inputProps={{
'data-testid': `prop-guardrails-script-hash-input`,
}}
error={!!constitutionManagerErrors?.prop_guardrails_script_hash}
helperText={constitutionManagerErrors?.prop_guardrails_script_hash}
FormHelperTextProps={{
sx: {
backgroundColor: 'transparent',
},
'data-testid': `prop-guardrails-script-hash-input-error`,
}}
/>
</Box>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion pdf-ui/src/components/CreationGoveranceAction/Step3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const Step3 = ({
</Box>
</Box>
)): null }
{selectedGATypeId === 3 && pc ? (
{selectedGATypeId == 3 && pc ? (
<Box>
<Box>
<Typography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
withdrawals: getWithdrawalsArray()
});
}
else if (parseInt(proposalGATypeId) === 3){
else if (parseInt(proposalGATypeId) === 3)
{
const constitUrl = proposal?.attributes?.content?.attributes.proposal_constitution_content.data.attributes.prop_constitution_url;
const constiUrlHash = await getHashFromUrl(constitUrl);
govActionBuilder =
Expand All @@ -150,8 +151,18 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
//prevGovernanceActionHash: string;
//prevGovernanceActionIndex: number;
//scriptHash: string;
});
}
});
}
else if(parseInt(proposalGATypeId) === 4)
{ ///Motion of No Confidence
govActionBuilder =
await walletAPI.buildNoConfidenceGovernanceAction({
hash: hashData,
url: fileURL,
});
}


if (govActionBuilder) {
const tx = await walletAPI.buildSignSubmitConwayCertTx({
govActionBuilder: govActionBuilder,
Expand Down
8 changes: 6 additions & 2 deletions pdf-ui/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
} from '@emurgo/cardano-serialization-lib-asmjs';

export const URL_REGEX =
/^(?:(?:https?:\/\/)?(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(?:\/[^\s]*)?)|(?:ipfs:\/\/(?:[a-zA-Z0-9]+(?:\/[a-zA-Z0-9._-]+)*))$|^$/;
/^(?:(?:https?:\/\/)?(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(?:\/[^\s]*)?)|(?:ipfs:\/\/(?:[a-zA-Z0-9]+(?:\/[a-zA-Z0-9._-]+)*))$/;

export const formatIsoDate = (isoDate) => {
export function isValidHashFormat(str) {
return "Not Implemented";
// const isValidHash = (hash) => !!bech32.decode(hash)?.words?.length
}
export const formatIsoDate = (isoDate) => {
if (!isoDate) return '';

return format(new Date(isoDate), 'd MMMM yyyy');
Expand Down
Loading