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

Feature/dao-action-page DAO-283 #478

Merged
merged 20 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
60f82a4
added basic daoSideCard
Fabricevladimir Sep 10, 2021
a6cf312
modified sidecard, added actionlinks
Fabricevladimir Sep 14, 2021
0cd86d6
Action Header added
sepehr2github Sep 14, 2021
a865227
searchbox and dropdown menu added to action page
sepehr2github Sep 14, 2021
4e64366
Action card added
sepehr2github Sep 15, 2021
30efa8f
Added basic calls for actions
Fabricevladimir Sep 15, 2021
fac256d
added help component on for settings page
Fabricevladimir Sep 16, 2021
118b22d
add load more button
sepehr2github Sep 16, 2021
1220c39
fix conflict
sepehr2github Sep 16, 2021
cbe3112
actions list logic added & actions filter added
sepehr2github Sep 17, 2021
56e3f54
search login implemented
sepehr2github Sep 17, 2021
a4abc9a
Human readable date format added & load more button logic added
sepehr2github Sep 19, 2021
5236b9a
fix action cards title overlaping
sepehr2github Sep 20, 2021
9486d57
fix single action card bugs & add no action available message
sepehr2github Sep 24, 2021
59012c5
Merge branch 'refactoring_finance' into feature/dao-action-page
sepehr2github Sep 24, 2021
ada0537
fix prettier error for setting route
sepehr2github Sep 24, 2021
525668d
change filter function & add no-available function & change limit to 100
sepehr2github Sep 27, 2021
dc80e25
add rejected status to dropdown menu and use same array for selected …
sepehr2github Sep 27, 2021
8d260e3
fix conflicts
sepehr2github Sep 29, 2021
dfb90f4
Merge branch 'refactoring_finance' into feature/dao-action-page
sepehr2github Sep 29, 2021
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
3 changes: 2 additions & 1 deletion packages/govern-console/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2
"tabWidth": 2,
"endOfLine":"auto"
}
2 changes: 1 addition & 1 deletion packages/govern-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@apollo/client": "^3.3.14",
"@aragon/govern": "^1.0.0-beta.12",
"@aragon/ui": "https://github.com/aragon/ui.git#v2",
"@aragon/ui": "https://github.com/aragon/ui#v2",
"@date-io/moment": "^1.3.13",
"@elastic/apm-rum-react": "^1.3.1",
"@material-ui/core": "^4.11.3",
Expand Down
181 changes: 181 additions & 0 deletions packages/govern-console/src/containers/DAO/DaoActionPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import React, { useState } from 'react';
import { DropDown, Button, GU, SearchInput, IconDown, Grid, GridItem, useLayout } from '@aragon/ui';
import styled from 'styled-components';
import { useHistory } from 'react-router-dom';

import DaoActionCard from './components/DaoActionCard/DaoActionCard';
import NoActionAvailable from './components/NoActionAvailable/NoActionAvailable';

type actionsType = {
__typename?: string;
id: string;
state: string;
createdAt: string;
payload: {
__typename?: string;
id: string;
executionTime: string;
title: string;
};
}[];

type props = {
fetchMore: () => Promise<void>;
actions: actionsType;
isMore: boolean;
identifier: string;
};

const Container = styled.div`
margin-top: ${3 * GU}px;
`;

const HeaderContainer = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-bottom: ${3 * GU}px;
`;

const Title = styled.div`
font-weight: 600;
font-size: 28px;
line-height: 125%;
`;

const SearchContainer = styled.div`
display: flex;
align-items: center;
width: 100%;
margin-bottom: ${3 * GU}px;
`;

const CustomActionButton = styled(Button)`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 12px 24px;
width: 134px;
height: 44px;
border-radius: 12px;
box-shadow: none;
`;

const LoadMoreButton = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 12px 24px;
width: 154px;
height: 44px;
border-radius: 12px;
color: #7483ab;
background: #ffffff;
box-shadow: none;
cursor: pointer;
& > svg {
padding-left: 2px;
}
`;

const ActionListContainer = styled.div`
width: 100%;
margin-bottom: ${3 * GU}px;
`;

const DaoActionsPage: React.FC<props> = ({ fetchMore, actions, isMore, identifier }) => {
const history = useHistory();
const [selected, setSelected] = useState<number>(0);
const [value, setValue] = useState<string>('');
const actionStates = [
'All Actions',
'Executable',
'Scheduled',
'Challenged',
'Executed',
'Rejected',
'Ruled Negatively',
];

const FilterState = (data: actionsType[0]) => {
return selected > 0 ? actionStates[selected] === data.state : true;
};

const SearchAction = (data: actionsType[0]) => {
const re = new RegExp(value, 'i');
if (data.payload.title?.match(re) || value === '') return data;
};

const RenderActions = (actions: actionsType) => {
const { layoutName } = useLayout();
const temp: React.ReactElement[] = [];
if (actions) {
actions
.filter((data) => FilterState(data)) // Filter Based on status
.filter((data) => SearchAction(data)) // search among vidible Actions
.map((data, index: number) => {
temp.push(
<GridItem
gridColumn={layoutName === 'medium' ? '1/-1' : index % 2 === 0 ? '1/3' : '3/5'}
>
<DaoActionCard
key={index}
date={data.createdAt}
state={data.state}
title={data.payload.title}
/>
</GridItem>,
);
});
if (temp.length === 0) return <NoActionAvailable />;
return temp;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified by creating a functional Component for NoAvailableAction

} else return <div>Loading...</div>;
};

const goToNewExecution = () => {
history.push(`/daos/${identifier}/actions/new-execution`);
};

return (
<Container>
<HeaderContainer>
<Title>Actions</Title>
<CustomActionButton label="New action" onClick={goToNewExecution} />
</HeaderContainer>
<SearchContainer>
<DropDown
items={actionStates}
css={`
border: none;
`}
selected={selected}
onChange={setSelected}
/>
<SearchInput
css={`
width: 100%;
margin-left: ${3 * GU}px;
border-radius: 12px;
`}
onChange={(text: string) => setValue(text)}
placeholder="Type to search..."
wide={true}
/>
</SearchContainer>
<ActionListContainer>
<Grid column={'4'}>{RenderActions(actions)}</Grid>
</ActionListContainer>
{isMore && (
<LoadMoreButton onClick={fetchMore}>
<span>Load more</span>
<IconDown />
</LoadMoreButton>
)}
</Container>
);
};

export default DaoActionsPage;
36 changes: 33 additions & 3 deletions packages/govern-console/src/containers/DAO/DaoHomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { Grid, GridItem, GU, useLayout } from '@aragon/ui';
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
import { Redirect, Switch, useHistory, useLocation, useParams, useRouteMatch } from 'react-router';

import NoDaoFound from './NoDaoFound';
import DaoSideCard from './components/DaoSideCard/DaoSideCard';
import NewExecution from 'containers/NewExecution/NewExecution';
import HelpComponent from 'components/HelpComponent/HelpComponent';
import ProposalDetails from 'containers/ProposalDetails/ProposalDetails';
import { useDaoQuery, useLazyProposalListQuery } from 'hooks/query-hooks';

import DaoActionsPage from './DaoActionPage';
const DaoSettings = lazy(() => import('containers/DAOSettings/DAOSettings'));

const StyledGridItem = styled(GridItem)<{ paddingTop: string }>`
Expand All @@ -32,13 +33,16 @@ const DaoHomePage: React.FC = () => {
* State
*/
const [daoExists, setDaoExists] = useState<boolean>(true);
const [IsMoreActions, setIsMoreActions] = useState<boolean>(false);
const [daoDetails, setDaoDetails] = useState<any>();
const [queueNonce, setQueueNonce] = useState<number>();
const [visibleActions, setVisibleActions] = useState<any>([]);

/**
* Effects
*/
const { data: dao, loading: daoIsLoading } = useDaoQuery(daoName);
const { getQueueData, data: queueData } = useLazyProposalListQuery();
const { getQueueData, data: queueData, fetchMore } = useLazyProposalListQuery();

/**
* Update state and get queue data
Expand All @@ -63,6 +67,19 @@ const DaoHomePage: React.FC = () => {
}
}, [daoIsLoading, dao, getQueueData]);

/**
* Functions
*/
const fetchMoreData = async () => {
if (fetchMore) {
fetchMore({
variables: {
offset: visibleActions.length,
},
});
}
};

/**
* Update visible proposals
*/
Expand All @@ -72,6 +89,12 @@ const DaoHomePage: React.FC = () => {
}
}, [queueData]);

useEffect(() => {
if (queueNonce && visibleActions.length) {
setIsMoreActions(queueNonce !== visibleActions.length);
} else setIsMoreActions(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how queueNonce is related to isMoreActions, please explain.

}, [queueNonce, visibleActions]);

/**
* Render
*/
Expand Down Expand Up @@ -100,7 +123,14 @@ const DaoHomePage: React.FC = () => {
<ApmRoute
exact
path={`${path}actions`}
render={() => <div>Actions Component goes here...</div>}
render={() => (
<DaoActionsPage
fetchMore={fetchMoreData}
actions={visibleActions}
isMore={IsMoreActions}
identifier={daoName}
/>
)}
/>
<ApmRoute
exact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ const StyledDiv = styled(NavLink)`
height: 48px;
padding: 8px 12px;
border-radius: 12px;

font-size: 16px;
color: #7483ab;
line-height: 20px;
font-weight: 600;
text-decoration: none;

/* Active */
&.active {
color: #00c2ff;
Expand Down
Loading