-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
282 on opportunities page data pipeline + companies + people is fetch…
…ed from be (#285) * feature: get pipelines columns from backend * feature: display item not found instead of crashing * feature: add BoardCard component * feature: display items from the backend * refactor: extract useBoard in a hook * refactor: export only loading and error from useBoard * refactor: create var pipelineStage * feature: implement support for Company boards
- Loading branch information
Showing
7 changed files
with
166 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const BoardCard = styled.p` | ||
color: ${(props) => props.theme.text80}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
GetCompaniesQuery, | ||
GetPeopleQuery, | ||
useGetCompaniesQuery, | ||
useGetPeopleQuery, | ||
useGetPipelinesQuery, | ||
} from '../../../generated/graphql'; | ||
import { BoardItemKey, Column, Items } from '../../ui/components/board/Board'; | ||
|
||
type Entities = GetCompaniesQuery | GetPeopleQuery; | ||
|
||
function isGetCompaniesQuery( | ||
entities: Entities, | ||
): entities is GetCompaniesQuery { | ||
return (entities as GetCompaniesQuery).companies !== undefined; | ||
} | ||
|
||
function isGetPeopleQuery(entities: Entities): entities is GetPeopleQuery { | ||
return (entities as GetPeopleQuery).people !== undefined; | ||
} | ||
|
||
export const useBoard = () => { | ||
const pipelines = useGetPipelinesQuery(); | ||
const pipelineStages = pipelines.data?.findManyPipeline[0].pipelineStages; | ||
const initialBoard: Column[] = | ||
pipelineStages?.map((pipelineStage) => ({ | ||
id: pipelineStage.name, | ||
title: pipelineStage.name, | ||
colorCode: pipelineStage.color, | ||
itemKeys: | ||
pipelineStage.pipelineProgresses?.map( | ||
(item) => `item-${item.associableId}` as BoardItemKey, | ||
) || [], | ||
})) || []; | ||
|
||
const pipelineEntityIds = pipelineStages?.reduce( | ||
(acc, pipelineStage) => [ | ||
...acc, | ||
...(pipelineStage.pipelineProgresses?.map((item) => item.associableId) || | ||
[]), | ||
], | ||
[] as string[], | ||
); | ||
|
||
const pipelineEntityType: 'Person' | 'Company' | undefined = | ||
pipelineStages?.[0].pipelineProgresses?.[0].associableType; | ||
console.log(pipelineEntityType); | ||
|
||
const query = | ||
pipelineEntityType === 'Person' ? useGetPeopleQuery : useGetCompaniesQuery; | ||
|
||
const entitiesQueryResult = query({ | ||
variables: { where: { id: { in: pipelineEntityIds } } }, | ||
}); | ||
|
||
const indexByIdReducer = (acc: Items, entity: { id: string }) => ({ | ||
...acc, | ||
[`item-${entity.id}`]: entity, | ||
}); | ||
|
||
const items: Items | undefined = entitiesQueryResult.data | ||
? isGetCompaniesQuery(entitiesQueryResult.data) | ||
? entitiesQueryResult.data.companies.reduce(indexByIdReducer, {} as Items) | ||
: isGetPeopleQuery(entitiesQueryResult.data) | ||
? entitiesQueryResult.data.people.reduce(indexByIdReducer, {} as Items) | ||
: undefined | ||
: undefined; | ||
|
||
return { | ||
initialBoard, | ||
items, | ||
loading: pipelines.loading || entitiesQueryResult.loading, | ||
error: pipelines.error || entitiesQueryResult.error, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const GET_PIPELINES = gql` | ||
query GetPipelines { | ||
findManyPipeline(skip: 1) { | ||
id | ||
name | ||
pipelineStages { | ||
name | ||
color | ||
pipelineProgresses { | ||
id | ||
associableType | ||
associableId | ||
} | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters