Skip to content

Commit

Permalink
Merge pull request #1432 from decentdao/feature/#1399-proposal-templa…
Browse files Browse the repository at this point in the history
…te-markdown

Implement markdown support for proposal templates and proposal view
  • Loading branch information
adamgall authored Mar 18, 2024
2 parents abd2889 + 49c1423 commit 5473d19
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# Create an environment file with sensitive information
- name: Create env file
working-directory: ./docker
run: echo NEXT_PUBLIC_ALCHEMY_TESTING_API_KEY=${{ secrets.NEXT_PUBLIC_ALCHEMY_TESTING_API_KEY }} >> .env.tests.local
run: echo VITE_APP_ALCHEMY_TESTING_API_KEY=${{ secrets.VITE_APP_ALCHEMY_TESTING_API_KEY }} >> .env.tests.local

# Set up Docker Buildx for building Docker images with cache support
- name: Set up Docker Buildx
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:

# Run the webapp Docker container
- name: Run webapp container
run: docker run -d --name webapp -p 3000:3000 -e NEXT_PUBLIC_TESTING_ENVIRONMENT=true -e NEXT_PUBLIC_LOCAL_CHAIN_ID=31337 -e NEXT_PUBLIC_LOCAL_PROVIDER_URL=http://0.0.0.0:8545 webapp:latest
run: docker run -d --name webapp -p 3000:3000 -e VITE_APP_TESTING_ENVIRONMENT=true -e VITE_APP_LOCAL_CHAIN_ID=31337 -e VITE_APP_LOCAL_PROVIDER_URL=http://0.0.0.0:8545 webapp:latest

# Remove existing package.json and package-lock.json, then create a new package.json
- name: remove package.json
Expand Down
2 changes: 1 addition & 1 deletion docker/.env.tests
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_ALCHEMY_TESTING_API_KEY=""
VITE_APP_ALCHEMY_TESTING_API_KEY=""
12 changes: 6 additions & 6 deletions docker/webapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM node:18.12.1

# Set build-time arguments
ARG NEXT_PUBLIC_TESTING_ENVIRONMENT
ARG NEXT_PUBLIC_LOCAL_CHAIN_ID
ARG NEXT_PUBLIC_LOCAL_PROVIDER_URL
ARG VITE_APP_TESTING_ENVIRONMENT
ARG VITE_APP_LOCAL_CHAIN_ID
ARG VITE_APP_LOCAL_PROVIDER_URL

# Set environment variables
ENV NEXT_PUBLIC_TESTING_ENVIRONMENT=$NEXT_PUBLIC_TESTING_ENVIRONMENT
ENV NEXT_PUBLIC_LOCAL_CHAIN_ID=$NEXT_PUBLIC_LOCAL_CHAIN_ID
ENV NEXT_PUBLIC_LOCAL_PROVIDER_URL=$NEXT_PUBLIC_LOCAL_PROVIDER_URL
ENV VITE_APP_TESTING_ENVIRONMENT=$VITE_APP_TESTING_ENVIRONMENT
ENV VITE_APP_LOCAL_CHAIN_ID=$VITE_APP_LOCAL_CHAIN_ID
ENV VITE_APP_LOCAL_PROVIDER_URL=$VITE_APP_LOCAL_PROVIDER_URL

# Set working directory
WORKDIR /fractal-webapp/
Expand Down
56 changes: 48 additions & 8 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"react-router-dom": "^6.22.0",
"react-toastify": "^9.0.8",
"remark-gfm": "^4.0.0",
"remove-markdown": "^0.5.0",
"viem": "^1.21",
"vite": "^5.1.0",
"vite-plugin-node-polyfills": "^0.21.0",
Expand Down Expand Up @@ -90,6 +91,7 @@
"@testing-library/react": "^14.2.1",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/remove-markdown": "^0.3.4",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@vitejs/plugin-react": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
timeout: 30 * 1000, // From https://github.com/vercel/next.js/blob/canary/examples/with-playwright/playwright.config.ts
timeout: 30 * 1000,
reporter: [
/* List reporter for getting updates */
[process.env.CI ? 'list' : 'line'],
Expand Down
File renamed without changes.
34 changes: 20 additions & 14 deletions src/components/Activity/ActivityDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Flex } from '@chakra-ui/react';
import { Activity, SnapshotProposal } from '../../types';
import SnapshotProposalDescription from '../Proposals/SnapshotProposalDetails/SnapshotProposalDescription';
import { Box, Flex } from '@chakra-ui/react';
import { useGetMetadata } from '../../hooks/DAO/proposal/useGetMetadata';
import { Activity, FractalProposal, SnapshotProposal } from '../../types';
import Markdown from '../ui/proposal/Markdown';
import { ProposalTitle } from './ActivityDescriptionGovernance';
import { ActivityDescriptionTreasury } from './ActivityDescriptionTreasury';

interface IActivityDescription {
activity: Activity;
showFullSnapshotDescription?: boolean;
showFullDescription?: boolean;
}

export function ActivityDescription({
activity,
showFullSnapshotDescription,
}: IActivityDescription) {
const snapshotProposalActivity = activity as SnapshotProposal;
export function ActivityDescription({ activity, showFullDescription }: IActivityDescription) {
const metaData = useGetMetadata(activity as FractalProposal);
const snapshotProposal = activity as SnapshotProposal;
const description = snapshotProposal.description || metaData.description;

return (
<Flex
color="grayscale.100"
Expand All @@ -23,11 +24,16 @@ export function ActivityDescription({
flexWrap="wrap"
>
<ProposalTitle activity={activity} />
{!!snapshotProposalActivity.snapshotProposalId && (
<SnapshotProposalDescription
truncate={!showFullSnapshotDescription}
proposal={snapshotProposalActivity}
/>
{description && (
<Box
my={4}
minWidth="100%"
>
<Markdown
content={description}
truncate={!showFullDescription}
/>
</Box>
)}
{!!activity.transaction && <ActivityDescriptionTreasury activity={activity} />}
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Activity/ActivityDescriptionGovernance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function ProposalTitle({ activity }: { activity: Activity }) {
return (
<>
<Text>{formatId((activity as GovernanceActivity).proposalId)}</Text>
<Text>{metaData.title || metaData.description}</Text>
{metaData.title ? <Text>{metaData.title}</Text> : null}
{hasTransfers && <Text> {t('proposalDescriptionCont', { ns: 'dashboard' })} </Text>}
<OnChainRejectionMessage activity={activity} />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Fragment, PropsWithChildren } from 'react';
import { useTranslation } from 'react-i18next';
import { BACKGROUND_SEMI_TRANSPARENT } from '../../constants/common';
import { CreateProposalTemplateForm } from '../../types/createProposalTemplate';
import LineBreakBlock from '../ui/utils/LineBreakBlock';
import Markdown from '../ui/proposal/Markdown';
import '../../assets/css/Markdown.css';

export function TransactionValueContainer({
children,
Expand Down Expand Up @@ -65,10 +66,9 @@ export default function ProposalTemplateDetails({
</HStack>
<HStack justifyContent="space-between">
<Text color="grayscale.500">{t('proposalTemplateDescription')}</Text>
<LineBreakBlock
textAlign="right"
wordBreak="break-word"
text={proposalTemplateMetadata.description?.trim()}
<Markdown
content={proposalTemplateMetadata.description}
collapsedLines={2}
/>
</HStack>
<Divider color="chocolate.700" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export default function ProposalTemplateMetadata({
/>
<TextareaComponent
label={t('proposalTemplateDescription')}
subLabel={t('')}
helper={t('proposalTemplateDescriptionHelperText')}
isRequired={false}
value={proposalTemplateMetadata.description}
onChange={e => setFieldValue('proposalTemplateMetadata.description', e.target.value)}
disabled={false}
rows={3}
maxLength={300}
rows={12}
/>
</VStack>
<Divider
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProposalCreate/ProposalMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function ProposalMetadata(props: AzoriusMetadataProps) {
onChange={e => setFieldValue('proposalMetadata.description', e.target.value)}
disabled={false}
placeholder={t('proposalDescriptionPlaceholder')}
rows={3}
rows={9}
/>
<InputComponent
label={t('proposalAdditionalResources')}
Expand Down
8 changes: 2 additions & 6 deletions src/components/ProposalTemplates/ProposalTemplateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ContentBox from '../ui/containers/ContentBox';
import { OptionMenu } from '../ui/menus/OptionMenu';
import { ModalType } from '../ui/modals/ModalProvider';
import { useFractalModal } from '../ui/modals/useFractalModal';
import Markdown from '../ui/proposal/Markdown';

type ProposalTemplateCardProps = {
proposalTemplate: ProposalTemplate;
Expand Down Expand Up @@ -122,12 +123,7 @@ export default function ProposalTemplateCard({
>
{title}
</Text>
<Text
textStyle="text-sm-mono-regular"
color="grayscale.100"
>
{description}
</Text>
<Markdown content={description} />
</ContentBox>
);
}
10 changes: 1 addition & 9 deletions src/components/Proposals/ProposalInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,8 @@ export function ProposalInfo({
<Box mt={4}>
<ActivityDescription
activity={proposal}
showFullSnapshotDescription
showFullDescription
/>
{!isSnapshotProposal && (
<Text
my={4}
whiteSpace="break-spaces"
>
{metaData.description}
</Text>
)}
{metaData.documentationUrl && (
<Text
onClick={confirmUrl}
Expand Down
15 changes: 13 additions & 2 deletions src/components/ui/forms/InputComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GridItem,
GridProps,
GridItemProps,
ResponsiveValue,
} from '@chakra-ui/react';
import { LabelWrapper } from '@decent-org/fractal-ui';
import { BigNumberInput, BigNumberInputProps } from './BigNumberInput';
Expand Down Expand Up @@ -43,6 +44,7 @@ interface TextareaProps extends Omit<BaseProps, 'children'> {
onChange: React.ChangeEventHandler<HTMLTextAreaElement> | undefined;
placeholder?: string;
rows?: number;
resize?: ResponsiveValue<'vertical' | 'horizontal' | 'both' | 'none'>;
}
interface BigNumberProps
extends Omit<BaseProps, 'children' | 'value'>,
Expand Down Expand Up @@ -142,15 +144,24 @@ export function EthAddressComponent(props: EthAddressProps) {
}

export function TextareaComponent(props: TextareaProps) {
const { id, value, disabled, onChange, rows, placeholder, maxLength } = props;
const {
id,
value,
disabled,
onChange,
rows,
placeholder,
maxLength,
resize = 'vertical',
} = props;
return (
<LabelComponent
{...props}
disabled={disabled}
>
<Textarea
id={id}
resize="none"
resize={resize}
onChange={onChange}
value={value}
isDisabled={disabled}
Expand Down
Loading

0 comments on commit 5473d19

Please sign in to comment.