Fix drag-performance (#1184)
* Fix drag-performance * Fixes * Fixes * Fixes * Fixes
This commit is contained in:
@ -21,6 +21,7 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
|
files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
|
||||||
rules: {
|
rules: {
|
||||||
|
'no-control-regex': 0,
|
||||||
'simple-import-sort/imports': [
|
'simple-import-sort/imports': [
|
||||||
'error',
|
'error',
|
||||||
{
|
{
|
||||||
|
|||||||
@ -92,43 +92,6 @@ export function CommandMenu() {
|
|||||||
cmd.type === CommandType.Create,
|
cmd.type === CommandType.Create,
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: Allow performing actions on page through CommandBar
|
|
||||||
|
|
||||||
import { useMatch, useResolvedPath } from 'react-router-dom';
|
|
||||||
import { IconBuildingSkyscraper, IconUser } from '@/ui/icon';
|
|
||||||
|
|
||||||
const createSection = (
|
|
||||||
<StyledGroup heading="Create">
|
|
||||||
<CommandMenuItem
|
|
||||||
label="Create People"
|
|
||||||
onClick={createPeople}
|
|
||||||
icon={<IconUser />}
|
|
||||||
shortcuts={
|
|
||||||
!!useMatch({
|
|
||||||
path: useResolvedPath('/people').pathname,
|
|
||||||
end: true,
|
|
||||||
})
|
|
||||||
? ['C']
|
|
||||||
: []
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<CommandMenuItem
|
|
||||||
label="Create Company"
|
|
||||||
onClick={createCompany}
|
|
||||||
icon={<IconBuildingSkyscraper />}
|
|
||||||
shortcuts={
|
|
||||||
!!useMatch({
|
|
||||||
path: useResolvedPath('/companies').pathname,
|
|
||||||
end: true,
|
|
||||||
})
|
|
||||||
? ['C']
|
|
||||||
: []
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</StyledGroup>
|
|
||||||
);*/
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledDialog
|
<StyledDialog
|
||||||
open={isCommandMenuOpened}
|
open={isCommandMenuOpened}
|
||||||
@ -181,6 +144,7 @@ export function CommandMenu() {
|
|||||||
to={matchingNavigateCommand.to}
|
to={matchingNavigateCommand.to}
|
||||||
label={matchingNavigateCommand.label}
|
label={matchingNavigateCommand.label}
|
||||||
shortcuts={matchingNavigateCommand.shortcuts}
|
shortcuts={matchingNavigateCommand.shortcuts}
|
||||||
|
key={matchingNavigateCommand.label}
|
||||||
/>
|
/>
|
||||||
</StyledGroup>
|
</StyledGroup>
|
||||||
)}
|
)}
|
||||||
@ -245,7 +209,7 @@ export function CommandMenu() {
|
|||||||
)
|
)
|
||||||
.map((cmd) => (
|
.map((cmd) => (
|
||||||
<CommandMenuItem
|
<CommandMenuItem
|
||||||
key={cmd.shortcuts?.join('')}
|
key={cmd.shortcuts?.join('') ?? ''}
|
||||||
to={cmd.to}
|
to={cmd.to}
|
||||||
label={cmd.label}
|
label={cmd.label}
|
||||||
shortcuts={cmd.shortcuts}
|
shortcuts={cmd.shortcuts}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
label: string;
|
label: string;
|
||||||
to?: string;
|
to?: string;
|
||||||
|
key: string;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
icon?: ReactNode;
|
icon?: ReactNode;
|
||||||
shortcuts?: Array<string>;
|
shortcuts?: Array<string>;
|
||||||
|
|||||||
@ -2,8 +2,8 @@ import { ReactNode, useContext } from 'react';
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
|
import { useCurrentCardSelected } from '@/ui/board/hooks/useCurrentCardSelected';
|
||||||
import { BoardCardIdContext } from '@/ui/board/states/BoardCardIdContext';
|
import { BoardCardIdContext } from '@/ui/board/states/BoardCardIdContext';
|
||||||
import { selectedBoardCardIdsState } from '@/ui/board/states/selectedBoardCardIdsState';
|
|
||||||
import { viewFieldsDefinitionsState } from '@/ui/board/states/viewFieldsDefinitionsState';
|
import { viewFieldsDefinitionsState } from '@/ui/board/states/viewFieldsDefinitionsState';
|
||||||
import { EntityChipVariant } from '@/ui/chip/components/EntityChip';
|
import { EntityChipVariant } from '@/ui/chip/components/EntityChip';
|
||||||
import { GenericEditableField } from '@/ui/editable-field/components/GenericEditableField';
|
import { GenericEditableField } from '@/ui/editable-field/components/GenericEditableField';
|
||||||
@ -102,6 +102,8 @@ const StyledFieldContainer = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export function CompanyBoardCard() {
|
export function CompanyBoardCard() {
|
||||||
|
const { currentCardSelected, setCurrentCardSelected } =
|
||||||
|
useCurrentCardSelected();
|
||||||
const boardCardId = useContext(BoardCardIdContext);
|
const boardCardId = useContext(BoardCardIdContext);
|
||||||
|
|
||||||
const [companyProgress] = useRecoilState(
|
const [companyProgress] = useRecoilState(
|
||||||
@ -109,23 +111,8 @@ export function CompanyBoardCard() {
|
|||||||
);
|
);
|
||||||
const { pipelineProgress, company } = companyProgress ?? {};
|
const { pipelineProgress, company } = companyProgress ?? {};
|
||||||
|
|
||||||
const [selectedBoardCards, setSelectedBoardCards] = useRecoilState(
|
|
||||||
selectedBoardCardIdsState,
|
|
||||||
);
|
|
||||||
const viewFieldsDefinitions = useRecoilValue(viewFieldsDefinitionsState);
|
const viewFieldsDefinitions = useRecoilValue(viewFieldsDefinitionsState);
|
||||||
|
|
||||||
const selected = selectedBoardCards.includes(boardCardId ?? '');
|
|
||||||
|
|
||||||
function setSelected(isSelected: boolean) {
|
|
||||||
if (isSelected) {
|
|
||||||
setSelectedBoardCards([...selectedBoardCards, boardCardId ?? '']);
|
|
||||||
} else {
|
|
||||||
setSelectedBoardCards(
|
|
||||||
selectedBoardCards.filter((id) => id !== boardCardId),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// boardCardId check can be moved to a wrapper to avoid unnecessary logic above
|
// boardCardId check can be moved to a wrapper to avoid unnecessary logic above
|
||||||
if (!company || !pipelineProgress || !boardCardId) {
|
if (!company || !pipelineProgress || !boardCardId) {
|
||||||
return null;
|
return null;
|
||||||
@ -150,8 +137,8 @@ export function CompanyBoardCard() {
|
|||||||
return (
|
return (
|
||||||
<StyledBoardCardWrapper>
|
<StyledBoardCardWrapper>
|
||||||
<StyledBoardCard
|
<StyledBoardCard
|
||||||
selected={selected}
|
selected={currentCardSelected}
|
||||||
onClick={() => setSelected(!selected)}
|
onClick={() => setCurrentCardSelected(!currentCardSelected)}
|
||||||
>
|
>
|
||||||
<StyledBoardCardHeader>
|
<StyledBoardCardHeader>
|
||||||
<CompanyChip
|
<CompanyChip
|
||||||
@ -162,8 +149,8 @@ export function CompanyBoardCard() {
|
|||||||
/>
|
/>
|
||||||
<StyledCheckboxContainer className="checkbox-container">
|
<StyledCheckboxContainer className="checkbox-container">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={selected}
|
checked={currentCardSelected}
|
||||||
onChange={() => setSelected(!selected)}
|
onChange={() => setCurrentCardSelected(!currentCardSelected)}
|
||||||
variant={CheckboxVariant.Secondary}
|
variant={CheckboxVariant.Secondary}
|
||||||
/>
|
/>
|
||||||
</StyledCheckboxContainer>
|
</StyledCheckboxContainer>
|
||||||
|
|||||||
@ -4,8 +4,10 @@ import { useRecoilState, useSetRecoilState } from 'recoil';
|
|||||||
import { pipelineViewFields } from '@/pipeline/constants/pipelineViewFields';
|
import { pipelineViewFields } from '@/pipeline/constants/pipelineViewFields';
|
||||||
import { isBoardLoadedState } from '@/ui/board/states/isBoardLoadedState';
|
import { isBoardLoadedState } from '@/ui/board/states/isBoardLoadedState';
|
||||||
import { viewFieldsDefinitionsState } from '@/ui/board/states/viewFieldsDefinitionsState';
|
import { viewFieldsDefinitionsState } from '@/ui/board/states/viewFieldsDefinitionsState';
|
||||||
|
import { availableFiltersScopedState } from '@/ui/filter-n-sort/states/availableFiltersScopedState';
|
||||||
import { filtersScopedState } from '@/ui/filter-n-sort/states/filtersScopedState';
|
import { filtersScopedState } from '@/ui/filter-n-sort/states/filtersScopedState';
|
||||||
import { turnFilterIntoWhereClause } from '@/ui/filter-n-sort/utils/turnFilterIntoWhereClause';
|
import { turnFilterIntoWhereClause } from '@/ui/filter-n-sort/utils/turnFilterIntoWhereClause';
|
||||||
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||||
import {
|
import {
|
||||||
PipelineProgressableType,
|
PipelineProgressableType,
|
||||||
@ -17,6 +19,7 @@ import {
|
|||||||
useGetPipelineProgressQuery,
|
useGetPipelineProgressQuery,
|
||||||
useGetPipelinesQuery,
|
useGetPipelinesQuery,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
|
import { opportunitiesBoardOptions } from '~/pages/opportunities/opportunitiesBoardOptions';
|
||||||
|
|
||||||
import { useUpdateCompanyBoardCardIds } from '../hooks/useUpdateBoardCardIds';
|
import { useUpdateCompanyBoardCardIds } from '../hooks/useUpdateBoardCardIds';
|
||||||
import { useUpdateCompanyBoard } from '../hooks/useUpdateCompanyBoardColumns';
|
import { useUpdateCompanyBoard } from '../hooks/useUpdateCompanyBoardColumns';
|
||||||
@ -30,8 +33,13 @@ export function HooksCompanyBoard({
|
|||||||
const setFieldsDefinitionsState = useSetRecoilState(
|
const setFieldsDefinitionsState = useSetRecoilState(
|
||||||
viewFieldsDefinitionsState,
|
viewFieldsDefinitionsState,
|
||||||
);
|
);
|
||||||
|
const [, setAvailableFilters] = useRecoilScopedState(
|
||||||
|
availableFiltersScopedState,
|
||||||
|
CompanyBoardContext,
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setAvailableFilters(opportunitiesBoardOptions.filters);
|
||||||
setFieldsDefinitionsState(pipelineViewFields);
|
setFieldsDefinitionsState(pipelineViewFields);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,53 +1,40 @@
|
|||||||
import { useRecoilCallback } from 'recoil';
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { boardCardIdsByColumnIdFamilyState } from '@/ui/board/states/boardCardIdsByColumnIdFamilyState';
|
import { GET_PIPELINES } from '@/pipeline/queries';
|
||||||
import { boardColumnsState } from '@/ui/board/states/boardColumnsState';
|
|
||||||
import { selectedBoardCardIdsState } from '@/ui/board/states/selectedBoardCardIdsState';
|
|
||||||
import { IconTrash } from '@/ui/icon/index';
|
import { IconTrash } from '@/ui/icon/index';
|
||||||
import { EntityTableActionBarButton } from '@/ui/table/action-bar/components/EntityTableActionBarButton';
|
import { EntityTableActionBarButton } from '@/ui/table/action-bar/components/EntityTableActionBarButton';
|
||||||
|
import { useDeleteManyPipelineProgressMutation } from '~/generated/graphql';
|
||||||
|
|
||||||
export function BoardActionBarButtonDeleteBoardCard({
|
import { useRemoveCardIds } from '../hooks/useRemoveCardIds';
|
||||||
onDelete,
|
import { selectedCardIdsSelector } from '../states/selectedCardIdsSelector';
|
||||||
}: {
|
|
||||||
onDelete: (deletedCardIds: string[]) => void;
|
|
||||||
}) {
|
|
||||||
const deleteBoardCardIds = useRecoilCallback(
|
|
||||||
({ set, snapshot }) =>
|
|
||||||
() => {
|
|
||||||
const boardCardIdsToDelete = snapshot
|
|
||||||
.getLoadable(selectedBoardCardIdsState)
|
|
||||||
.getValue();
|
|
||||||
|
|
||||||
const boardColumns = snapshot.getLoadable(boardColumnsState).getValue();
|
export function BoardActionBarButtonDeleteBoardCard() {
|
||||||
|
const selectedCardIds = useRecoilValue(selectedCardIdsSelector);
|
||||||
|
const removeCardIds = useRemoveCardIds();
|
||||||
|
|
||||||
for (const boardColumn of boardColumns) {
|
const [deletePipelineProgress] = useDeleteManyPipelineProgressMutation({
|
||||||
const boardColumnCardIds = snapshot
|
refetchQueries: [getOperationName(GET_PIPELINES) ?? ''],
|
||||||
.getLoadable(boardCardIdsByColumnIdFamilyState(boardColumn.id))
|
});
|
||||||
.getValue();
|
|
||||||
|
|
||||||
const newBoardColumnCardIds = boardColumnCardIds.filter(
|
async function handleDelete() {
|
||||||
(cardId) => !boardCardIdsToDelete.includes(cardId),
|
await deletePipelineProgress({
|
||||||
);
|
variables: {
|
||||||
|
ids: selectedCardIds,
|
||||||
if (newBoardColumnCardIds.length !== boardColumnCardIds.length) {
|
|
||||||
set(
|
|
||||||
boardCardIdsByColumnIdFamilyState(boardColumn.id),
|
|
||||||
newBoardColumnCardIds,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set(selectedBoardCardIdsState, []);
|
|
||||||
|
|
||||||
return boardCardIdsToDelete;
|
|
||||||
},
|
},
|
||||||
[],
|
optimisticResponse: {
|
||||||
);
|
__typename: 'Mutation',
|
||||||
|
deleteManyPipelineProgress: {
|
||||||
async function handleDeleteClick() {
|
count: selectedCardIds.length,
|
||||||
const deletedCardIds = deleteBoardCardIds();
|
},
|
||||||
|
},
|
||||||
onDelete(deletedCardIds);
|
update: (cache) => {
|
||||||
|
removeCardIds(selectedCardIds);
|
||||||
|
selectedCardIds.forEach((id) => {
|
||||||
|
cache.evict({ id: `PipelineProgress:${id}` });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -55,7 +42,7 @@ export function BoardActionBarButtonDeleteBoardCard({
|
|||||||
label="Delete"
|
label="Delete"
|
||||||
icon={<IconTrash size={16} />}
|
icon={<IconTrash size={16} />}
|
||||||
type="warning"
|
type="warning"
|
||||||
onClick={handleDeleteClick}
|
onClick={() => handleDelete()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import { CompanyBoardContext } from '@/companies/states/CompanyBoardContext';
|
|||||||
import { GET_PIPELINE_PROGRESS } from '@/pipeline/queries';
|
import { GET_PIPELINE_PROGRESS } from '@/pipeline/queries';
|
||||||
import { BoardHeader } from '@/ui/board/components/BoardHeader';
|
import { BoardHeader } from '@/ui/board/components/BoardHeader';
|
||||||
import { StyledBoard } from '@/ui/board/components/StyledBoard';
|
import { StyledBoard } from '@/ui/board/components/StyledBoard';
|
||||||
import { useUpdateBoardCardIds } from '@/ui/board/hooks/useUpdateBoardCardIds';
|
|
||||||
import { BoardColumnIdContext } from '@/ui/board/states/BoardColumnIdContext';
|
import { BoardColumnIdContext } from '@/ui/board/states/BoardColumnIdContext';
|
||||||
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
|
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
|
||||||
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
|
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
|
||||||
@ -22,9 +21,10 @@ import {
|
|||||||
useUpdateOnePipelineProgressStageMutation,
|
useUpdateOnePipelineProgressStageMutation,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
|
|
||||||
|
import { useSetCardSelected } from '../hooks/useSetCardSelected';
|
||||||
|
import { useUpdateBoardCardIds } from '../hooks/useUpdateBoardCardIds';
|
||||||
import { BoardColumnContext } from '../states/BoardColumnContext';
|
import { BoardColumnContext } from '../states/BoardColumnContext';
|
||||||
import { boardColumnsState } from '../states/boardColumnsState';
|
import { boardColumnsState } from '../states/boardColumnsState';
|
||||||
import { selectedBoardCardIdsState } from '../states/selectedBoardCardIdsState';
|
|
||||||
import { BoardOptions } from '../types/BoardOptions';
|
import { BoardOptions } from '../types/BoardOptions';
|
||||||
|
|
||||||
import { EntityBoardColumn } from './EntityBoardColumn';
|
import { EntityBoardColumn } from './EntityBoardColumn';
|
||||||
@ -48,6 +48,7 @@ export function EntityBoard({
|
|||||||
onEditColumnTitle: (columnId: string, title: string, color: string) => void;
|
onEditColumnTitle: (columnId: string, title: string, color: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const [boardColumns] = useRecoilState(boardColumnsState);
|
const [boardColumns] = useRecoilState(boardColumnsState);
|
||||||
|
const setCardSelected = useSetCardSelected();
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [updatePipelineProgressStage] =
|
const [updatePipelineProgressStage] =
|
||||||
@ -104,19 +105,6 @@ export function EntityBoard({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const boardRef = useRef(null);
|
const boardRef = useRef(null);
|
||||||
const [selectedBoardCards, setSelectedBoardCards] = useRecoilState(
|
|
||||||
selectedBoardCardIdsState,
|
|
||||||
);
|
|
||||||
|
|
||||||
function setRowSelectedState(boardCardId: string, selected: boolean) {
|
|
||||||
if (selected && !selectedBoardCards.includes(boardCardId)) {
|
|
||||||
setSelectedBoardCards([...selectedBoardCards, boardCardId ?? '']);
|
|
||||||
} else if (!selected && selectedBoardCards.includes(boardCardId)) {
|
|
||||||
setSelectedBoardCards(
|
|
||||||
selectedBoardCards.filter((id) => id !== boardCardId),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (boardColumns?.length ?? 0) > 0 ? (
|
return (boardColumns?.length ?? 0) > 0 ? (
|
||||||
<StyledBoardWithHeader>
|
<StyledBoardWithHeader>
|
||||||
@ -144,7 +132,7 @@ export function EntityBoard({
|
|||||||
</StyledBoard>
|
</StyledBoard>
|
||||||
<DragSelect
|
<DragSelect
|
||||||
dragSelectable={boardRef}
|
dragSelectable={boardRef}
|
||||||
onDragSelectionChange={setRowSelectedState}
|
onDragSelectionChange={setCardSelected}
|
||||||
/>
|
/>
|
||||||
</StyledBoardWithHeader>
|
</StyledBoardWithHeader>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@ -3,13 +3,13 @@ import { useRecoilValue } from 'recoil';
|
|||||||
|
|
||||||
import { ActionBar } from '@/ui/action-bar/components/ActionBar';
|
import { ActionBar } from '@/ui/action-bar/components/ActionBar';
|
||||||
|
|
||||||
import { selectedBoardCardIdsState } from '../states/selectedBoardCardIdsState';
|
import { selectedCardIdsSelector } from '../states/selectedCardIdsSelector';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
children: React.ReactNode | React.ReactNode[];
|
children: React.ReactNode | React.ReactNode[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function EntityBoardActionBar({ children }: OwnProps) {
|
export function EntityBoardActionBar({ children }: OwnProps) {
|
||||||
const selectedBoardCards = useRecoilValue(selectedBoardCardIdsState);
|
const selectedCardIds = useRecoilValue(selectedCardIdsSelector);
|
||||||
return <ActionBar selectedIds={selectedBoardCards}>{children}</ActionBar>;
|
return <ActionBar selectedIds={selectedCardIds}>{children}</ActionBar>;
|
||||||
}
|
}
|
||||||
|
|||||||
28
front/src/modules/ui/board/hooks/useCurrentCardSelected.ts
Normal file
28
front/src/modules/ui/board/hooks/useCurrentCardSelected.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { useRecoilCallback, useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { BoardCardIdContext } from '../states/BoardCardIdContext';
|
||||||
|
import { isCardSelectedFamilyState } from '../states/isCardSelectedFamilyState';
|
||||||
|
|
||||||
|
export function useCurrentCardSelected() {
|
||||||
|
const currentCardId = useContext(BoardCardIdContext);
|
||||||
|
|
||||||
|
const [isCardSelected] = useRecoilState(
|
||||||
|
isCardSelectedFamilyState(currentCardId ?? ''),
|
||||||
|
);
|
||||||
|
|
||||||
|
const setCurrentCardSelected = useRecoilCallback(
|
||||||
|
({ set }) =>
|
||||||
|
(selected: boolean) => {
|
||||||
|
if (!currentCardId) return;
|
||||||
|
|
||||||
|
set(isCardSelectedFamilyState(currentCardId), selected);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
currentCardSelected: isCardSelected,
|
||||||
|
setCurrentCardSelected,
|
||||||
|
};
|
||||||
|
}
|
||||||
27
front/src/modules/ui/board/hooks/useRemoveCardIds.ts
Normal file
27
front/src/modules/ui/board/hooks/useRemoveCardIds.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Atlassian dnd does not support StrictMode from RN 18, so we use a fork @hello-pangea/dnd https://github.com/atlassian/react-beautiful-dnd/issues/2350
|
||||||
|
import { useRecoilCallback } from 'recoil';
|
||||||
|
|
||||||
|
import { boardCardIdsByColumnIdFamilyState } from '../states/boardCardIdsByColumnIdFamilyState';
|
||||||
|
import { boardColumnsState } from '../states/boardColumnsState';
|
||||||
|
|
||||||
|
export function useRemoveCardIds() {
|
||||||
|
return useRecoilCallback(
|
||||||
|
({ snapshot, set }) =>
|
||||||
|
(cardIdToRemove: string[]) => {
|
||||||
|
const boardColumns = snapshot
|
||||||
|
.getLoadable(boardColumnsState)
|
||||||
|
.valueOrThrow();
|
||||||
|
|
||||||
|
boardColumns.forEach((boardColumn) => {
|
||||||
|
const columnCardIds = snapshot
|
||||||
|
.getLoadable(boardCardIdsByColumnIdFamilyState(boardColumn.id))
|
||||||
|
.valueOrThrow();
|
||||||
|
set(
|
||||||
|
boardCardIdsByColumnIdFamilyState(boardColumn.id),
|
||||||
|
columnCardIds.filter((cardId) => !cardIdToRemove.includes(cardId)),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
}
|
||||||
27
front/src/modules/ui/board/hooks/useResetCardSelection.ts
Normal file
27
front/src/modules/ui/board/hooks/useResetCardSelection.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { useRecoilCallback } from 'recoil';
|
||||||
|
|
||||||
|
import { boardCardIdsByColumnIdFamilyState } from '../states/boardCardIdsByColumnIdFamilyState';
|
||||||
|
import { boardColumnsState } from '../states/boardColumnsState';
|
||||||
|
import { isCardSelectedFamilyState } from '../states/isCardSelectedFamilyState';
|
||||||
|
|
||||||
|
export function useResetCardSelection() {
|
||||||
|
return useRecoilCallback(
|
||||||
|
({ snapshot, set }) =>
|
||||||
|
() => {
|
||||||
|
const boardColumns = snapshot
|
||||||
|
.getLoadable(boardColumnsState)
|
||||||
|
.valueOrThrow();
|
||||||
|
|
||||||
|
const cardIds = boardColumns.flatMap((boardColumn) =>
|
||||||
|
snapshot
|
||||||
|
.getLoadable(boardCardIdsByColumnIdFamilyState(boardColumn.id))
|
||||||
|
.valueOrThrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const cardId of cardIds) {
|
||||||
|
set(isCardSelectedFamilyState(cardId), false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
}
|
||||||
9
front/src/modules/ui/board/hooks/useSetCardSelected.ts
Normal file
9
front/src/modules/ui/board/hooks/useSetCardSelected.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { useRecoilCallback } from 'recoil';
|
||||||
|
|
||||||
|
import { isCardSelectedFamilyState } from '../states/isCardSelectedFamilyState';
|
||||||
|
|
||||||
|
export function useSetCardSelected() {
|
||||||
|
return useRecoilCallback(({ set }) => (cardId: string, selected: boolean) => {
|
||||||
|
set(isCardSelectedFamilyState(cardId), selected);
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
import { atomFamily } from 'recoil';
|
||||||
|
|
||||||
|
export const isCardSelectedFamilyState = atomFamily<boolean, string>({
|
||||||
|
key: 'isCardSelectedFamilyState',
|
||||||
|
default: false,
|
||||||
|
});
|
||||||
@ -1,6 +0,0 @@
|
|||||||
import { atom } from 'recoil';
|
|
||||||
|
|
||||||
export const selectedBoardCardIdsState = atom<string[]>({
|
|
||||||
key: 'selectedBoardCardIdsState',
|
|
||||||
default: [],
|
|
||||||
});
|
|
||||||
22
front/src/modules/ui/board/states/selectedCardIdsSelector.ts
Normal file
22
front/src/modules/ui/board/states/selectedCardIdsSelector.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { selector } from 'recoil';
|
||||||
|
|
||||||
|
import { boardCardIdsByColumnIdFamilyState } from './boardCardIdsByColumnIdFamilyState';
|
||||||
|
import { boardColumnsState } from './boardColumnsState';
|
||||||
|
import { isCardSelectedFamilyState } from './isCardSelectedFamilyState';
|
||||||
|
|
||||||
|
export const selectedCardIdsSelector = selector<string[]>({
|
||||||
|
key: 'selectedCardIdsSelector',
|
||||||
|
get: ({ get }) => {
|
||||||
|
const boardColumns = get(boardColumnsState);
|
||||||
|
|
||||||
|
const cardIds = boardColumns.flatMap((boardColumn) =>
|
||||||
|
get(boardCardIdsByColumnIdFamilyState(boardColumn.id)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const selectedCardIds = cardIds.filter(
|
||||||
|
(cardId) => get(isCardSelectedFamilyState(cardId)) === true,
|
||||||
|
);
|
||||||
|
|
||||||
|
return selectedCardIds;
|
||||||
|
},
|
||||||
|
});
|
||||||
@ -28,7 +28,7 @@ export function DropdownMenuContainer({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledDropdownMenuContainer>
|
<StyledDropdownMenuContainer data-select-disable>
|
||||||
<DropdownMenu ref={dropdownRef}>{children}</DropdownMenu>
|
<DropdownMenu ref={dropdownRef}>{children}</DropdownMenu>
|
||||||
</StyledDropdownMenuContainer>
|
</StyledDropdownMenuContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -30,16 +30,25 @@ export function SocialLink({ children, href, onClick, type }: OwnProps) {
|
|||||||
let displayValue = children;
|
let displayValue = children;
|
||||||
|
|
||||||
if (type === 'linkedin') {
|
if (type === 'linkedin') {
|
||||||
const splitUrl = href.split('/');
|
const matches = href.match(
|
||||||
const splitName = splitUrl[4].split('-');
|
/(?:https?:\/\/)?(?:www.)?linkedin.com\/(?:in|company)\/([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
|
||||||
displayValue = splitName[2]
|
);
|
||||||
? `${splitName[0]}-${splitName[1]}`
|
if (matches && matches[1]) {
|
||||||
: splitName[0];
|
displayValue = matches[1];
|
||||||
|
} else {
|
||||||
|
displayValue = 'LinkedIn';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'twitter') {
|
if (type === 'twitter') {
|
||||||
const splitUrl = href.split('/');
|
const matches = href.match(
|
||||||
displayValue = `@${splitUrl[3]}`;
|
/(?:https?:\/\/)?(?:www.)?twitter.com\/([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
|
||||||
|
);
|
||||||
|
if (matches && matches[1]) {
|
||||||
|
displayValue = `@${matches[1]}`;
|
||||||
|
} else {
|
||||||
|
displayValue = '@twitter';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
|
import { useDragSelect } from '@/ui/utilities/drag-select/hooks/useDragSelect';
|
||||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||||
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||||
|
|
||||||
@ -17,17 +18,20 @@ export function useEditableCell() {
|
|||||||
const { setCurrentCellInEditMode } = useCurrentCellEditMode();
|
const { setCurrentCellInEditMode } = useCurrentCellEditMode();
|
||||||
|
|
||||||
const setHotkeyScope = useSetHotkeyScope();
|
const setHotkeyScope = useSetHotkeyScope();
|
||||||
|
const { setDragSelectionStartEnabled } = useDragSelect();
|
||||||
|
|
||||||
const closeCurrentCellInEditMode = useCloseCurrentCellInEditMode();
|
const closeCurrentCellInEditMode = useCloseCurrentCellInEditMode();
|
||||||
|
|
||||||
const customCellHotkeyScope = useContext(CellHotkeyScopeContext);
|
const customCellHotkeyScope = useContext(CellHotkeyScopeContext);
|
||||||
|
|
||||||
function closeEditableCell() {
|
function closeEditableCell() {
|
||||||
|
setDragSelectionStartEnabled(true);
|
||||||
closeCurrentCellInEditMode();
|
closeCurrentCellInEditMode();
|
||||||
setHotkeyScope(TableHotkeyScope.TableSoftFocus);
|
setHotkeyScope(TableHotkeyScope.TableSoftFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEditableCell() {
|
function openEditableCell() {
|
||||||
|
setDragSelectionStartEnabled(false);
|
||||||
setCurrentCellInEditMode();
|
setCurrentCellInEditMode();
|
||||||
|
|
||||||
if (customCellHotkeyScope) {
|
if (customCellHotkeyScope) {
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import {
|
|||||||
useSelectionContainer,
|
useSelectionContainer,
|
||||||
} from '@air/react-drag-to-select';
|
} from '@air/react-drag-to-select';
|
||||||
|
|
||||||
|
import { useDragSelect } from '../hooks/useDragSelect';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
dragSelectable: RefObject<HTMLElement>;
|
dragSelectable: RefObject<HTMLElement>;
|
||||||
onDragSelectionChange: (id: string, selected: boolean) => void;
|
onDragSelectionChange: (id: string, selected: boolean) => void;
|
||||||
@ -15,8 +17,12 @@ export function DragSelect({
|
|||||||
onDragSelectionChange,
|
onDragSelectionChange,
|
||||||
onDragSelectionStart,
|
onDragSelectionStart,
|
||||||
}: OwnProps) {
|
}: OwnProps) {
|
||||||
|
const { isDragSelectionStartEnabled } = useDragSelect();
|
||||||
const { DragSelection } = useSelectionContainer({
|
const { DragSelection } = useSelectionContainer({
|
||||||
shouldStartSelecting: (target) => {
|
shouldStartSelecting: (target) => {
|
||||||
|
if (!isDragSelectionStartEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (target instanceof HTMLElement) {
|
if (target instanceof HTMLElement) {
|
||||||
let el = target;
|
let el = target;
|
||||||
while (el.parentElement && !el.dataset.selectDisable) {
|
while (el.parentElement && !el.dataset.selectDisable) {
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
import { useRecoilCallback, useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { isDragSelectionStartEnabledState } from '../states/internal/isDragSelectionStartEnabledState';
|
||||||
|
|
||||||
|
export function useDragSelect() {
|
||||||
|
const [, setIsDragSelectionStartEnabledInternal] = useRecoilState(
|
||||||
|
isDragSelectionStartEnabledState,
|
||||||
|
);
|
||||||
|
|
||||||
|
function setDragSelectionStartEnabled(isEnabled: boolean) {
|
||||||
|
setIsDragSelectionStartEnabledInternal(isEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDragSelectionStartEnabled = useRecoilCallback(
|
||||||
|
({ snapshot }) =>
|
||||||
|
() => {
|
||||||
|
return snapshot
|
||||||
|
.getLoadable(isDragSelectionStartEnabledState)
|
||||||
|
.getValue();
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isDragSelectionStartEnabled,
|
||||||
|
setDragSelectionStartEnabled,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
import { atom } from 'recoil';
|
||||||
|
|
||||||
|
export const isDragSelectionStartEnabledState = atom({
|
||||||
|
key: 'drag-select/isDragSelectionStartEnabledState',
|
||||||
|
default: true,
|
||||||
|
});
|
||||||
@ -1,12 +1,10 @@
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { getOperationName } from '@apollo/client/utilities';
|
|
||||||
import { useTheme } from '@emotion/react';
|
import { useTheme } from '@emotion/react';
|
||||||
|
|
||||||
import { HooksCompanyBoard } from '@/companies/components/HooksCompanyBoard';
|
import { HooksCompanyBoard } from '@/companies/components/HooksCompanyBoard';
|
||||||
import { CompanyBoardContext } from '@/companies/states/CompanyBoardContext';
|
import { CompanyBoardContext } from '@/companies/states/CompanyBoardContext';
|
||||||
import {
|
import {
|
||||||
defaultPipelineProgressOrderBy,
|
defaultPipelineProgressOrderBy,
|
||||||
GET_PIPELINES,
|
|
||||||
PipelineProgressesSelectedSortType,
|
PipelineProgressesSelectedSortType,
|
||||||
} from '@/pipeline/queries';
|
} from '@/pipeline/queries';
|
||||||
import { BoardActionBarButtonDeleteBoardCard } from '@/ui/board/components/BoardActionBarButtonDeleteBoardCard';
|
import { BoardActionBarButtonDeleteBoardCard } from '@/ui/board/components/BoardActionBarButtonDeleteBoardCard';
|
||||||
@ -14,13 +12,11 @@ import { EntityBoard } from '@/ui/board/components/EntityBoard';
|
|||||||
import { EntityBoardActionBar } from '@/ui/board/components/EntityBoardActionBar';
|
import { EntityBoardActionBar } from '@/ui/board/components/EntityBoardActionBar';
|
||||||
import { BoardOptionsContext } from '@/ui/board/states/BoardOptionsContext';
|
import { BoardOptionsContext } from '@/ui/board/states/BoardOptionsContext';
|
||||||
import { reduceSortsToOrderBy } from '@/ui/filter-n-sort/helpers';
|
import { reduceSortsToOrderBy } from '@/ui/filter-n-sort/helpers';
|
||||||
import { AvailableFiltersContext } from '@/ui/filter-n-sort/states/AvailableFiltersContext';
|
|
||||||
import { IconTargetArrow } from '@/ui/icon/index';
|
import { IconTargetArrow } from '@/ui/icon/index';
|
||||||
import { WithTopBarContainer } from '@/ui/layout/components/WithTopBarContainer';
|
import { WithTopBarContainer } from '@/ui/layout/components/WithTopBarContainer';
|
||||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
import {
|
import {
|
||||||
PipelineProgressOrderByWithRelationInput,
|
PipelineProgressOrderByWithRelationInput,
|
||||||
useDeleteManyPipelineProgressMutation,
|
|
||||||
useUpdatePipelineStageMutation,
|
useUpdatePipelineStageMutation,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
import { opportunitiesBoardOptions } from '~/pages/opportunities/opportunitiesBoardOptions';
|
import { opportunitiesBoardOptions } from '~/pages/opportunities/opportunitiesBoardOptions';
|
||||||
@ -67,18 +63,6 @@ export function Opportunities() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const [deletePipelineProgress] = useDeleteManyPipelineProgressMutation({
|
|
||||||
refetchQueries: [getOperationName(GET_PIPELINES) ?? ''],
|
|
||||||
});
|
|
||||||
|
|
||||||
async function handleDelete(cardIdsToDelete: string[]) {
|
|
||||||
await deletePipelineProgress({
|
|
||||||
variables: {
|
|
||||||
ids: cardIdsToDelete,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WithTopBarContainer
|
<WithTopBarContainer
|
||||||
title="Opportunities"
|
title="Opportunities"
|
||||||
@ -86,19 +70,15 @@ export function Opportunities() {
|
|||||||
>
|
>
|
||||||
<BoardOptionsContext.Provider value={opportunitiesBoardOptions}>
|
<BoardOptionsContext.Provider value={opportunitiesBoardOptions}>
|
||||||
<RecoilScope SpecificContext={CompanyBoardContext}>
|
<RecoilScope SpecificContext={CompanyBoardContext}>
|
||||||
<AvailableFiltersContext.Provider
|
<HooksCompanyBoard orderBy={orderBy} />
|
||||||
value={opportunitiesBoardOptions.filters}
|
<EntityBoard
|
||||||
>
|
boardOptions={opportunitiesBoardOptions}
|
||||||
<HooksCompanyBoard orderBy={orderBy} />
|
updateSorts={updateSorts}
|
||||||
<EntityBoard
|
onEditColumnTitle={handleEditColumnTitle}
|
||||||
boardOptions={opportunitiesBoardOptions}
|
/>
|
||||||
updateSorts={updateSorts}
|
<EntityBoardActionBar>
|
||||||
onEditColumnTitle={handleEditColumnTitle}
|
<BoardActionBarButtonDeleteBoardCard />
|
||||||
/>
|
</EntityBoardActionBar>
|
||||||
<EntityBoardActionBar>
|
|
||||||
<BoardActionBarButtonDeleteBoardCard onDelete={handleDelete} />
|
|
||||||
</EntityBoardActionBar>
|
|
||||||
</AvailableFiltersContext.Provider>
|
|
||||||
</RecoilScope>
|
</RecoilScope>
|
||||||
</BoardOptionsContext.Provider>
|
</BoardOptionsContext.Provider>
|
||||||
</WithTopBarContainer>
|
</WithTopBarContainer>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
import { useSetRecoilState } from 'recoil';
|
import { useSetRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { commandMenuCommands } from '@/command-menu/constants/commandMenuCommands';
|
import { commandMenuCommands } from '@/command-menu/constants/commandMenuCommands';
|
||||||
@ -7,7 +8,9 @@ export function CommandMenuHook() {
|
|||||||
const setCommands = useSetRecoilState(commandMenuCommand);
|
const setCommands = useSetRecoilState(commandMenuCommand);
|
||||||
|
|
||||||
const commands = commandMenuCommands;
|
const commands = commandMenuCommands;
|
||||||
setCommands(commands);
|
useEffect(() => {
|
||||||
|
setCommands(commands);
|
||||||
|
}, [commands, setCommands]);
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,11 @@ describe('isURL', () => {
|
|||||||
expect(isURL('https://2.com/test/')).toBeTruthy();
|
expect(isURL('https://2.com/test/')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return false if string https://2.com/test/sldkfj!?`, () => {
|
it(`should return true if string is https://www.linkedin.com/company/b%C3%B6ke-&-partner-sdft-partmbb/`, () => {
|
||||||
expect(isURL('https://2.com/test/sldkfj!?')).toBeFalsy();
|
expect(
|
||||||
|
isURL(
|
||||||
|
'https://www.linkedin.com/company/b%C3%B6ke-&-partner-sdft-partmbb/',
|
||||||
|
),
|
||||||
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
import { isDefined } from './isDefined';
|
import { isDefined } from './isDefined';
|
||||||
|
|
||||||
export function isURL(url: string | undefined | null) {
|
export function isURL(url: string | undefined | null) {
|
||||||
const pattern = new RegExp(
|
return (
|
||||||
'^(https?:\\/\\/)?' +
|
isDefined(url) &&
|
||||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
|
url.match(
|
||||||
'((\\d{1,3}\\.){3}\\d{1,3}))' +
|
/^(https?:\/\/)?(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i,
|
||||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
|
)
|
||||||
'(\\?[;&a-z\\d%_.~+=-]*)?' +
|
|
||||||
'(\\#[-a-z\\d_]*)?$',
|
|
||||||
'i',
|
|
||||||
);
|
);
|
||||||
return isDefined(url) && !!pattern.test(url);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user