Skip to content

Commit

Permalink
Improved layout of project searched items, started implementing searc…
Browse files Browse the repository at this point in the history
…h header, implemented edit route (not editing yet), implemented gql mutation for deleting projects (no deleting yet)
  • Loading branch information
zachsa committed Jun 7, 2021
1 parent c995a46 commit 2e748b2
Show file tree
Hide file tree
Showing 22 changed files with 356 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Set project and all child entities to have deletedAt = new Date()... etc.
* return the project
*/

// eslint-disable-next-line
export default async (_, args, ctx) => {
throw new Error('TODO')
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default ({ fields, table, ids, vocabularyFilters }) => {
})
.join('\n')}
where
where [${table}].deletedAt is null and
${ids.length ? `[${table}].id in (${ids.join(',')})` : '1 = 1'}
${vocabularyFilters.length ? 'and ' : ''}
${vocabularyFilters
Expand Down
4 changes: 3 additions & 1 deletion src/api/src/graphql/resolvers/types/mutation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import createProject from '../mutations/create-project/index.js'
import updateProject from '../mutations/update-project.js'
import updateProject from '../mutations/update-project/index.js'
import deleteProject from '../mutations/delete-project/index.js'
import updateVocabulary from '../mutations/update-vocabulary/index.js'
import integrateOldDb from '../mutations/integrate-old-db/index.js'

Expand All @@ -8,4 +9,5 @@ export default {
updateProject,
updateVocabulary,
integrateOldDb,
deleteProject,
}
1 change: 1 addition & 0 deletions src/api/src/graphql/schema/type-defs/main.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ type Mutation {
mitigationForms: [MitigationInput!]
adaptationForms: [AdaptationInput!]
): Project!
deleteProject(id: ID!): Project
}
14 changes: 10 additions & 4 deletions src/api/src/mssql/setup-db/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ create table Projects (
alternativeContact nvarchar(255),
alternativeContactEmail nvarchar(255),
leadAgent nvarchar(255),
deletedAt date,
interventionType int foreign key references VocabularyXrefTree (id),
projectStatus int foreign key references VocabularyXrefTree (id),
validationStatus int foreign key references VocabularyXrefTree (id),
Expand All @@ -195,7 +196,7 @@ create table Projects (
hostSubSector int foreign key references VocabularyXrefTree (id),
province int foreign key references VocabularyXrefTree (id),
districtMunicipality int foreign key references VocabularyXrefTree (id),
localMunicipality int foreign key references VocabularyXrefTree (id)
localMunicipality int foreign key references VocabularyXrefTree (id)
);
end

Expand Down Expand Up @@ -228,6 +229,7 @@ create table Mitigations (
researchTargetAudience nvarchar(255),
researchAuthor nvarchar(255),
researchPaper nvarchar(255),
deletedAt date,
energyOrEmissionsData int foreign key references VocabularyXrefTree (id),
mitigationType int foreign key references VocabularyXrefTree (id),
mitigationSubType int foreign key references VocabularyXrefTree (id),
Expand Down Expand Up @@ -256,7 +258,8 @@ create table EnergyData (
year int not null,
annualKwh int not null default 0,
annualKwhPurchaseReduction int not null default 0,
notes nvarchar(4000) null
notes nvarchar(4000) null,
deletedAt date
);
end

Expand All @@ -274,7 +277,8 @@ create table EmissionsData (
mitigationId int not null foreign key references Mitigations (id),
emissionType int not null foreign key references VocabularyXrefTree (id),
year int not null,
notes nvarchar(4000) null
notes nvarchar(4000) null,
deletedAt date
);
end

Expand All @@ -291,7 +295,8 @@ create table EmissionsDataXrefVocabTreeX (
id int not null identity primary key,
emissionsDataId int not null foreign key references EmissionsData (id),
chemical int not null foreign key references VocabularyXrefTree (id),
tonnesPerYear int not null
tonnesPerYear int not null,
deletedAt date
);
end

Expand All @@ -318,6 +323,7 @@ create table Adaptations (
researchTargetAudience nvarchar(255),
researchAuthor nvarchar(255),
researchPaper nvarchar(255),
deletedAt date,
interventionStatus int foreign key references VocabularyXrefTree (id),
adaptationSector int foreign key references VocabularyXrefTree (id),
adaptationPurpose int foreign key references VocabularyXrefTree (id),
Expand Down
4 changes: 4 additions & 0 deletions src/client/src/layout/header/appbar/breadcrumbs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Breadcrumbs from '@material-ui/core/Breadcrumbs'
import { Link, useLocation } from 'react-router-dom'
import MuiLink from '@material-ui/core/Link'
import navItems from './nav-items'
import EditIcon from 'mdi-react/EditIcon'

const useStyles = makeStyles(theme => ({
link: {
Expand Down Expand Up @@ -41,6 +42,9 @@ export default function IconBreadcrumbs() {
})}

{tree.slice(-1).map(({ label, Icon } = {}) => {
if (label === 'Edit') {
Icon = EditIcon
}
return (
<Typography key={label} color="textPrimary" className={classes.link}>
{Icon && <Icon className={classes.icon} />}
Expand Down
13 changes: 13 additions & 0 deletions src/client/src/layout/routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const HomePage = lazy(() => import('../../pages/home'))
const AccessPage = lazy(() => import('../../pages/access'))
const ProjectsPage = lazy(() => import('../../pages/projects'))
const ProjectPage = lazy(() => import('../../pages/project'))
const EditProjectPage = lazy(() => import('../../pages/edit-project'))
const SubmitProjectPage = lazy(() => import('../../pages/submit-project'))
const DeploymentsPage = lazy(() => import('../../pages/deployments'))

Expand Down Expand Up @@ -60,6 +61,18 @@ export default withRouter(() => {
)}
/>

{/* EDIT PROJECT */}
<Route
key={'edit-project'}
path={'/projects/:id/edit'}
exact
render={props => (
<Transition tKey="edit-project">
<EditProjectPage id={props.match.params.id} {...props} />
</Transition>
)}
/>

{/* PROJECT */}
<Route
key={'project'}
Expand Down
114 changes: 114 additions & 0 deletions src/client/src/pages/edit-project/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { useQuery, gql } from '@apollo/client'
import Loading from '../../components/loading'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import useTheme from '@material-ui/core/styles/useTheme'

export default ({ id }) => {
const theme = useTheme()
const { error, loading, data } = useQuery(
gql`
query projects($ids: [Int!]) {
projects(ids: $ids) {
id
title
description
projectManager
link
startDate
endDate
validationComments
fundingOrganisation
fundingPartner
budgetLower
budgetUpper
hostOrganisation
hostPartner
alternativeContact
alternativeContactEmail
leadAgent
interventionType
projectStatus
validationStatus
fundingStatus
estimatedBudget
hostSector
hostSubSector
province
districtMunicipality
localMunicipality
mitigations {
id
title
description
carbonCredit
volMethodology
goldStandard
vcs
yx
otherCarbonCreditStandard
otherCarbonCreditStandardDescription
cdmProjectNumber
cdmStatus
isResearch
researchDescription
energyOrEmissionsData
energyData
emissionsData
researchType
researchTargetAudience
researchAuthor
researchPaper
mitigationType
mitigationSubType
interventionStatus
cdmMethodology
cdmExecutiveStatus
hostSector
hostSubSectorPrimary
hostSubSectorSecondary
}
adaptations {
id
title
description
startDate
endDate
yx
isResearch
interventionStatus
researchDescription
researchType
researchTargetAudience
researchAuthor
researchPaper
adaptationSector
adaptationPurpose
hazardFamily
hazardSubFamily
hazard
subHazard
}
}
}
`,
{ variables: { ids: [parseInt(id, 10)] } }
)

if (loading) {
return <Loading />
}

if (error) {
throw error
}

return (
<Card style={{ backgroundColor: theme.backgroundColor }} variant="outlined">
<CardContent>
<h1>Edit page</h1>
<pre>{JSON.stringify(data, null, 2)}</pre>
</CardContent>
</Card>
)
}
47 changes: 1 addition & 46 deletions src/client/src/pages/projects/context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ export default ({ children }) => {
id
title
description
projectManager
link
startDate
endDate
validationComments
fundingOrganisation
fundingPartner
budgetLower
budgetUpper
hostOrganisation
hostPartner
alternativeContact
alternativeContactEmail
leadAgent
interventionType
projectStatus
validationStatus
Expand All @@ -82,26 +68,6 @@ export default ({ children }) => {
localMunicipality
mitigations {
id
title
description
carbonCredit
volMethodology
goldStandard
vcs
yx
otherCarbonCreditStandard
otherCarbonCreditStandardDescription
cdmProjectNumber
cdmStatus
isResearch
researchDescription
energyOrEmissionsData
energyData
emissionsData
researchType
researchTargetAudience
researchAuthor
researchPaper
mitigationType
mitigationSubType
interventionStatus
Expand All @@ -113,20 +79,9 @@ export default ({ children }) => {
}
adaptations {
id
title
description
startDate
endDate
yx
isResearch
interventionStatus
researchDescription
researchType
researchTargetAudience
researchAuthor
researchPaper
adaptationSector
adaptationPurpose
interventionStatus
hazardFamily
hazardSubFamily
hazard
Expand Down
16 changes: 16 additions & 0 deletions src/client/src/pages/projects/header/_download-data.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import DownloadIcon from 'mdi-react/DownloadIcon'
import Button from '@material-ui/core/Button'

export default () => {
return (
<Button
disableElevation
size="small"
variant="contained"
color="primary"
startIcon={<DownloadIcon size={18} />}
>
Download data
</Button>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ export default ({ Filters, filters }) => {
<>
<Drawer
id="mobile-filters-menu"
PaperProps={{ style: { maxWidth: '100%' } }}
anchor="right"
PaperProps={{ style: { width: '100%' } }}
anchor="left"
open={showSidebar}
onOpen={() => setShowSidebar(true)}
onClose={() => setShowSidebar(false)}
>
<Grid item xs={12}>
<IconButton aria-label="Toggle search filters" onClick={() => setShowSidebar(false)}>
<CloseIcon />
</IconButton>
<Filters filters={filters} />
<Grid container>
<Grid item xs={12} style={{ display: 'flex', justifyContent: 'flex-end' }}>
<IconButton aria-label="Toggle search filters" onClick={() => setShowSidebar(false)}>
<CloseIcon />
</IconButton>
</Grid>
<Grid item xs={12}>
<Filters filters={filters} />
</Grid>
</Grid>
</Drawer>
<IconButton onClick={() => setShowSidebar(true)} size="small">
Expand Down
19 changes: 19 additions & 0 deletions src/client/src/pages/projects/header/_submit-project.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import SubmitIcon from 'mdi-react/DatabasePlusIcon'
import Button from '@material-ui/core/Button'
import { Link } from 'react-router-dom'

export default () => {
return (
<Button
component={Link}
to="/projects/submission"
disableElevation
size="small"
variant="contained"
color="primary"
startIcon={<SubmitIcon size={18} />}
>
Submit project
</Button>
)
}
Loading

0 comments on commit 2e748b2

Please sign in to comment.