-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Feat/generic editable cell chip #982
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
795fd09
Added generic relation cell
lucasbordeau 3fe6ef4
Deactivated debug
lucasbordeau bb8c33b
Added default warning
lucasbordeau 75ad274
Put back display component
lucasbordeau cf02eb8
Removed unused types
lucasbordeau 9e4c11e
wip
lucasbordeau 13cd9f0
Merge branch 'main' into feat/generic-editable-cell-chip
lucasbordeau 72763fa
Renamed to view field
lucasbordeau 136efde
Use new view field structure to have chip working
lucasbordeau d2b91a7
Finished
lucasbordeau a88d953
Merge branch 'main' into feat/generic-editable-cell-chip
lucasbordeau 4c61107
Added a temp feature flag
lucasbordeau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 additions & 0 deletions
22
front/src/modules/companies/constants/companyFieldMetadataArray.tsx
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,22 @@ | ||
import { IconBuildingSkyscraper } from '@tabler/icons-react'; | ||
|
||
import { Entity } from '@/ui/relation-picker/types/EntityTypeForSelect'; | ||
import { | ||
ViewFieldChipMetadata, | ||
ViewFieldDefinition, | ||
} from '@/ui/table/types/ViewField'; | ||
|
||
export const companyViewFields: ViewFieldDefinition<unknown>[] = [ | ||
{ | ||
columnLabel: 'Name', | ||
columnIcon: <IconBuildingSkyscraper size={16} />, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use iconSize from theme |
||
columnSize: 150, | ||
type: 'chip', | ||
columnOrder: 1, | ||
metadata: { | ||
urlFieldName: 'domainName', | ||
contentFieldName: 'name', | ||
relationType: Entity.Company, | ||
}, | ||
} as ViewFieldDefinition<ViewFieldChipMetadata>, | ||
]; |
54 changes: 54 additions & 0 deletions
54
front/src/modules/companies/table/components/CompanyTableV2.tsx
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,54 @@ | ||
import { useCallback, useMemo, useState } from 'react'; | ||
|
||
import { companyViewFields } from '@/companies/constants/companyFieldMetadataArray'; | ||
import { CompaniesSelectedSortType, defaultOrderBy } from '@/companies/queries'; | ||
import { GenericEntityTableData } from '@/people/components/GenericEntityTableData'; | ||
import { reduceSortsToOrderBy } from '@/ui/filter-n-sort/helpers'; | ||
import { filtersScopedState } from '@/ui/filter-n-sort/states/filtersScopedState'; | ||
import { turnFilterIntoWhereClause } from '@/ui/filter-n-sort/utils/turnFilterIntoWhereClause'; | ||
import { IconList } from '@/ui/icon'; | ||
import { useRecoilScopedValue } from '@/ui/recoil-scope/hooks/useRecoilScopedValue'; | ||
import { EntityTable } from '@/ui/table/components/EntityTableV2'; | ||
import { TableContext } from '@/ui/table/states/TableContext'; | ||
import { | ||
CompanyOrderByWithRelationInput, | ||
useGetCompaniesQuery, | ||
useUpdateOneCompanyMutation, | ||
} from '~/generated/graphql'; | ||
import { companiesFilters } from '~/pages/companies/companies-filters'; | ||
import { availableSorts } from '~/pages/companies/companies-sorts'; | ||
|
||
export function CompanyTable() { | ||
const [orderBy, setOrderBy] = | ||
useState<CompanyOrderByWithRelationInput[]>(defaultOrderBy); | ||
|
||
const updateSorts = useCallback((sorts: Array<CompaniesSelectedSortType>) => { | ||
setOrderBy(sorts.length ? reduceSortsToOrderBy(sorts) : defaultOrderBy); | ||
}, []); | ||
|
||
const filters = useRecoilScopedValue(filtersScopedState, TableContext); | ||
|
||
const whereFilters = useMemo(() => { | ||
return { AND: filters.map(turnFilterIntoWhereClause) }; | ||
}, [filters]) as any; | ||
|
||
return ( | ||
<> | ||
<GenericEntityTableData | ||
getRequestResultKey="companies" | ||
useGetRequest={useGetCompaniesQuery} | ||
orderBy={orderBy} | ||
whereFilters={whereFilters} | ||
viewFields={companyViewFields} | ||
filterDefinitionArray={companiesFilters} | ||
/> | ||
<EntityTable | ||
viewName="All Companies" | ||
viewIcon={<IconList size={16} />} | ||
availableSorts={availableSorts} | ||
onSortsUpdate={updateSorts} | ||
useUpdateEntityMutation={useUpdateOneCompanyMutation} | ||
/> | ||
</> | ||
); | ||
} |
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
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 |
---|---|---|
|
@@ -2,34 +2,38 @@ import { useContext } from 'react'; | |
import { useRecoilValue } from 'recoil'; | ||
|
||
import { EntityForSelect } from '@/ui/relation-picker/types/EntityForSelect'; | ||
import { entityFieldMetadataArrayState } from '@/ui/table/states/entityFieldMetadataArrayState'; | ||
import { EntityUpdateMutationHookContext } from '@/ui/table/states/EntityUpdateMutationHookContext'; | ||
import { viewFieldsState } from '@/ui/table/states/viewFieldsState'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this front/src/modules/people/hooks/useUpdateEntityField.ts to @/ui/table |
||
import { isViewFieldChip } from '@/ui/table/types/guards/isViewFieldChip'; | ||
import { isViewFieldRelation } from '@/ui/table/types/guards/isViewFieldRelation'; | ||
import { isViewFieldText } from '@/ui/table/types/guards/isViewFieldText'; | ||
|
||
export function useUpdateEntityField() { | ||
const useUpdateEntityMutation = useContext(EntityUpdateMutationHookContext); | ||
|
||
const [updateEntity] = useUpdateEntityMutation(); | ||
|
||
const entityFieldMetadataArray = useRecoilValue( | ||
entityFieldMetadataArrayState, | ||
); | ||
const viewFields = useRecoilValue(viewFieldsState); | ||
|
||
return function updatePeopleField( | ||
currentEntityId: string, | ||
fieldName: string, | ||
viewFieldId: string, | ||
newFieldValue: unknown, | ||
) { | ||
const fieldMetadata = entityFieldMetadataArray.find( | ||
(metadata) => metadata.fieldName === fieldName, | ||
const viewField = viewFields.find( | ||
(metadata) => metadata.id === viewFieldId, | ||
); | ||
|
||
if (!fieldMetadata) { | ||
throw new Error(`Field metadata not found for field ${fieldName}`); | ||
if (!viewField) { | ||
throw new Error(`View field not found for id ${viewFieldId}`); | ||
} | ||
|
||
if (fieldMetadata.type === 'relation') { | ||
// TODO: improve type narrowing here with validation maybe ? Also validate the newFieldValue with linked type guards | ||
if (isViewFieldRelation(viewField)) { | ||
const newSelectedEntity = newFieldValue as EntityForSelect | null; | ||
|
||
const fieldName = viewField.metadata.fieldName; | ||
|
||
if (!newSelectedEntity) { | ||
updateEntity({ | ||
variables: { | ||
|
@@ -53,11 +57,22 @@ export function useUpdateEntityField() { | |
}, | ||
}); | ||
} | ||
} else { | ||
} else if (isViewFieldChip(viewField)) { | ||
const newContent = newFieldValue as string; | ||
|
||
updateEntity({ | ||
variables: { | ||
where: { id: currentEntityId }, | ||
data: { [viewField.metadata.contentFieldName]: newContent }, | ||
}, | ||
}); | ||
} else if (isViewFieldText(viewField)) { | ||
const newContent = newFieldValue as string; | ||
|
||
updateEntity({ | ||
variables: { | ||
where: { id: currentEntityId }, | ||
data: { [fieldName]: newFieldValue }, | ||
data: { [viewField.metadata.fieldName]: newContent }, | ||
}, | ||
}); | ||
} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@/ui/icon