Compare commits
1 Commits
feat/outli
...
refactor/c
Author | SHA1 | Date | |
---|---|---|---|
2de48e288b |
@ -21,4 +21,4 @@ windows:
|
|||||||
- database:
|
- database:
|
||||||
root: ./
|
root: ./
|
||||||
panes:
|
panes:
|
||||||
- pgcli postgres://taskcafe:taskcafe_test@localhost:8855/taskcafe
|
- pgcli postgres://taskcafe:taskcafe_test@localhost:5432/taskcafe
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"@types/jest": "^24.0.0",
|
"@types/jest": "^24.0.0",
|
||||||
"@types/jwt-decode": "^2.2.1",
|
"@types/jwt-decode": "^2.2.1",
|
||||||
"@types/lodash": "^4.14.149",
|
"@types/lodash": "^4.14.149",
|
||||||
"@types/marked": "^1.2.2",
|
|
||||||
"@types/node": "^12.0.0",
|
"@types/node": "^12.0.0",
|
||||||
"@types/query-string": "^6.3.0",
|
"@types/query-string": "^6.3.0",
|
||||||
"@types/react": "^16.9.21",
|
"@types/react": "^16.9.21",
|
||||||
@ -23,7 +22,6 @@
|
|||||||
"@types/react-router-dom": "^5.1.3",
|
"@types/react-router-dom": "^5.1.3",
|
||||||
"@types/react-select": "^3.0.13",
|
"@types/react-select": "^3.0.13",
|
||||||
"@types/react-timeago": "^4.1.1",
|
"@types/react-timeago": "^4.1.1",
|
||||||
"@types/react-window": "^1.8.2",
|
|
||||||
"@types/styled-components": "^5.0.0",
|
"@types/styled-components": "^5.0.0",
|
||||||
"apollo-cache-inmemory": "^1.6.5",
|
"apollo-cache-inmemory": "^1.6.5",
|
||||||
"apollo-client": "^2.6.8",
|
"apollo-client": "^2.6.8",
|
||||||
@ -43,7 +41,6 @@
|
|||||||
"immer": "^6.0.3",
|
"immer": "^6.0.3",
|
||||||
"jwt-decode": "^2.2.0",
|
"jwt-decode": "^2.2.0",
|
||||||
"lodash": "^4.17.20",
|
"lodash": "^4.17.20",
|
||||||
"marked": "^2.0.0",
|
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"query-string": "^6.13.7",
|
"query-string": "^6.13.7",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
@ -59,8 +56,6 @@
|
|||||||
"react-select": "^3.1.0",
|
"react-select": "^3.1.0",
|
||||||
"react-timeago": "^4.4.0",
|
"react-timeago": "^4.4.0",
|
||||||
"react-toastify": "^6.0.8",
|
"react-toastify": "^6.0.8",
|
||||||
"react-visibility-sensor": "^5.1.1",
|
|
||||||
"react-window": "^1.8.6",
|
|
||||||
"rich-markdown-editor": "^10.6.5",
|
"rich-markdown-editor": "^10.6.5",
|
||||||
"styled-components": "^5.0.1",
|
"styled-components": "^5.0.1",
|
||||||
"typescript": "~3.7.2"
|
"typescript": "~3.7.2"
|
||||||
|
@ -182,7 +182,7 @@ const AdminRoute = () => {
|
|||||||
updateApolloCache<UsersQuery>(client, UsersDocument, cache =>
|
updateApolloCache<UsersQuery>(client, UsersDocument, cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.invitedUsers = cache.invitedUsers.filter(
|
draftCache.invitedUsers = cache.invitedUsers.filter(
|
||||||
u => u.id !== response.data?.deleteInvitedUserAccount.invitedUser.id,
|
u => u.id !== response.data.deleteInvitedUserAccount.invitedUser.id,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -192,7 +192,7 @@ const AdminRoute = () => {
|
|||||||
update: (client, response) => {
|
update: (client, response) => {
|
||||||
updateApolloCache<UsersQuery>(client, UsersDocument, cache =>
|
updateApolloCache<UsersQuery>(client, UsersDocument, cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.users = cache.users.filter(u => u.id !== response.data?.deleteUserAccount.userAccount.id);
|
draftCache.users = cache.users.filter(u => u.id !== response.data.deleteUserAccount.userAccount.id);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -203,7 +203,7 @@ const AdminRoute = () => {
|
|||||||
query: UsersDocument,
|
query: UsersDocument,
|
||||||
});
|
});
|
||||||
const newData = produce(cacheData, (draftState: any) => {
|
const newData = produce(cacheData, (draftState: any) => {
|
||||||
draftState.users = [...draftState.users, { ...createData.data?.createUserAccount }];
|
draftState.users = [...draftState.users, { ...createData.data.createUserAccount }];
|
||||||
});
|
});
|
||||||
|
|
||||||
client.writeQuery({
|
client.writeQuery({
|
||||||
|
@ -15,7 +15,6 @@ import styled from 'styled-components';
|
|||||||
import JwtDecode from 'jwt-decode';
|
import JwtDecode from 'jwt-decode';
|
||||||
import { setAccessToken } from 'shared/utils/accessToken';
|
import { setAccessToken } from 'shared/utils/accessToken';
|
||||||
import { useCurrentUser } from 'App/context';
|
import { useCurrentUser } from 'App/context';
|
||||||
import Outline from 'Outline';
|
|
||||||
|
|
||||||
const MainContent = styled.div`
|
const MainContent = styled.div`
|
||||||
padding: 0 0 0 0;
|
padding: 0 0 0 0;
|
||||||
@ -26,20 +25,12 @@ const MainContent = styled.div`
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type RefreshTokenResponse = {
|
|
||||||
accessToken: string;
|
|
||||||
setup?: null | { confirmToken: string };
|
|
||||||
};
|
|
||||||
|
|
||||||
const AuthorizedRoutes = () => {
|
const AuthorizedRoutes = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { setUser } = useCurrentUser();
|
const { setUser } = useCurrentUser();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
fetch('/auth/refresh_token', {
|
fetch('/auth/refresh_token', {
|
||||||
signal: abortController.signal,
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
}).then(async x => {
|
}).then(async x => {
|
||||||
@ -63,9 +54,6 @@ const AuthorizedRoutes = () => {
|
|||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
return () => {
|
|
||||||
abortController.abort();
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
return loading ? null : (
|
return loading ? null : (
|
||||||
<Switch>
|
<Switch>
|
||||||
@ -74,7 +62,6 @@ const AuthorizedRoutes = () => {
|
|||||||
<Route exact path="/projects" component={Projects} />
|
<Route exact path="/projects" component={Projects} />
|
||||||
<Route path="/projects/:projectID" component={Project} />
|
<Route path="/projects/:projectID" component={Project} />
|
||||||
<Route path="/teams/:teamID" component={Teams} />
|
<Route path="/teams/:teamID" component={Teams} />
|
||||||
<Route path="/outline" component={Outline} />
|
|
||||||
<Route path="/profile" component={Profile} />
|
<Route path="/profile" component={Profile} />
|
||||||
<Route path="/admin" component={Admin} />
|
<Route path="/admin" component={Admin} />
|
||||||
</MainContent>
|
</MainContent>
|
||||||
|
@ -167,7 +167,7 @@ const ProjectFinder = () => {
|
|||||||
return <span>error</span>;
|
return <span>error</span>;
|
||||||
};
|
};
|
||||||
type ProjectPopupProps = {
|
type ProjectPopupProps = {
|
||||||
history: any;
|
history: History<History.PoorMansUnknown>;
|
||||||
name: string;
|
name: string;
|
||||||
projectID: string;
|
projectID: string;
|
||||||
};
|
};
|
||||||
@ -182,7 +182,7 @@ export const ProjectPopup: React.FC<ProjectPopupProps> = ({ history, name, proje
|
|||||||
|
|
||||||
const newData = produce(cacheData, (draftState: any) => {
|
const newData = produce(cacheData, (draftState: any) => {
|
||||||
draftState.projects = draftState.projects.filter(
|
draftState.projects = draftState.projects.filter(
|
||||||
(project: any) => project.id !== deleteData.data?.deleteProject.project.id,
|
(project: any) => project.id !== deleteData.data.deleteProject.project.id,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,6 +46,10 @@ const StyledContainer = styled(ToastContainer).attrs({
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const history = createBrowserHistory();
|
const history = createBrowserHistory();
|
||||||
|
type RefreshTokenResponse = {
|
||||||
|
accessToken: string;
|
||||||
|
isInstalled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [user, setUser] = useState<CurrentUserRaw | null>(null);
|
const [user, setUser] = useState<CurrentUserRaw | null>(null);
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { DragDebugWrapper } from './Styles';
|
|
||||||
|
|
||||||
type DragDebugProps = {
|
|
||||||
zone: ImpactZone | null;
|
|
||||||
depthTarget: number;
|
|
||||||
draggedNodes: Array<string> | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const DragDebug: React.FC<DragDebugProps> = ({ zone, depthTarget, draggedNodes }) => {
|
|
||||||
let aboveID = null;
|
|
||||||
let belowID = null;
|
|
||||||
if (zone) {
|
|
||||||
aboveID = zone.above ? zone.above.node.id : null;
|
|
||||||
belowID = zone.below ? zone.below.node.id : null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<DragDebugWrapper>{`aboveID=${aboveID} / belowID=${belowID} / depthTarget=${depthTarget} draggedNodes=${
|
|
||||||
draggedNodes ? draggedNodes.toString() : null
|
|
||||||
}`}</DragDebugWrapper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DragDebug;
|
|
@ -1,41 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { getDimensions } from './utils';
|
|
||||||
import { DragIndicatorBar } from './Styles';
|
|
||||||
|
|
||||||
type DragIndicatorProps = {
|
|
||||||
container: React.RefObject<HTMLDivElement>;
|
|
||||||
zone: ImpactZone;
|
|
||||||
depthTarget: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
const DragIndicator: React.FC<DragIndicatorProps> = ({ container, zone, depthTarget }) => {
|
|
||||||
let top = 0;
|
|
||||||
let width = 0;
|
|
||||||
if (zone.below === null) {
|
|
||||||
if (zone.above) {
|
|
||||||
const entry = getDimensions(zone.above.dimensions.entry);
|
|
||||||
const children = getDimensions(zone.above.dimensions.children);
|
|
||||||
if (children) {
|
|
||||||
top = children.top;
|
|
||||||
width = children.width - depthTarget * 35;
|
|
||||||
} else if (entry) {
|
|
||||||
top = entry.bottom;
|
|
||||||
width = entry.width - depthTarget * 35;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (zone.below) {
|
|
||||||
const entry = getDimensions(zone.below.dimensions.entry);
|
|
||||||
if (entry) {
|
|
||||||
top = entry.top;
|
|
||||||
width = entry.width - depthTarget * 35;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let left = 0;
|
|
||||||
if (container && container.current) {
|
|
||||||
left = container.current.getBoundingClientRect().left + (depthTarget - 1) * 35;
|
|
||||||
width = container.current.getBoundingClientRect().width - depthTarget * 35;
|
|
||||||
}
|
|
||||||
return <DragIndicatorBar top={top} left={left} width={width} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DragIndicator;
|
|
@ -1,385 +0,0 @@
|
|||||||
import React, { useRef, useCallback, useState, useMemo, useEffect } from 'react';
|
|
||||||
import { Dot } from 'shared/icons';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import {
|
|
||||||
findNextDraggable,
|
|
||||||
getDimensions,
|
|
||||||
getTargetDepth,
|
|
||||||
getNodeAbove,
|
|
||||||
getBelowParent,
|
|
||||||
findNodeAbove,
|
|
||||||
getNodeOver,
|
|
||||||
getLastChildInBranch,
|
|
||||||
findNodeDepth,
|
|
||||||
} from './utils';
|
|
||||||
import { useDrag } from './useDrag';
|
|
||||||
|
|
||||||
const Container = styled.div`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 18px;
|
|
||||||
height: 18px;
|
|
||||||
border-radius: 9px;
|
|
||||||
background: rgba(${p => p.theme.colors.primary});
|
|
||||||
svg {
|
|
||||||
fill: rgba(${p => p.theme.colors.text.primary});
|
|
||||||
stroke: rgba(${p => p.theme.colors.text.primary});
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type DraggerProps = {
|
|
||||||
container: React.RefObject<HTMLDivElement>;
|
|
||||||
draggedNodes: { nodes: Array<string>; first?: OutlineNode | null };
|
|
||||||
isDragging: boolean;
|
|
||||||
onDragEnd: (zone: ImpactZone) => void;
|
|
||||||
initialPos: { x: number; y: number };
|
|
||||||
pageRef: React.RefObject<HTMLDivElement>;
|
|
||||||
};
|
|
||||||
|
|
||||||
let timer: any = null;
|
|
||||||
|
|
||||||
type windowScrollOptions = {
|
|
||||||
maxScrollX: number;
|
|
||||||
maxScrollY: number;
|
|
||||||
isInTopEdge: boolean;
|
|
||||||
isInBottomEdge: boolean;
|
|
||||||
edgeTop: number;
|
|
||||||
edgeBottom: number;
|
|
||||||
edgeSize: number;
|
|
||||||
viewportY: number;
|
|
||||||
$page: React.RefObject<HTMLDivElement>;
|
|
||||||
};
|
|
||||||
function adjustWindowScroll({
|
|
||||||
maxScrollY,
|
|
||||||
maxScrollX,
|
|
||||||
$page,
|
|
||||||
isInTopEdge,
|
|
||||||
isInBottomEdge,
|
|
||||||
edgeTop,
|
|
||||||
edgeBottom,
|
|
||||||
edgeSize,
|
|
||||||
viewportY,
|
|
||||||
}: windowScrollOptions) {
|
|
||||||
// Get the current scroll position of the document.
|
|
||||||
if ($page.current) {
|
|
||||||
var currentScrollX = $page.current.scrollLeft;
|
|
||||||
var currentScrollY = $page.current.scrollTop;
|
|
||||||
|
|
||||||
// Determine if the window can be scrolled in any particular direction.
|
|
||||||
var canScrollUp = currentScrollY > 0;
|
|
||||||
var canScrollDown = currentScrollY < maxScrollY;
|
|
||||||
|
|
||||||
// Since we can potentially scroll in two directions at the same time,
|
|
||||||
// let's keep track of the next scroll, starting with the current scroll.
|
|
||||||
// Each of these values can then be adjusted independently in the logic
|
|
||||||
// below.
|
|
||||||
var nextScrollX = currentScrollX;
|
|
||||||
var nextScrollY = currentScrollY;
|
|
||||||
|
|
||||||
// As we examine the mouse position within the edge, we want to make the
|
|
||||||
// incremental scroll changes more "intense" the closer that the user
|
|
||||||
// gets the viewport edge. As such, we'll calculate the percentage that
|
|
||||||
// the user has made it "through the edge" when calculating the delta.
|
|
||||||
// Then, that use that percentage to back-off from the "max" step value.
|
|
||||||
var maxStep = 50;
|
|
||||||
|
|
||||||
// Should we scroll up?
|
|
||||||
if (isInTopEdge && canScrollUp) {
|
|
||||||
var intensity = (edgeTop - viewportY) / edgeSize;
|
|
||||||
|
|
||||||
nextScrollY = nextScrollY - maxStep * intensity;
|
|
||||||
|
|
||||||
// Should we scroll down?
|
|
||||||
} else if (isInBottomEdge && canScrollDown) {
|
|
||||||
var intensity = (viewportY - edgeBottom) / edgeSize;
|
|
||||||
|
|
||||||
nextScrollY = nextScrollY + maxStep * intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize invalid maximums. An invalid scroll offset won't break the
|
|
||||||
// subsequent .scrollTo() call; however, it will make it harder to
|
|
||||||
// determine if the .scrollTo() method should have been called in the
|
|
||||||
// first place.
|
|
||||||
nextScrollX = Math.max(0, Math.min(maxScrollX, nextScrollX));
|
|
||||||
nextScrollY = Math.max(0, Math.min(maxScrollY, nextScrollY));
|
|
||||||
|
|
||||||
if (nextScrollX !== currentScrollX || nextScrollY !== currentScrollY) {
|
|
||||||
$page.current.scrollTo(nextScrollX, nextScrollY);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Dragger: React.FC<DraggerProps> = ({
|
|
||||||
draggedNodes,
|
|
||||||
container,
|
|
||||||
onDragEnd,
|
|
||||||
isDragging,
|
|
||||||
initialPos,
|
|
||||||
pageRef: $page,
|
|
||||||
}) => {
|
|
||||||
const [pos, setPos] = useState<{ x: number; y: number }>(initialPos);
|
|
||||||
const { outline, impact, setImpact } = useDrag();
|
|
||||||
const $handle = useRef<HTMLDivElement>(null);
|
|
||||||
const handleMouseUp = useCallback(() => {
|
|
||||||
onDragEnd(impact ? impact.zone : { below: null, above: null });
|
|
||||||
}, [impact]);
|
|
||||||
const handleMouseMove = useCallback(
|
|
||||||
e => {
|
|
||||||
var t0 = performance.now();
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
const { clientX, clientY, pageX, pageY } = e;
|
|
||||||
setPos({ x: clientX, y: clientY });
|
|
||||||
const { curDepth, curPosition, curDraggable } = getNodeOver({ x: clientX, y: clientY }, outline.current);
|
|
||||||
let depthTarget: number = 0;
|
|
||||||
let aboveNode: null | OutlineNode = null;
|
|
||||||
let belowNode: null | OutlineNode = null;
|
|
||||||
|
|
||||||
const edgeSize = 50;
|
|
||||||
|
|
||||||
const viewportWidth = document.documentElement.clientWidth;
|
|
||||||
const viewportHeight = document.documentElement.clientHeight;
|
|
||||||
|
|
||||||
var edgeTop = edgeSize + 80;
|
|
||||||
var edgeBottom = viewportHeight - edgeSize;
|
|
||||||
|
|
||||||
var isInTopEdge = clientY < edgeTop;
|
|
||||||
var isInBottomEdge = clientY > edgeBottom;
|
|
||||||
|
|
||||||
if ((isInBottomEdge || isInTopEdge) && $page.current) {
|
|
||||||
var documentWidth = Math.max(
|
|
||||||
$page.current.scrollWidth,
|
|
||||||
$page.current.offsetWidth,
|
|
||||||
$page.current.clientWidth,
|
|
||||||
$page.current.scrollWidth,
|
|
||||||
$page.current.offsetWidth,
|
|
||||||
$page.current.clientWidth,
|
|
||||||
);
|
|
||||||
var documentHeight = Math.max(
|
|
||||||
$page.current.scrollHeight,
|
|
||||||
$page.current.offsetHeight,
|
|
||||||
$page.current.clientHeight,
|
|
||||||
$page.current.scrollHeight,
|
|
||||||
$page.current.offsetHeight,
|
|
||||||
$page.current.clientHeight,
|
|
||||||
);
|
|
||||||
|
|
||||||
var maxScrollX = documentWidth - viewportWidth;
|
|
||||||
var maxScrollY = documentHeight - viewportHeight;
|
|
||||||
|
|
||||||
(function checkForWindowScroll() {
|
|
||||||
clearTimeout(timer);
|
|
||||||
|
|
||||||
if (
|
|
||||||
adjustWindowScroll({
|
|
||||||
maxScrollX,
|
|
||||||
maxScrollY,
|
|
||||||
edgeBottom,
|
|
||||||
$page,
|
|
||||||
edgeTop,
|
|
||||||
edgeSize,
|
|
||||||
isInBottomEdge,
|
|
||||||
isInTopEdge,
|
|
||||||
viewportY: clientY,
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
timer = setTimeout(checkForWindowScroll, 30);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
} else {
|
|
||||||
clearTimeout(timer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curPosition === 'before') {
|
|
||||||
belowNode = curDraggable;
|
|
||||||
} else {
|
|
||||||
aboveNode = curDraggable;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if belowNode has the depth of 1, then the above element will be a part of a different branch
|
|
||||||
|
|
||||||
const { relationships, nodes } = outline.current;
|
|
||||||
if (!belowNode || !aboveNode) {
|
|
||||||
if (belowNode) {
|
|
||||||
aboveNode = findNodeAbove(outline.current, curDepth, belowNode);
|
|
||||||
} else if (aboveNode) {
|
|
||||||
let targetBelowNode: RelationshipChild | null = null;
|
|
||||||
const parent = relationships.get(aboveNode.parent);
|
|
||||||
if (aboveNode.children !== 0 && !aboveNode.collapsed) {
|
|
||||||
const abr = relationships.get(aboveNode.id);
|
|
||||||
if (abr) {
|
|
||||||
const newTarget = abr.children[0];
|
|
||||||
if (newTarget) {
|
|
||||||
targetBelowNode = newTarget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (parent) {
|
|
||||||
const aboveNodeIndex = parent.children.findIndex(c => aboveNode && c.id === aboveNode.id);
|
|
||||||
if (aboveNodeIndex !== -1) {
|
|
||||||
if (aboveNodeIndex === parent.children.length - 1) {
|
|
||||||
targetBelowNode = getBelowParent(aboveNode, outline.current);
|
|
||||||
} else {
|
|
||||||
const nextChild = parent.children[aboveNodeIndex + 1];
|
|
||||||
targetBelowNode = nextChild ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetBelowNode) {
|
|
||||||
const depthNodes = nodes.get(targetBelowNode.depth);
|
|
||||||
if (depthNodes) {
|
|
||||||
belowNode = depthNodes.get(targetBelowNode.id) ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if outside outline, get either first or last item in list based on mouse Y
|
|
||||||
if (!aboveNode && !belowNode) {
|
|
||||||
if (container && container.current) {
|
|
||||||
const bounds = container.current.getBoundingClientRect();
|
|
||||||
if (clientY < bounds.top + bounds.height / 2) {
|
|
||||||
const rootChildren = outline.current.relationships.get('root');
|
|
||||||
const rootDepth = outline.current.nodes.get(1);
|
|
||||||
if (rootChildren && rootDepth) {
|
|
||||||
const firstChild = rootChildren.children[0];
|
|
||||||
belowNode = rootDepth.get(firstChild.id) ?? null;
|
|
||||||
aboveNode = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: enhance to actually get last child item, not last top level branch
|
|
||||||
const rootChildren = outline.current.relationships.get('root');
|
|
||||||
const rootDepth = outline.current.nodes.get(1);
|
|
||||||
if (rootChildren && rootDepth) {
|
|
||||||
const lastChild = rootChildren.children[rootChildren.children.length - 1];
|
|
||||||
const lastParentNode = rootDepth.get(lastChild.id) ?? null;
|
|
||||||
|
|
||||||
if (lastParentNode) {
|
|
||||||
const lastBranchChild = getLastChildInBranch(outline.current, lastParentNode);
|
|
||||||
if (lastBranchChild) {
|
|
||||||
const lastChildDepth = outline.current.nodes.get(lastBranchChild.depth);
|
|
||||||
if (lastChildDepth) {
|
|
||||||
aboveNode = lastChildDepth.get(lastBranchChild.id) ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aboveNode) {
|
|
||||||
const foundDepth = findNodeDepth(outline.current.published, aboveNode.id);
|
|
||||||
if (foundDepth === null) return;
|
|
||||||
for (let i = 0; i < draggedNodes.nodes.length; i++) {
|
|
||||||
const nodeID = draggedNodes.nodes[i];
|
|
||||||
if (foundDepth.ancestors.find(c => c === nodeID)) {
|
|
||||||
if (draggedNodes.first) {
|
|
||||||
belowNode = draggedNodes.first;
|
|
||||||
aboveNode = findNodeAbove(outline.current, aboveNode ? aboveNode.depth : 1, draggedNodes.first);
|
|
||||||
} else {
|
|
||||||
const foundDepth = findNodeDepth(outline.current.published, nodeID);
|
|
||||||
if (foundDepth === null) return;
|
|
||||||
const nodeDepth = outline.current.nodes.get(foundDepth.depth);
|
|
||||||
const targetNode = nodeDepth ? nodeDepth.get(nodeID) : null;
|
|
||||||
if (targetNode) {
|
|
||||||
belowNode = targetNode;
|
|
||||||
|
|
||||||
aboveNode = findNodeAbove(outline.current, foundDepth.depth, targetNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate available depths
|
|
||||||
|
|
||||||
let minDepth = 1;
|
|
||||||
let maxDepth = 2;
|
|
||||||
if (aboveNode) {
|
|
||||||
const aboveParent = relationships.get(aboveNode.parent);
|
|
||||||
if (aboveNode.children !== 0 && !aboveNode.collapsed) {
|
|
||||||
minDepth = aboveNode.depth + 1;
|
|
||||||
maxDepth = aboveNode.depth + 1;
|
|
||||||
} else if (aboveParent) {
|
|
||||||
minDepth = aboveNode.depth;
|
|
||||||
maxDepth = aboveNode.depth + 1;
|
|
||||||
const aboveNodeIndex = aboveParent.children.findIndex(c => aboveNode && c.id === aboveNode.id);
|
|
||||||
if (aboveNodeIndex === aboveParent.children.length - 1) {
|
|
||||||
minDepth = belowNode ? belowNode.depth : minDepth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (aboveNode) {
|
|
||||||
const dimensions = outline.current.dimensions.get(aboveNode.id);
|
|
||||||
const entry = getDimensions(dimensions?.entry);
|
|
||||||
if (entry) {
|
|
||||||
depthTarget = getTargetDepth(clientX, entry.left, { min: minDepth, max: maxDepth });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let aboveImpact: null | ImpactZoneData = null;
|
|
||||||
let belowImpact: null | ImpactZoneData = null;
|
|
||||||
if (aboveNode) {
|
|
||||||
const aboveDim = outline.current.dimensions.get(aboveNode.id);
|
|
||||||
if (aboveDim) {
|
|
||||||
aboveImpact = {
|
|
||||||
node: aboveNode,
|
|
||||||
dimensions: aboveDim,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (belowNode) {
|
|
||||||
const belowDim = outline.current.dimensions.get(belowNode.id);
|
|
||||||
if (belowDim) {
|
|
||||||
belowImpact = {
|
|
||||||
node: belowNode,
|
|
||||||
dimensions: belowDim,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setImpact({
|
|
||||||
zone: {
|
|
||||||
above: aboveImpact,
|
|
||||||
below: belowImpact,
|
|
||||||
},
|
|
||||||
depth: depthTarget,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[outline.current.nodes],
|
|
||||||
);
|
|
||||||
useEffect(() => {
|
|
||||||
document.addEventListener('mouseup', handleMouseUp);
|
|
||||||
document.addEventListener('mousemove', handleMouseMove);
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('mouseup', handleMouseUp);
|
|
||||||
document.removeEventListener('mousemove', handleMouseMove);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
const styles = useMemo(() => {
|
|
||||||
const position: 'fixed' | 'relative' = isDragging ? 'fixed' : 'relative';
|
|
||||||
return {
|
|
||||||
cursor: isDragging ? '-webkit-grabbing' : '-webkit-grab',
|
|
||||||
transform: `translate(${pos.x - 10}px, ${pos.y - 4}px)`,
|
|
||||||
transition: isDragging ? 'none' : 'transform 500ms',
|
|
||||||
zIndex: isDragging ? 2 : 1,
|
|
||||||
position,
|
|
||||||
};
|
|
||||||
}, [isDragging, pos]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{pos && (
|
|
||||||
<Container ref={$handle} style={styles}>
|
|
||||||
<Dot width={18} height={18} />
|
|
||||||
</Container>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Dragger;
|
|
@ -1,377 +0,0 @@
|
|||||||
import React, { useRef, useEffect, useCallback, useState } from 'react';
|
|
||||||
import { Dot, CaretDown, CaretRight } from 'shared/icons';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import marked from 'marked';
|
|
||||||
import VisibilitySensor from 'react-visibility-sensor';
|
|
||||||
|
|
||||||
import {
|
|
||||||
EntryChildren,
|
|
||||||
EntryWrapper,
|
|
||||||
EntryContent,
|
|
||||||
EntryInnerContent,
|
|
||||||
EntryHandle,
|
|
||||||
ExpandButton,
|
|
||||||
EntryContentEditor,
|
|
||||||
EntryContentDisplay,
|
|
||||||
} from './Styles';
|
|
||||||
import { useDrag } from './useDrag';
|
|
||||||
import { getCaretPosition, setCurrentCursorPosition } from './utils';
|
|
||||||
import useOnOutsideClick from 'shared/hooks/onOutsideClick';
|
|
||||||
|
|
||||||
type EditorProps = {
|
|
||||||
text: string;
|
|
||||||
initFocus: null | { caret: null | number };
|
|
||||||
autoFocus: number | null;
|
|
||||||
onChangeCurrentText: (text: string) => void;
|
|
||||||
onDeleteEntry: (caret: number) => void;
|
|
||||||
onBlur: () => void;
|
|
||||||
handleChangeText: (caret: number) => void;
|
|
||||||
onDepthChange: (delta: number) => void;
|
|
||||||
onCreateEntry: () => void;
|
|
||||||
onNodeFocused: () => void;
|
|
||||||
};
|
|
||||||
const Editor: React.FC<EditorProps> = ({
|
|
||||||
text,
|
|
||||||
onCreateEntry,
|
|
||||||
initFocus,
|
|
||||||
autoFocus,
|
|
||||||
onChangeCurrentText,
|
|
||||||
onDepthChange,
|
|
||||||
onDeleteEntry,
|
|
||||||
onNodeFocused,
|
|
||||||
handleChangeText,
|
|
||||||
onBlur,
|
|
||||||
}) => {
|
|
||||||
const $editor = useRef<HTMLInputElement>(null);
|
|
||||||
useOnOutsideClick($editor, true, () => onBlur(), null);
|
|
||||||
useEffect(() => {
|
|
||||||
if (autoFocus && $editor.current) {
|
|
||||||
$editor.current.focus();
|
|
||||||
$editor.current.setSelectionRange(autoFocus, autoFocus);
|
|
||||||
onNodeFocused();
|
|
||||||
}
|
|
||||||
}, [autoFocus]);
|
|
||||||
useEffect(() => {
|
|
||||||
if (initFocus && $editor.current) {
|
|
||||||
$editor.current.focus();
|
|
||||||
if (initFocus.caret) {
|
|
||||||
$editor.current.setSelectionRange(initFocus.caret ?? 0, initFocus.caret ?? 0);
|
|
||||||
}
|
|
||||||
onNodeFocused();
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
return (
|
|
||||||
<EntryContentEditor
|
|
||||||
value={text}
|
|
||||||
ref={$editor}
|
|
||||||
onChange={e => {
|
|
||||||
onChangeCurrentText(e.currentTarget.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={e => {
|
|
||||||
if (e.keyCode === 13) {
|
|
||||||
e.preventDefault();
|
|
||||||
// onCreateEntry(parentID, position * 2);
|
|
||||||
onCreateEntry();
|
|
||||||
return;
|
|
||||||
} else if (e.keyCode === 9) {
|
|
||||||
e.preventDefault();
|
|
||||||
onDepthChange(e.shiftKey ? -1 : 1);
|
|
||||||
} else if (e.keyCode === 8) {
|
|
||||||
const caretPos = e.currentTarget.selectionEnd;
|
|
||||||
if (caretPos === 0) {
|
|
||||||
// handleChangeText.flush();
|
|
||||||
// onDeleteEntry(depth, id, currentText, caretPos);
|
|
||||||
onDeleteEntry(caretPos);
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (e.key === 'z' && e.ctrlKey) {
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleChangeText(e.currentTarget.selectionEnd ?? 0);
|
|
||||||
// setCaretPos(e.currentTarget.selectionEnd ?? 0);
|
|
||||||
// handleChangeText();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
type EntryProps = {
|
|
||||||
id: string;
|
|
||||||
collapsed?: boolean;
|
|
||||||
onToggleCollapse: (id: string, collapsed: boolean) => void;
|
|
||||||
parentID: string;
|
|
||||||
onStartDrag: (e: { id: string; clientX: number; clientY: number }) => void;
|
|
||||||
onStartSelect: (e: { id: string; depth: number }) => void;
|
|
||||||
isRoot?: boolean;
|
|
||||||
selection: null | Array<{ id: string }>;
|
|
||||||
draggedNodes: null | Array<string>;
|
|
||||||
onNodeFocused: (id: string) => void;
|
|
||||||
text: string;
|
|
||||||
entries: Array<ItemElement>;
|
|
||||||
onTextChange: (id: string, prex: string, next: string, caret: number) => void;
|
|
||||||
onCancelDrag: () => void;
|
|
||||||
autoFocus: null | { caret: null | number };
|
|
||||||
onCreateEntry: (parent: string, nextPositon: number) => void;
|
|
||||||
position: number;
|
|
||||||
chain?: Array<string>;
|
|
||||||
onHandleClick: (id: string) => void;
|
|
||||||
onDepthChange: (id: string, parent: string, position: number, depth: number, depthDelta: number) => void;
|
|
||||||
onDeleteEntry: (depth: number, id: string, text: string, caretPos: number) => void;
|
|
||||||
depth?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Entry: React.FC<EntryProps> = ({
|
|
||||||
id,
|
|
||||||
text,
|
|
||||||
parentID,
|
|
||||||
isRoot = false,
|
|
||||||
selection,
|
|
||||||
onToggleCollapse,
|
|
||||||
autoFocus,
|
|
||||||
onStartSelect,
|
|
||||||
onHandleClick,
|
|
||||||
onTextChange,
|
|
||||||
position,
|
|
||||||
onNodeFocused,
|
|
||||||
onDepthChange,
|
|
||||||
onCreateEntry,
|
|
||||||
onDeleteEntry,
|
|
||||||
onCancelDrag,
|
|
||||||
onStartDrag,
|
|
||||||
collapsed = false,
|
|
||||||
draggedNodes,
|
|
||||||
entries,
|
|
||||||
chain = [],
|
|
||||||
depth = 0,
|
|
||||||
}) => {
|
|
||||||
const $entry = useRef<HTMLDivElement>(null);
|
|
||||||
const $children = useRef<HTMLDivElement>(null);
|
|
||||||
const { setNodeDimensions, clearNodeDimensions } = useDrag();
|
|
||||||
if (autoFocus) {
|
|
||||||
}
|
|
||||||
|
|
||||||
const $snapshot = useRef<{ now: string; prev: string }>({ now: text, prev: text });
|
|
||||||
const [currentText, setCurrentText] = useState(text);
|
|
||||||
const [caretPos, setCaretPos] = useState(0);
|
|
||||||
const $firstRun = useRef<boolean>(true);
|
|
||||||
useEffect(() => {
|
|
||||||
if ($firstRun.current) {
|
|
||||||
$firstRun.current = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('updating text');
|
|
||||||
setCurrentText(text);
|
|
||||||
}, [text]);
|
|
||||||
|
|
||||||
const [editor, setEditor] = useState<{ open: boolean; caret: null | number }>({
|
|
||||||
open: false,
|
|
||||||
caret: null,
|
|
||||||
});
|
|
||||||
useEffect(() => {
|
|
||||||
if (autoFocus) setEditor({ open: true, caret: null });
|
|
||||||
}, [autoFocus]);
|
|
||||||
useEffect(() => {
|
|
||||||
$snapshot.current.now = currentText;
|
|
||||||
}, [currentText]);
|
|
||||||
const handleChangeText = useCallback(
|
|
||||||
_.debounce(() => {
|
|
||||||
onTextChange(id, $snapshot.current.prev, $snapshot.current.now, caretPos);
|
|
||||||
$snapshot.current.prev = $snapshot.current.now;
|
|
||||||
}, 500),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
const [visible, setVisible] = useState(false);
|
|
||||||
useEffect(() => {
|
|
||||||
if (isRoot) return;
|
|
||||||
if (!visible) {
|
|
||||||
clearNodeDimensions(id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($entry && $entry.current) {
|
|
||||||
setNodeDimensions(id, {
|
|
||||||
entry: $entry,
|
|
||||||
children: entries.length !== 0 ? $children : null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
clearNodeDimensions(id);
|
|
||||||
};
|
|
||||||
}, [position, depth, entries, visible]);
|
|
||||||
let showHandle = true;
|
|
||||||
if (draggedNodes && draggedNodes.length === 1 && draggedNodes.find(c => c === id)) {
|
|
||||||
showHandle = false;
|
|
||||||
}
|
|
||||||
let isSelected = false;
|
|
||||||
if (selection && selection.find(c => c.id === id)) {
|
|
||||||
isSelected = true;
|
|
||||||
}
|
|
||||||
const renderMap: Array<number> = [];
|
|
||||||
const renderer = {
|
|
||||||
text(text: any) {
|
|
||||||
const localId = renderMap.length;
|
|
||||||
renderMap.push(text.length);
|
|
||||||
return `<span id="${id}_${localId}">${text}</span>`;
|
|
||||||
},
|
|
||||||
codespan(text: any) {
|
|
||||||
const localId = renderMap.length;
|
|
||||||
renderMap.push(text.length + 2);
|
|
||||||
return `<span class="markdown-code" id="${id}_${localId}">${text}</span>`;
|
|
||||||
},
|
|
||||||
strong(text: string) {
|
|
||||||
const idx = parseInt(text.split('"')[1].split('_')[1]);
|
|
||||||
renderMap[idx] += 4;
|
|
||||||
return text.replace('<span', '<span class="markdown-strong"');
|
|
||||||
},
|
|
||||||
em(text: string) {
|
|
||||||
const idx = parseInt(text.split('"')[1].split('_')[1]);
|
|
||||||
renderMap[idx] += 2;
|
|
||||||
return text.replace('<span', '<span class="markdown-em"');
|
|
||||||
},
|
|
||||||
del(text: string) {
|
|
||||||
const idx = parseInt(text.split('"')[1].split('_')[1]);
|
|
||||||
renderMap[idx] += 2;
|
|
||||||
return text.replace('<span', '<span class="markdown-del"');
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
marked.use({ renderer });
|
|
||||||
|
|
||||||
const handleMouseDown = useCallback(
|
|
||||||
_.debounce((e: any) => {
|
|
||||||
onStartDrag({ id, clientX: e.clientX, clientY: e.clientY });
|
|
||||||
}, 100),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
<VisibilitySensor
|
|
||||||
onChange={v => {
|
|
||||||
if (v) {
|
|
||||||
setVisible(v);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<EntryWrapper isSelected={isSelected} isDragging={!showHandle}>
|
|
||||||
{!isRoot && (
|
|
||||||
<EntryContent>
|
|
||||||
{entries.length !== 0 && (
|
|
||||||
<ExpandButton onClick={() => onToggleCollapse(id, !collapsed)}>
|
|
||||||
{collapsed ? <CaretRight width={20} height={20} /> : <CaretDown width={20} height={20} />}
|
|
||||||
</ExpandButton>
|
|
||||||
)}
|
|
||||||
{showHandle && (
|
|
||||||
<EntryHandle
|
|
||||||
onMouseUp={() => {
|
|
||||||
handleMouseDown.cancel();
|
|
||||||
onHandleClick(id);
|
|
||||||
}}
|
|
||||||
onMouseDown={e => {
|
|
||||||
handleMouseDown(e);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Dot width={18} height={18} />
|
|
||||||
</EntryHandle>
|
|
||||||
)}
|
|
||||||
<EntryInnerContent
|
|
||||||
onMouseDown={() => {
|
|
||||||
onStartSelect({ id, depth });
|
|
||||||
}}
|
|
||||||
ref={$entry}
|
|
||||||
>
|
|
||||||
{editor.open ? (
|
|
||||||
<Editor
|
|
||||||
onDepthChange={delta => onDepthChange(id, parentID, depth, position, delta)}
|
|
||||||
onBlur={() => setEditor({ open: false, caret: null })}
|
|
||||||
onNodeFocused={() => onNodeFocused(id)}
|
|
||||||
autoFocus={autoFocus ? (autoFocus.caret ? autoFocus.caret : 0) : null}
|
|
||||||
initFocus={editor.open ? { caret: editor.caret } : null}
|
|
||||||
text={currentText}
|
|
||||||
onDeleteEntry={caret => {
|
|
||||||
handleChangeText.flush();
|
|
||||||
onDeleteEntry(depth, id, currentText, caret);
|
|
||||||
}}
|
|
||||||
onCreateEntry={() => {
|
|
||||||
onCreateEntry(parentID, position * 2);
|
|
||||||
}}
|
|
||||||
onChangeCurrentText={text => setCurrentText(text)}
|
|
||||||
handleChangeText={caret => {
|
|
||||||
setCaretPos(caret);
|
|
||||||
handleChangeText();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<EntryContentDisplay
|
|
||||||
onClick={e => {
|
|
||||||
let offset = 0;
|
|
||||||
let textNode: any;
|
|
||||||
if (document.caretPositionFromPoint) {
|
|
||||||
// standard
|
|
||||||
const range = document.caretPositionFromPoint(e.pageX, e.pageY);
|
|
||||||
console.dir(range);
|
|
||||||
if (range) {
|
|
||||||
textNode = range.offsetNode;
|
|
||||||
offset = range.offset;
|
|
||||||
}
|
|
||||||
} else if (document.caretRangeFromPoint) {
|
|
||||||
// WebKit
|
|
||||||
const range = document.caretRangeFromPoint(e.pageX, e.pageY);
|
|
||||||
if (range) {
|
|
||||||
textNode = range.startContainer;
|
|
||||||
offset = range.startOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = textNode.parentNode.id.split('_');
|
|
||||||
const index = parseInt(id[1]);
|
|
||||||
let caret = offset;
|
|
||||||
for (let i = 0; i < index; i++) {
|
|
||||||
caret += renderMap[i];
|
|
||||||
}
|
|
||||||
setEditor({ open: true, caret });
|
|
||||||
}}
|
|
||||||
dangerouslySetInnerHTML={{ __html: marked.parseInline(text) }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</EntryInnerContent>
|
|
||||||
</EntryContent>
|
|
||||||
)}
|
|
||||||
{entries.length !== 0 && !collapsed && (
|
|
||||||
<EntryChildren ref={$children} isRoot={isRoot}>
|
|
||||||
{entries
|
|
||||||
.sort((a, b) => a.position - b.position)
|
|
||||||
.map(entry => (
|
|
||||||
<Entry
|
|
||||||
onDeleteEntry={onDeleteEntry}
|
|
||||||
onHandleClick={onHandleClick}
|
|
||||||
onDepthChange={onDepthChange}
|
|
||||||
parentID={id}
|
|
||||||
key={entry.id}
|
|
||||||
onTextChange={onTextChange}
|
|
||||||
position={entry.position}
|
|
||||||
text={entry.text}
|
|
||||||
depth={depth + 1}
|
|
||||||
draggedNodes={draggedNodes}
|
|
||||||
collapsed={entry.collapsed}
|
|
||||||
id={entry.id}
|
|
||||||
autoFocus={entry.focus}
|
|
||||||
onNodeFocused={onNodeFocused}
|
|
||||||
onStartSelect={onStartSelect}
|
|
||||||
onStartDrag={onStartDrag}
|
|
||||||
onCancelDrag={onCancelDrag}
|
|
||||||
entries={entry.children ?? []}
|
|
||||||
chain={[...chain, id]}
|
|
||||||
selection={selection}
|
|
||||||
onToggleCollapse={onToggleCollapse}
|
|
||||||
onCreateEntry={onCreateEntry}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</EntryChildren>
|
|
||||||
)}
|
|
||||||
</EntryWrapper>
|
|
||||||
</VisibilitySensor>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Entry;
|
|
@ -1,260 +0,0 @@
|
|||||||
import styled, { css } from 'styled-components';
|
|
||||||
import { mixin } from 'shared/utils/styles';
|
|
||||||
|
|
||||||
export const EntryWrapper = styled.div<{ isDragging: boolean; isSelected: boolean }>`
|
|
||||||
position: relative;
|
|
||||||
${props =>
|
|
||||||
props.isDragging &&
|
|
||||||
css`
|
|
||||||
&:before {
|
|
||||||
border-radius: 3px;
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 2px;
|
|
||||||
right: -5px;
|
|
||||||
left: -5px;
|
|
||||||
bottom: -2px;
|
|
||||||
background-color: #eceef0;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
${props =>
|
|
||||||
props.isSelected &&
|
|
||||||
css`
|
|
||||||
&:before {
|
|
||||||
border-radius: 3px;
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 2px;
|
|
||||||
right: -5px;
|
|
||||||
bottom: -2px;
|
|
||||||
left: -5px;
|
|
||||||
background-color: ${mixin.rgba(props.theme.colors.primary, 0.75)};
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const EntryChildren = styled.div<{ isRoot: boolean }>`
|
|
||||||
position: relative;
|
|
||||||
${props =>
|
|
||||||
!props.isRoot &&
|
|
||||||
css`
|
|
||||||
margin-left: 10px;
|
|
||||||
padding-left: 25px;
|
|
||||||
border-left: 1px solid ${mixin.rgba(props.theme.colors.text.primary, 0.6)};
|
|
||||||
`}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const PageContent = styled.div`
|
|
||||||
min-height: calc(100vh - 146px);
|
|
||||||
width: 100%;
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
box-shadow: none;
|
|
||||||
user-select: none;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
max-width: 700px;
|
|
||||||
padding-left: 56px;
|
|
||||||
padding-right: 56px;
|
|
||||||
padding-top: 24px;
|
|
||||||
padding-bottom: 24px;
|
|
||||||
text-size-adjust: none;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const DragHandle = styled.div<{ top: number; left: number }>`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
position: fixed;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
transform: translate3d(${props => props.left}px, ${props => props.top}px, 0);
|
|
||||||
transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1);
|
|
||||||
width: 18px;
|
|
||||||
height: 18px;
|
|
||||||
color: rgb(75, 81, 85);
|
|
||||||
border-radius: 9px;
|
|
||||||
`;
|
|
||||||
export const RootWrapper = styled.div``;
|
|
||||||
|
|
||||||
export const EntryHandle = styled.div`
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
position: absolute;
|
|
||||||
left: 501px;
|
|
||||||
top: 7px;
|
|
||||||
width: 18px;
|
|
||||||
height: 18px;
|
|
||||||
color: ${p => p.theme.colors.text.primary};
|
|
||||||
border-radius: 9px;
|
|
||||||
&:hover {
|
|
||||||
background: ${p => p.theme.colors.primary};
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
fill: ${p => p.theme.colors.text.primary};
|
|
||||||
stroke: ${p => p.theme.colors.text.primary};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
export const EntryContentDisplay = styled.div`
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
font-size: 15px;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
background: none;
|
|
||||||
outline: none;
|
|
||||||
border: none;
|
|
||||||
line-height: 24px;
|
|
||||||
min-height: 24px;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
position: relative;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
color: ${p => p.theme.colors.text.primary};
|
|
||||||
user-select: none;
|
|
||||||
|
|
||||||
cursor: text;
|
|
||||||
.markdown-del {
|
|
||||||
text-decoration: line-through;
|
|
||||||
}
|
|
||||||
.markdown-code {
|
|
||||||
margin-top: -4px;
|
|
||||||
font-size: 16px;
|
|
||||||
line-height: 19px;
|
|
||||||
color: ${props => props.theme.colors.primary};
|
|
||||||
font-family: monospace;
|
|
||||||
padding: 4px 5px 0;
|
|
||||||
font-family: 'Consolas', Courier, monospace;
|
|
||||||
background: ${props => props.theme.colors.bg.primary};
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: middle;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
.markdown-em {
|
|
||||||
margin-top: -4px;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
.markdown-strong {
|
|
||||||
font-weight: 700;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
&:focus {
|
|
||||||
outline: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const EntryContentEditor = styled.input`
|
|
||||||
width: 100%;
|
|
||||||
font-size: 15px;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
background: none;
|
|
||||||
outline: none;
|
|
||||||
border: none;
|
|
||||||
line-height: 24px;
|
|
||||||
min-height: 24px;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
position: relative;
|
|
||||||
user-select: text;
|
|
||||||
color: ${p => p.theme.colors.text.primary};
|
|
||||||
&::selection {
|
|
||||||
background: #a49de8;
|
|
||||||
}
|
|
||||||
&:focus {
|
|
||||||
outline: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const EntryInnerContent = styled.div`
|
|
||||||
padding-top: 4px;
|
|
||||||
font-size: 15px;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
background: none;
|
|
||||||
outline: none;
|
|
||||||
border: none;
|
|
||||||
line-height: 24px;
|
|
||||||
min-height: 24px;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
position: relative;
|
|
||||||
user-select: text;
|
|
||||||
color: ${p => p.theme.colors.text.primary};
|
|
||||||
&::selection {
|
|
||||||
background: #a49de8;
|
|
||||||
}
|
|
||||||
&:focus {
|
|
||||||
outline: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const DragDebugWrapper = styled.div`
|
|
||||||
position: absolute;
|
|
||||||
left: 42px;
|
|
||||||
bottom: 24px;
|
|
||||||
color: #fff;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const DragIndicatorBar = styled.div<{ left: number; top: number; width: number }>`
|
|
||||||
position: fixed;
|
|
||||||
width: ${props => props.width}px;
|
|
||||||
top: ${props => props.top}px;
|
|
||||||
left: ${props => props.left}px;
|
|
||||||
height: 4px;
|
|
||||||
border-radius: 3px;
|
|
||||||
background: rgb(204, 204, 204);
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const ExpandButton = styled.div`
|
|
||||||
top: 6px;
|
|
||||||
cursor: default;
|
|
||||||
color: transparent;
|
|
||||||
position: absolute;
|
|
||||||
top: 6px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
left: 478px;
|
|
||||||
width: 20px;
|
|
||||||
height: 20px;
|
|
||||||
svg {
|
|
||||||
fill: transparent;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
export const EntryContent = styled.div`
|
|
||||||
position: relative;
|
|
||||||
margin-left: -500px;
|
|
||||||
padding-left: 524px;
|
|
||||||
|
|
||||||
&:hover ${ExpandButton} svg {
|
|
||||||
fill: ${props => props.theme.colors.text.primary};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const PageContainer = styled.div`
|
|
||||||
overflow-y: auto;
|
|
||||||
overflow-x: hidden;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const PageName = styled.div`
|
|
||||||
position: relative;
|
|
||||||
margin-left: -100px;
|
|
||||||
padding-left: 100px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
border-color: rgb(170, 170, 170);
|
|
||||||
font-size: 26px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #fff;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const PageNameContent = styled.div`
|
|
||||||
white-space: pre-wrap;
|
|
||||||
line-height: 34px;
|
|
||||||
min-height: 34px;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
position: relative;
|
|
||||||
user-select: text;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const PageNameText = styled.span``;
|
|
@ -1,784 +0,0 @@
|
|||||||
import React, { useState, useRef, useEffect, useMemo, useCallback, useContext, memo, createRef } from 'react';
|
|
||||||
import { DotCircle } from 'shared/icons';
|
|
||||||
import styled from 'styled-components/macro';
|
|
||||||
import GlobalTopNavbar from 'App/TopNavbar';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import produce from 'immer';
|
|
||||||
import Entry from './Entry';
|
|
||||||
import DragIndicator from './DragIndicator';
|
|
||||||
import Dragger from './Dragger';
|
|
||||||
import DragDebug from './DragDebug';
|
|
||||||
import { DragContext } from './useDrag';
|
|
||||||
|
|
||||||
import {
|
|
||||||
PageContainer,
|
|
||||||
DragDebugWrapper,
|
|
||||||
DragIndicatorBar,
|
|
||||||
PageContent,
|
|
||||||
EntryChildren,
|
|
||||||
EntryInnerContent,
|
|
||||||
EntryWrapper,
|
|
||||||
EntryContent,
|
|
||||||
RootWrapper,
|
|
||||||
EntryHandle,
|
|
||||||
PageNameContent,
|
|
||||||
PageNameText,
|
|
||||||
PageName,
|
|
||||||
} from './Styles';
|
|
||||||
import {
|
|
||||||
transformToTree,
|
|
||||||
findNode,
|
|
||||||
findNodeDepth,
|
|
||||||
getNumberOfChildren,
|
|
||||||
validateDepth,
|
|
||||||
getDimensions,
|
|
||||||
findNextDraggable,
|
|
||||||
getNodeOver,
|
|
||||||
getCorrectNode,
|
|
||||||
findCommonParent,
|
|
||||||
getNodeAbove,
|
|
||||||
findNodeAbove,
|
|
||||||
} from './utils';
|
|
||||||
import NOOP from 'shared/utils/noop';
|
|
||||||
|
|
||||||
enum CommandType {
|
|
||||||
MOVE,
|
|
||||||
MERGE,
|
|
||||||
CHANGE_TEXT,
|
|
||||||
DELETE,
|
|
||||||
CREATE,
|
|
||||||
}
|
|
||||||
|
|
||||||
type MoveData = {
|
|
||||||
prev: { position: number; parent: string | null };
|
|
||||||
next: { position: number; parent: string | null };
|
|
||||||
};
|
|
||||||
|
|
||||||
type ChangeTextData = {
|
|
||||||
node: {
|
|
||||||
id: string;
|
|
||||||
parentID: string;
|
|
||||||
position: number;
|
|
||||||
};
|
|
||||||
caret: number;
|
|
||||||
prev: string;
|
|
||||||
next: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type DeleteData = {
|
|
||||||
node: {
|
|
||||||
id: string;
|
|
||||||
parentID: string;
|
|
||||||
position: number;
|
|
||||||
text: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type OutlineCommand = {
|
|
||||||
nodes: Array<{
|
|
||||||
id: string;
|
|
||||||
type: CommandType;
|
|
||||||
data: MoveData | DeleteData | ChangeTextData;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ItemCollapsed = {
|
|
||||||
id: string;
|
|
||||||
collapsed: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
function generateItems(c: number) {
|
|
||||||
const items: Array<ItemElement> = [];
|
|
||||||
for (let i = 0; i < c; i++) {
|
|
||||||
items.push({
|
|
||||||
collapsed: false,
|
|
||||||
focus: null,
|
|
||||||
id: `entry-gen-${i}`,
|
|
||||||
text: `entry-gen-${i}`,
|
|
||||||
parent: 'root',
|
|
||||||
position: 4096 * (6 + i),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
const listItems: Array<ItemElement> = [
|
|
||||||
{ id: 'root', text: '', position: 4096, parent: null, collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-1', text: 'entry-1', position: 4096, parent: 'root', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-1-3', text: 'entry-1-3', position: 4096 * 3, parent: 'entry-1', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-1-3-1', text: 'entry-1-3-1', position: 4096, parent: 'entry-1-3', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-1-3-2', text: 'entry-1-3-2', position: 4096 * 2, parent: 'entry-1-3', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-1-3-3', text: 'entry-1-3-3', position: 4096 * 3, parent: 'entry-1-3', collapsed: false, focus: null },
|
|
||||||
{
|
|
||||||
id: 'entry-1-3-3-1',
|
|
||||||
text: '*Hello!* I am `doing super` well ~how~ are **you**?',
|
|
||||||
position: 4096 * 1,
|
|
||||||
parent: 'entry-1-3-3',
|
|
||||||
collapsed: false,
|
|
||||||
focus: null,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'entry-1-3-3-1-1',
|
|
||||||
text: 'entry-1-3-3-1-1',
|
|
||||||
position: 4096 * 1,
|
|
||||||
parent: 'entry-1-3-3-1',
|
|
||||||
collapsed: false,
|
|
||||||
focus: null,
|
|
||||||
},
|
|
||||||
{ id: 'entry-2', text: 'entry-2', position: 4096 * 2, parent: 'root', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-3', text: 'entry-3', position: 4096 * 3, parent: 'root', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-4', text: 'entry-4', position: 4096 * 4, parent: 'root', collapsed: false, focus: null },
|
|
||||||
{ id: 'entry-5', text: 'entry-5', position: 4096 * 5, parent: 'root', collapsed: false, focus: null },
|
|
||||||
...generateItems(100),
|
|
||||||
];
|
|
||||||
|
|
||||||
const Outline: React.FC = () => {
|
|
||||||
const [items, setItems] = useState(listItems);
|
|
||||||
const [selecting, setSelecting] = useState<{
|
|
||||||
isSelecting: boolean;
|
|
||||||
node: { id: string; depth: number } | null;
|
|
||||||
}>({ isSelecting: false, node: null });
|
|
||||||
const [selection, setSelection] = useState<null | { nodes: Array<{ id: string }>; first?: OutlineNode | null }>(null);
|
|
||||||
const [dragging, setDragging] = useState<{
|
|
||||||
show: boolean;
|
|
||||||
draggedNodes: null | Array<string>;
|
|
||||||
initialPos: { x: number; y: number };
|
|
||||||
}>({ show: false, draggedNodes: null, initialPos: { x: 0, y: 0 } });
|
|
||||||
const [impact, setImpact] = useState<null | {
|
|
||||||
listPosition: number;
|
|
||||||
zone: ImpactZone;
|
|
||||||
depthTarget: number;
|
|
||||||
}>(null);
|
|
||||||
const selectRef = useRef<{ isSelecting: boolean; hasSelection: boolean; node: { id: string; depth: number } | null }>(
|
|
||||||
{
|
|
||||||
isSelecting: false,
|
|
||||||
node: null,
|
|
||||||
hasSelection: false,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const impactRef = useRef<null | { listPosition: number; depth: number; zone: ImpactZone }>(null);
|
|
||||||
useEffect(() => {
|
|
||||||
if (impact) {
|
|
||||||
impactRef.current = { zone: impact.zone, depth: impact.depthTarget, listPosition: impact.listPosition };
|
|
||||||
}
|
|
||||||
}, [impact]);
|
|
||||||
useEffect(() => {
|
|
||||||
selectRef.current.isSelecting = selecting.isSelecting;
|
|
||||||
selectRef.current.node = selecting.node;
|
|
||||||
}, [selecting]);
|
|
||||||
|
|
||||||
const $content = useRef<HTMLDivElement>(null);
|
|
||||||
const outline = useRef<OutlineData>({
|
|
||||||
published: new Map<string, string>(),
|
|
||||||
dimensions: new Map<string, NodeDimensions>(),
|
|
||||||
nodes: new Map<number, Map<string, OutlineNode>>(),
|
|
||||||
relationships: new Map<string, NodeRelationships>(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const tree = transformToTree(_.cloneDeep(items));
|
|
||||||
let root: any = null;
|
|
||||||
if (tree.length === 1) {
|
|
||||||
root = tree[0];
|
|
||||||
}
|
|
||||||
const outlineHistory = useRef<{ commands: Array<OutlineCommand>; current: number }>({ current: -1, commands: [] });
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
outline.current.relationships = new Map<string, NodeRelationships>();
|
|
||||||
outline.current.published = new Map<string, string>();
|
|
||||||
outline.current.nodes = new Map<number, Map<string, OutlineNode>>();
|
|
||||||
const collapsedMap = items.reduce((map, next) => {
|
|
||||||
if (next.collapsed) {
|
|
||||||
map.set(next.id, true);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}, new Map<string, boolean>());
|
|
||||||
items.forEach(item => outline.current.published.set(item.id, item.parent ?? 'root'));
|
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
|
||||||
const { collapsed, position, id, parent: curParent } = items[i];
|
|
||||||
if (id === 'root') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const parent = curParent ?? 'root';
|
|
||||||
outline.current.published.set(id, parent ?? 'root');
|
|
||||||
const foundDepth = findNodeDepth(outline.current.published, id);
|
|
||||||
if (foundDepth === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const { depth, ancestors } = foundDepth;
|
|
||||||
const collapsedParent = ancestors.slice(0, -1).find(a => collapsedMap.get(a));
|
|
||||||
if (collapsedParent) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const children = getNumberOfChildren(root, ancestors);
|
|
||||||
if (!outline.current.nodes.has(depth)) {
|
|
||||||
outline.current.nodes.set(depth, new Map<string, OutlineNode>());
|
|
||||||
}
|
|
||||||
const targetDepthNodes = outline.current.nodes.get(depth);
|
|
||||||
if (targetDepthNodes) {
|
|
||||||
targetDepthNodes.set(id, {
|
|
||||||
id,
|
|
||||||
children,
|
|
||||||
position,
|
|
||||||
depth,
|
|
||||||
ancestors,
|
|
||||||
collapsed,
|
|
||||||
parent,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!outline.current.relationships.has(parent)) {
|
|
||||||
outline.current.relationships.set(parent, {
|
|
||||||
self: {
|
|
||||||
depth: depth - 1,
|
|
||||||
id: parent,
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
numberOfSubChildren: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const nodeRelations = outline.current.relationships.get(parent);
|
|
||||||
if (nodeRelations) {
|
|
||||||
outline.current.relationships.set(parent, {
|
|
||||||
self: nodeRelations.self,
|
|
||||||
numberOfSubChildren: nodeRelations.numberOfSubChildren + children,
|
|
||||||
children: [...nodeRelations.children, { id, position, depth, children }].sort(
|
|
||||||
(a, b) => a.position - b.position,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [items]);
|
|
||||||
const handleKeyDown = useCallback(e => {
|
|
||||||
if (e.code === 'KeyZ' && e.ctrlKey) {
|
|
||||||
const currentCommand = outlineHistory.current.commands[outlineHistory.current.current];
|
|
||||||
if (currentCommand) {
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
currentCommand.nodes.forEach(node => {
|
|
||||||
const idx = prevItems.findIndex(c => c.id === node.id);
|
|
||||||
if (node.type === CommandType.MOVE) {
|
|
||||||
if (idx === -1) return;
|
|
||||||
const data = node.data as MoveData;
|
|
||||||
draftItems[idx].parent = data.prev.parent;
|
|
||||||
draftItems[idx].position = data.prev.position;
|
|
||||||
} else if (node.type === CommandType.CHANGE_TEXT) {
|
|
||||||
if (idx === -1) return;
|
|
||||||
const data = node.data as ChangeTextData;
|
|
||||||
draftItems[idx] = produce(prevItems[idx], draftItem => {
|
|
||||||
draftItem.text = data.prev;
|
|
||||||
draftItem.focus = { caret: data.caret };
|
|
||||||
});
|
|
||||||
} else if (node.type === CommandType.DELETE) {
|
|
||||||
const data = node.data as DeleteData;
|
|
||||||
draftItems.push({
|
|
||||||
id: data.node.id,
|
|
||||||
position: data.node.position,
|
|
||||||
parent: data.node.parentID,
|
|
||||||
text: '',
|
|
||||||
focus: { caret: null },
|
|
||||||
children: [],
|
|
||||||
collapsed: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
outlineHistory.current.current--;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (e.code === 'KeyY' && e.ctrlKey) {
|
|
||||||
const currentCommand = outlineHistory.current.commands[outlineHistory.current.current + 1];
|
|
||||||
if (currentCommand) {
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
currentCommand.nodes.forEach(node => {
|
|
||||||
const idx = prevItems.findIndex(c => c.id === node.id);
|
|
||||||
if (idx !== -1) {
|
|
||||||
if (node.type === CommandType.MOVE) {
|
|
||||||
const data = node.data as MoveData;
|
|
||||||
draftItems[idx].parent = data.next.parent;
|
|
||||||
draftItems[idx].position = data.next.position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
outlineHistory.current.current++;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleMouseUp = useCallback(
|
|
||||||
e => {
|
|
||||||
if (selectRef.current.hasSelection && !selectRef.current.isSelecting) {
|
|
||||||
setSelection(null);
|
|
||||||
}
|
|
||||||
if (selectRef.current.isSelecting) {
|
|
||||||
setSelecting({ isSelecting: false, node: null });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[dragging, selecting],
|
|
||||||
);
|
|
||||||
const handleMouseMove = useCallback(e => {
|
|
||||||
if (selectRef.current.isSelecting && selectRef.current.node) {
|
|
||||||
const { clientX, clientY } = e;
|
|
||||||
const dimensions = outline.current.dimensions.get(selectRef.current.node.id);
|
|
||||||
if (dimensions) {
|
|
||||||
const entry = getDimensions(dimensions.entry);
|
|
||||||
if (entry) {
|
|
||||||
const isAbove = clientY < entry.top;
|
|
||||||
const isBelow = clientY > entry.bottom;
|
|
||||||
if (!isAbove && !isBelow && selectRef.current.hasSelection) {
|
|
||||||
const nodeDepth = outline.current.nodes.get(selectRef.current.node.depth);
|
|
||||||
const aboveNode = nodeDepth ? nodeDepth.get(selectRef.current.node.id) : null;
|
|
||||||
if (aboveNode) {
|
|
||||||
setSelection({ nodes: [{ id: selectRef.current.node.id }], first: aboveNode });
|
|
||||||
selectRef.current.hasSelection = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isAbove || isBelow) {
|
|
||||||
e.preventDefault();
|
|
||||||
const { curDraggable } = getNodeOver({ x: clientX, y: clientY }, outline.current);
|
|
||||||
const nodeDepth = outline.current.nodes.get(selectRef.current.node.depth);
|
|
||||||
const selectedNode = nodeDepth ? nodeDepth.get(selectRef.current.node.id) : null;
|
|
||||||
let aboveNode: OutlineNode | undefined | null = null;
|
|
||||||
let belowNode: OutlineNode | undefined | null = null;
|
|
||||||
if (isBelow) {
|
|
||||||
aboveNode = selectedNode;
|
|
||||||
belowNode = curDraggable;
|
|
||||||
} else {
|
|
||||||
aboveNode = curDraggable;
|
|
||||||
belowNode = selectedNode;
|
|
||||||
}
|
|
||||||
if (aboveNode && belowNode) {
|
|
||||||
const aboveDim = outline.current.dimensions.get(aboveNode.id);
|
|
||||||
const belowDim = outline.current.dimensions.get(belowNode.id);
|
|
||||||
if (aboveDim && belowDim) {
|
|
||||||
const aboveDimBounds = getDimensions(aboveDim.entry);
|
|
||||||
const belowDimBounds = getDimensions(belowDim.children ? belowDim.children : belowDim.entry);
|
|
||||||
const aboveDimY = aboveDimBounds ? aboveDimBounds.bottom : 0;
|
|
||||||
const belowDimY = belowDimBounds ? belowDimBounds.top : 0;
|
|
||||||
const inbetweenNodes: Array<{ id: string }> = [];
|
|
||||||
for (const [id, dimension] of outline.current.dimensions.entries()) {
|
|
||||||
if (id === aboveNode.id || id === belowNode.id) {
|
|
||||||
inbetweenNodes.push({ id });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const targetNodeBounds = getDimensions(dimension.entry);
|
|
||||||
if (targetNodeBounds) {
|
|
||||||
if (
|
|
||||||
Math.round(aboveDimY) <= Math.round(targetNodeBounds.top) &&
|
|
||||||
Math.round(belowDimY) >= Math.round(targetNodeBounds.bottom)
|
|
||||||
) {
|
|
||||||
inbetweenNodes.push({ id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const filteredNodes = inbetweenNodes.filter(n => {
|
|
||||||
const parent = outline.current.published.get(n.id);
|
|
||||||
if (parent) {
|
|
||||||
const foundParent = inbetweenNodes.find(c => c.id === parent);
|
|
||||||
if (foundParent) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
selectRef.current.hasSelection = true;
|
|
||||||
setSelection({ nodes: filteredNodes, first: aboveNode });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
useEffect(() => {
|
|
||||||
document.addEventListener('mouseup', handleMouseUp);
|
|
||||||
document.addEventListener('mousemove', handleMouseMove);
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('mouseup', handleMouseUp);
|
|
||||||
document.removeEventListener('mousemove', handleMouseMove);
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const $page = useRef<HTMLDivElement>(null);
|
|
||||||
const $pageName = useRef<HTMLDivElement>(null);
|
|
||||||
if (!root) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<GlobalTopNavbar onSaveProjectName={NOOP} projectID={null} name={null} />
|
|
||||||
<DragContext.Provider
|
|
||||||
value={{
|
|
||||||
outline,
|
|
||||||
impact,
|
|
||||||
setImpact: data => {
|
|
||||||
if (data) {
|
|
||||||
const { zone, depth } = data;
|
|
||||||
let listPosition = 65535;
|
|
||||||
if (zone.above && zone.above.node.depth + 1 <= depth && zone.above.node.collapsed) {
|
|
||||||
const aboveChildren = items
|
|
||||||
.filter(i => (zone.above ? i.parent === zone.above.node.id : false))
|
|
||||||
.sort((a, b) => a.position - b.position);
|
|
||||||
const lastChild = aboveChildren[aboveChildren.length - 1];
|
|
||||||
if (lastChild) {
|
|
||||||
listPosition = lastChild.position * 2.0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const correctNode = getCorrectNode(outline.current, zone.above ? zone.above.node : null, depth);
|
|
||||||
const listAbove = validateDepth(correctNode, depth);
|
|
||||||
const listBelow = validateDepth(zone.below ? zone.below.node : null, depth);
|
|
||||||
if (listAbove && listBelow) {
|
|
||||||
listPosition = (listAbove.position + listBelow.position) / 2.0;
|
|
||||||
} else if (listAbove && !listBelow) {
|
|
||||||
listPosition = listAbove.position * 2.0;
|
|
||||||
} else if (!listAbove && listBelow) {
|
|
||||||
listPosition = listBelow.position / 2.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!zone.above && zone.below) {
|
|
||||||
const newPosition = zone.below.node.position / 2.0;
|
|
||||||
setImpact(() => ({
|
|
||||||
zone,
|
|
||||||
listPosition: newPosition,
|
|
||||||
depthTarget: depth,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
if (zone.above) {
|
|
||||||
// console.log(`prev=${prev} next=${next} targetPosition=${targetPosition}`);
|
|
||||||
// let targetID = depthTarget === 1 ? 'root' : node.ancestors[depthTarget - 1];
|
|
||||||
// targetID = targetID ?? node.id;
|
|
||||||
setImpact(() => ({
|
|
||||||
zone,
|
|
||||||
listPosition,
|
|
||||||
depthTarget: depth,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setImpact(null);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setNodeDimensions: (nodeID, ref) => {
|
|
||||||
outline.current.dimensions.set(nodeID, ref);
|
|
||||||
},
|
|
||||||
clearNodeDimensions: nodeID => {
|
|
||||||
outline.current.dimensions.delete(nodeID);
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<>
|
|
||||||
<PageContainer ref={$page}>
|
|
||||||
<PageContent>
|
|
||||||
<RootWrapper ref={$content}>
|
|
||||||
<PageName>
|
|
||||||
<PageNameContent ref={$pageName}>
|
|
||||||
<PageNameText>entry-1-3-1</PageNameText>
|
|
||||||
</PageNameContent>
|
|
||||||
</PageName>
|
|
||||||
<Entry
|
|
||||||
onDepthChange={(id, parentID, position, depth, depthDelta) => {
|
|
||||||
if (depthDelta === -1) {
|
|
||||||
const parentRelation = outline.current.relationships.get(parentID);
|
|
||||||
if (parentRelation) {
|
|
||||||
const nodeIdx = parentRelation.children
|
|
||||||
.sort((a, b) => a.position - b.position)
|
|
||||||
.findIndex(c => c.id === id);
|
|
||||||
if (parentRelation.children.length !== 0) {
|
|
||||||
const grandparent = outline.current.published.get(parentID);
|
|
||||||
if (grandparent) {
|
|
||||||
const grandparentNode = outline.current.relationships.get(grandparent);
|
|
||||||
if (grandparentNode) {
|
|
||||||
const parents = grandparentNode.children.sort((a, b) => a.position - b.position);
|
|
||||||
const parentIdx = parents.findIndex(c => c.id === parentID);
|
|
||||||
if (parentIdx === -1) return;
|
|
||||||
let position = parents[parentIdx].position * 2;
|
|
||||||
const nextParent = parents[parentIdx + 1];
|
|
||||||
if (nextParent) {
|
|
||||||
position = (parents[parentIdx].position + nextParent.position) / 2.0;
|
|
||||||
}
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
const idx = prevItems.findIndex(c => c.id === id);
|
|
||||||
draftItems[idx] = produce(prevItems[idx], draftItem => {
|
|
||||||
draftItem.parent = grandparent;
|
|
||||||
draftItem.position = position;
|
|
||||||
draftItem.focus = { caret: 0 };
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const parent = outline.current.relationships.get(parentID);
|
|
||||||
if (parent) {
|
|
||||||
const nodeIdx = parent.children
|
|
||||||
.sort((a, b) => a.position - b.position)
|
|
||||||
.findIndex(c => c.id === id);
|
|
||||||
const aboveNode = parent.children[nodeIdx - 1];
|
|
||||||
if (aboveNode) {
|
|
||||||
const aboveNodeRelations = outline.current.relationships.get(aboveNode.id);
|
|
||||||
let position = 65535;
|
|
||||||
if (aboveNodeRelations) {
|
|
||||||
const children = aboveNodeRelations.children.sort((a, b) => a.position - b.position);
|
|
||||||
if (children.length !== 0) {
|
|
||||||
position = children[children.length - 1].position * 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
const idx = prevItems.findIndex(c => c.id === id);
|
|
||||||
draftItems[idx] = produce(prevItems[idx], draftItem => {
|
|
||||||
draftItem.parent = aboveNode.id;
|
|
||||||
draftItem.position = position;
|
|
||||||
draftItem.focus = { caret: 0 };
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onTextChange={(id, prev, next, caret) => {
|
|
||||||
outlineHistory.current.current += 1;
|
|
||||||
const data: ChangeTextData = {
|
|
||||||
node: {
|
|
||||||
id,
|
|
||||||
position: 0,
|
|
||||||
parentID: '',
|
|
||||||
},
|
|
||||||
caret,
|
|
||||||
prev,
|
|
||||||
next,
|
|
||||||
};
|
|
||||||
const command: OutlineCommand = {
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id,
|
|
||||||
type: CommandType.CHANGE_TEXT,
|
|
||||||
data,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
outlineHistory.current.commands[outlineHistory.current.current] = command;
|
|
||||||
if (outlineHistory.current.commands[outlineHistory.current.current + 1]) {
|
|
||||||
outlineHistory.current.commands.splice(outlineHistory.current.current + 1);
|
|
||||||
}
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
const idx = prevItems.findIndex(c => c.id === id);
|
|
||||||
if (idx !== -1) {
|
|
||||||
draftItems[idx] = produce(prevItems[idx], draftItem => {
|
|
||||||
draftItem.text = next;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
text=""
|
|
||||||
autoFocus={null}
|
|
||||||
onDeleteEntry={(depth, id, text, caretPos) => {
|
|
||||||
const nodeDepth = outline.current.nodes.get(depth);
|
|
||||||
if (nodeDepth) {
|
|
||||||
const node = nodeDepth.get(id);
|
|
||||||
if (node) {
|
|
||||||
const nodeAbove = findNodeAbove(outline.current, depth, node);
|
|
||||||
setItems(prevItems => {
|
|
||||||
return produce(prevItems, draftItems => {
|
|
||||||
draftItems = prevItems.filter(c => c.id !== id);
|
|
||||||
const idx = prevItems.findIndex(c => c.id === nodeAbove?.id);
|
|
||||||
if (idx !== -1) {
|
|
||||||
draftItems[idx] = produce(prevItems[idx], draftItem => {
|
|
||||||
draftItem.focus = { caret: draftItem.text.length };
|
|
||||||
const cType = CommandType.DELETE;
|
|
||||||
const data: DeleteData = {
|
|
||||||
node: {
|
|
||||||
id,
|
|
||||||
position: node.position,
|
|
||||||
parentID: node.parent,
|
|
||||||
text: '',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (text !== '') {
|
|
||||||
draftItem.text += text;
|
|
||||||
}
|
|
||||||
|
|
||||||
const command: OutlineCommand = {
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id,
|
|
||||||
type: cType,
|
|
||||||
data,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
outlineHistory.current.current += 1;
|
|
||||||
outlineHistory.current.commands[outlineHistory.current.current] = command;
|
|
||||||
if (outlineHistory.current.commands[outlineHistory.current.current + 1]) {
|
|
||||||
outlineHistory.current.commands.splice(outlineHistory.current.current + 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return draftItems;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onCreateEntry={(parent, position) => {
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
draftItems.push({
|
|
||||||
id: '' + Math.random(),
|
|
||||||
collapsed: false,
|
|
||||||
position,
|
|
||||||
text: '',
|
|
||||||
focus: {
|
|
||||||
caret: null,
|
|
||||||
},
|
|
||||||
parent,
|
|
||||||
children: [],
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
onNodeFocused={id => {
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
const idx = draftItems.findIndex(c => c.id === id);
|
|
||||||
draftItems[idx] = produce(draftItems[idx], draftItem => {
|
|
||||||
draftItem.focus = null;
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
onStartSelect={({ id, depth }) => {
|
|
||||||
setSelection(null);
|
|
||||||
setSelecting({ isSelecting: true, node: { id, depth } });
|
|
||||||
}}
|
|
||||||
onToggleCollapse={(id, collapsed) => {
|
|
||||||
setItems(prevItems =>
|
|
||||||
produce(prevItems, draftItems => {
|
|
||||||
const idx = prevItems.findIndex(c => c.id === id);
|
|
||||||
if (idx !== -1) {
|
|
||||||
draftItems[idx].collapsed = collapsed;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
id="root"
|
|
||||||
parentID="root"
|
|
||||||
isRoot
|
|
||||||
selection={selection ? selection.nodes : null}
|
|
||||||
draggedNodes={dragging.draggedNodes}
|
|
||||||
position={root.position}
|
|
||||||
entries={root.children}
|
|
||||||
onCancelDrag={() => {
|
|
||||||
setImpact(null);
|
|
||||||
setDragging({ show: false, draggedNodes: null, initialPos: { x: 0, y: 0 } });
|
|
||||||
}}
|
|
||||||
onHandleClick={id => {}}
|
|
||||||
onStartDrag={e => {
|
|
||||||
if (e.id !== 'root') {
|
|
||||||
if (selectRef.current.hasSelection && selection && selection.nodes.find(c => c.id === e.id)) {
|
|
||||||
setImpact(null);
|
|
||||||
setDragging({
|
|
||||||
show: true,
|
|
||||||
draggedNodes: [...selection.nodes.map(c => c.id)],
|
|
||||||
initialPos: { x: e.clientX, y: e.clientY },
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setImpact(null);
|
|
||||||
setDragging({ show: true, draggedNodes: [e.id], initialPos: { x: e.clientX, y: e.clientY } });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</RootWrapper>
|
|
||||||
</PageContent>
|
|
||||||
</PageContainer>
|
|
||||||
{dragging.show && dragging.draggedNodes && (
|
|
||||||
<Dragger
|
|
||||||
container={$content}
|
|
||||||
initialPos={dragging.initialPos}
|
|
||||||
pageRef={$page}
|
|
||||||
draggedNodes={{ nodes: dragging.draggedNodes, first: selection ? selection.first : null }}
|
|
||||||
isDragging={dragging.show}
|
|
||||||
onDragEnd={() => {
|
|
||||||
if (dragging.draggedNodes && impactRef.current) {
|
|
||||||
const { zone, depth, listPosition } = impactRef.current;
|
|
||||||
const noZone = !zone.above && !zone.below;
|
|
||||||
if (!noZone) {
|
|
||||||
let parentID = 'root';
|
|
||||||
if (zone.above) {
|
|
||||||
parentID = zone.above.node.ancestors[depth - 1];
|
|
||||||
}
|
|
||||||
let reparent = true;
|
|
||||||
for (let i = 0; i < dragging.draggedNodes.length; i++) {
|
|
||||||
const draggedID = dragging.draggedNodes[i];
|
|
||||||
const prevItem = items.find(i => i.id === draggedID);
|
|
||||||
if (prevItem && prevItem.position === listPosition && prevItem.parent === parentID) {
|
|
||||||
reparent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: set reparent if list position changed but parent did not
|
|
||||||
//
|
|
||||||
|
|
||||||
if (reparent) {
|
|
||||||
// UPDATE OUTLINE DATA AFTER NODE MOVE
|
|
||||||
setItems(itemsPrev =>
|
|
||||||
produce(itemsPrev, draftItems => {
|
|
||||||
if (dragging.draggedNodes) {
|
|
||||||
const command: OutlineCommand = { nodes: [] };
|
|
||||||
outlineHistory.current.current += 1;
|
|
||||||
dragging.draggedNodes.forEach(n => {
|
|
||||||
const curDragging = itemsPrev.findIndex(i => i.id === n);
|
|
||||||
command.nodes.push({
|
|
||||||
id: n,
|
|
||||||
type: CommandType.MOVE,
|
|
||||||
data: {
|
|
||||||
prev: {
|
|
||||||
parent: draftItems[curDragging].parent,
|
|
||||||
position: draftItems[curDragging].position,
|
|
||||||
},
|
|
||||||
next: {
|
|
||||||
parent: parentID,
|
|
||||||
position: listPosition,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
draftItems[curDragging].parent = parentID;
|
|
||||||
draftItems[curDragging].position = listPosition;
|
|
||||||
});
|
|
||||||
outlineHistory.current.commands[outlineHistory.current.current] = command;
|
|
||||||
if (outlineHistory.current.commands[outlineHistory.current.current + 1]) {
|
|
||||||
outlineHistory.current.commands.splice(outlineHistory.current.current + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setImpact(null);
|
|
||||||
setDragging({ show: false, draggedNodes: null, initialPos: { x: 0, y: 0 } });
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
</DragContext.Provider>
|
|
||||||
{impact && <DragIndicator depthTarget={impact.depthTarget} container={$content} zone={impact.zone} />}
|
|
||||||
{impact && (
|
|
||||||
<DragDebug zone={impact.zone ?? null} draggedNodes={dragging.draggedNodes} depthTarget={impact.depthTarget} />
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Outline;
|
|
@ -1,22 +0,0 @@
|
|||||||
import React, { useContext } from 'react';
|
|
||||||
|
|
||||||
type DragContextData = {
|
|
||||||
impact: null | { zone: ImpactZone; depthTarget: number };
|
|
||||||
outline: React.MutableRefObject<OutlineData>;
|
|
||||||
setNodeDimensions: (
|
|
||||||
nodeID: string,
|
|
||||||
ref: { entry: React.RefObject<HTMLElement>; children: React.RefObject<HTMLElement> | null },
|
|
||||||
) => void;
|
|
||||||
clearNodeDimensions: (nodeID: string) => void;
|
|
||||||
setImpact: (data: ImpactData | null) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DragContext = React.createContext<DragContextData | null>(null);
|
|
||||||
|
|
||||||
export const useDrag = () => {
|
|
||||||
const ctx = useContext(DragContext);
|
|
||||||
if (ctx) {
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
throw new Error('context is null');
|
|
||||||
};
|
|
@ -1,409 +0,0 @@
|
|||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
export function getCorrectNode(data: OutlineData, node: OutlineNode | null, depth: number) {
|
|
||||||
if (node) {
|
|
||||||
if (depth === node.depth) {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
const parent = node.ancestors[depth];
|
|
||||||
if (parent) {
|
|
||||||
const parentNode = data.relationships.get(parent);
|
|
||||||
if (parentNode) {
|
|
||||||
const parentDepth = parentNode.self.depth;
|
|
||||||
const nodeDepth = data.nodes.get(parentDepth);
|
|
||||||
return nodeDepth ? nodeDepth.get(parent) : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
export function validateDepth(node: OutlineNode | null | undefined, depth: number) {
|
|
||||||
if (node) {
|
|
||||||
return node.depth === depth ? node : null;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNodeAbove(node: OutlineNode, startingParent: RelationshipChild, outline: OutlineData) {
|
|
||||||
let hasChildren = true;
|
|
||||||
let nodeAbove: null | RelationshipChild = null;
|
|
||||||
let aboveTargetID = startingParent.id;
|
|
||||||
while (hasChildren) {
|
|
||||||
const targetParent = outline.relationships.get(aboveTargetID);
|
|
||||||
if (targetParent) {
|
|
||||||
const parentNodes = outline.nodes.get(targetParent.self.depth);
|
|
||||||
const parentNode = parentNodes ? parentNodes.get(targetParent.self.id) : null;
|
|
||||||
if (targetParent.children.length === 0) {
|
|
||||||
if (parentNode) {
|
|
||||||
nodeAbove = {
|
|
||||||
id: parentNode.id,
|
|
||||||
depth: parentNode.depth,
|
|
||||||
position: parentNode.position,
|
|
||||||
children: parentNode.children,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
hasChildren = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
nodeAbove = targetParent.children[targetParent.children.length - 1];
|
|
||||||
if (targetParent.numberOfSubChildren === 0) {
|
|
||||||
hasChildren = false;
|
|
||||||
} else {
|
|
||||||
aboveTargetID = nodeAbove.id;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const target = outline.relationships.get(node.ancestors[0]);
|
|
||||||
if (target) {
|
|
||||||
const targetChild = target.children.find(i => i.id === aboveTargetID);
|
|
||||||
if (targetChild) {
|
|
||||||
nodeAbove = targetChild;
|
|
||||||
}
|
|
||||||
hasChildren = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodeAbove;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getBelowParent(node: OutlineNode, outline: OutlineData) {
|
|
||||||
const { relationships, nodes } = outline;
|
|
||||||
const parentDepth = nodes.get(node.depth - 1);
|
|
||||||
const parent = parentDepth ? parentDepth.get(node.parent) : null;
|
|
||||||
if (parent) {
|
|
||||||
const grandfather = relationships.get(parent.parent);
|
|
||||||
if (grandfather) {
|
|
||||||
const parentIndex = grandfather.children.findIndex(c => c.id === parent.id);
|
|
||||||
if (parentIndex !== -1) {
|
|
||||||
if (parentIndex === grandfather.children.length - 1) {
|
|
||||||
const root = relationships.get(node.ancestors[0]);
|
|
||||||
if (root) {
|
|
||||||
const ancestorIndex = root.children.findIndex(c => c.id === node.ancestors[1]);
|
|
||||||
if (ancestorIndex !== -1) {
|
|
||||||
const nextAncestor = root.children[ancestorIndex + 1];
|
|
||||||
if (nextAncestor) {
|
|
||||||
return nextAncestor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const nextChild = grandfather.children[parentIndex + 1];
|
|
||||||
if (nextChild) {
|
|
||||||
return nextChild;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDimensions(ref: React.RefObject<HTMLElement> | null | undefined) {
|
|
||||||
if (ref && ref.current) {
|
|
||||||
return ref.current.getBoundingClientRect();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTargetDepth(mouseX: number, handleLeft: number, availableDepths: { min: number; max: number }) {
|
|
||||||
if (mouseX > handleLeft) {
|
|
||||||
return availableDepths.max;
|
|
||||||
}
|
|
||||||
let curDepth = availableDepths.max - 1;
|
|
||||||
for (let x = availableDepths.min; x < availableDepths.max; x++) {
|
|
||||||
const breakpoint = handleLeft - x * 35;
|
|
||||||
if (mouseX > breakpoint) {
|
|
||||||
return curDepth;
|
|
||||||
}
|
|
||||||
curDepth -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return availableDepths.min;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findNextDraggable(pos: { x: number; y: number }, outline: OutlineData, curDepth: number) {
|
|
||||||
let index = 0;
|
|
||||||
const currentDepthNodes = outline.nodes.get(curDepth);
|
|
||||||
let nodeAbove: null | RelationshipChild = null;
|
|
||||||
if (!currentDepthNodes) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (const [id, node] of currentDepthNodes) {
|
|
||||||
const dimensions = outline.dimensions.get(id);
|
|
||||||
const target = dimensions ? getDimensions(dimensions.entry) : null;
|
|
||||||
const children = dimensions ? getDimensions(dimensions.children) : null;
|
|
||||||
if (target) {
|
|
||||||
if (pos.y <= target.bottom && pos.y >= target.top) {
|
|
||||||
const middlePoint = target.top + target.height / 2;
|
|
||||||
const position: ImpactPosition = pos.y > middlePoint ? 'after' : 'before';
|
|
||||||
return {
|
|
||||||
found: true,
|
|
||||||
node,
|
|
||||||
position,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (children) {
|
|
||||||
if (pos.y <= children.bottom && pos.y >= children.top) {
|
|
||||||
const position: ImpactPosition = 'after';
|
|
||||||
return { found: false, node, position };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function transformToTree(arr: any) {
|
|
||||||
const nodes: any = {};
|
|
||||||
return arr.filter(function(obj: any) {
|
|
||||||
var id = obj['id'],
|
|
||||||
parentId = obj['parent'];
|
|
||||||
|
|
||||||
nodes[id] = _.defaults(obj, nodes[id], { children: [] });
|
|
||||||
parentId && (nodes[parentId] = nodes[parentId] || { children: [] })['children'].push(obj);
|
|
||||||
|
|
||||||
return !parentId;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findNode(parentID: string, nodeID: string, data: OutlineData) {
|
|
||||||
const nodeRelations = data.relationships.get(parentID);
|
|
||||||
if (nodeRelations) {
|
|
||||||
const nodeDepth = data.nodes.get(nodeRelations.self.depth + 1);
|
|
||||||
if (nodeDepth) {
|
|
||||||
const node = nodeDepth.get(nodeID);
|
|
||||||
return node ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findNodeDepth(published: Map<string, string>, id: string) {
|
|
||||||
let currentID = id;
|
|
||||||
let breaker = 0;
|
|
||||||
let depth = 0;
|
|
||||||
let ancestors = [id];
|
|
||||||
while (currentID !== 'root') {
|
|
||||||
const nextID = published.get(currentID);
|
|
||||||
if (nextID) {
|
|
||||||
ancestors = [nextID, ...ancestors];
|
|
||||||
currentID = nextID;
|
|
||||||
depth += 1;
|
|
||||||
breaker += 1;
|
|
||||||
if (breaker > 100) {
|
|
||||||
throw new Error('node depth breaker was thrown');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { depth, ancestors };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNumberOfChildren(root: ItemElement, ancestors: Array<string>) {
|
|
||||||
let currentBranch = root;
|
|
||||||
for (let i = 1; i < ancestors.length; i++) {
|
|
||||||
const nextBranch = currentBranch.children ? currentBranch.children.find(c => c.id === ancestors[i]) : null;
|
|
||||||
if (nextBranch) {
|
|
||||||
currentBranch = nextBranch;
|
|
||||||
} else {
|
|
||||||
throw new Error('unable to find next branch');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return currentBranch.children ? currentBranch.children.length : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findNodeAbove(outline: OutlineData, curDepth: number, belowNode: OutlineNode) {
|
|
||||||
let targetAboveNode: null | RelationshipChild = null;
|
|
||||||
if (curDepth === 1) {
|
|
||||||
const relations = outline.relationships.get(belowNode.ancestors[0]);
|
|
||||||
if (relations) {
|
|
||||||
const parentIndex = relations.children.findIndex(n => belowNode && n.id === belowNode.ancestors[1]);
|
|
||||||
if (parentIndex !== -1) {
|
|
||||||
const aboveParent = relations.children[parentIndex - 1];
|
|
||||||
if (parentIndex === 0) {
|
|
||||||
targetAboveNode = null;
|
|
||||||
} else {
|
|
||||||
targetAboveNode = getNodeAbove(belowNode, aboveParent, outline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const relations = outline.relationships.get(belowNode.parent);
|
|
||||||
if (relations) {
|
|
||||||
const currentIndex = relations.children.findIndex(n => belowNode && n.id === belowNode.id);
|
|
||||||
// is first child, so use parent
|
|
||||||
if (currentIndex === 0) {
|
|
||||||
const parentNodes = outline.nodes.get(belowNode.depth - 1);
|
|
||||||
const parentNode = parentNodes ? parentNodes.get(belowNode.parent) : null;
|
|
||||||
if (parentNode) {
|
|
||||||
targetAboveNode = {
|
|
||||||
id: belowNode.parent,
|
|
||||||
depth: belowNode.depth - 1,
|
|
||||||
position: parentNode.position,
|
|
||||||
children: parentNode.children,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else if (currentIndex !== -1) {
|
|
||||||
// is not first child, so first prev sibling
|
|
||||||
const aboveParentNode = relations.children[currentIndex - 1];
|
|
||||||
if (aboveParentNode) {
|
|
||||||
targetAboveNode = getNodeAbove(belowNode, aboveParentNode, outline);
|
|
||||||
if (targetAboveNode === null) {
|
|
||||||
targetAboveNode = aboveParentNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetAboveNode) {
|
|
||||||
const depthNodes = outline.nodes.get(targetAboveNode.depth);
|
|
||||||
if (depthNodes) {
|
|
||||||
return depthNodes.get(targetAboveNode.id) ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNodeOver(mouse: { x: number; y: number }, outline: OutlineData) {
|
|
||||||
let curDepth = 1;
|
|
||||||
let curDraggables: any;
|
|
||||||
let curDraggable: any;
|
|
||||||
let curPosition: ImpactPosition = 'after';
|
|
||||||
while (outline.nodes.size + 1 > curDepth) {
|
|
||||||
curDraggables = outline.nodes.get(curDepth);
|
|
||||||
if (curDraggables) {
|
|
||||||
const nextDraggable = findNextDraggable(mouse, outline, curDepth);
|
|
||||||
if (nextDraggable) {
|
|
||||||
curDraggable = nextDraggable.node;
|
|
||||||
curPosition = nextDraggable.position;
|
|
||||||
if (nextDraggable.found) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
curDepth += 1;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
curDepth,
|
|
||||||
curDraggable,
|
|
||||||
curPosition,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findCommonParent(outline: OutlineData, aboveNode: OutlineNode, belowNode: OutlineNode) {
|
|
||||||
let aboveParentID = null;
|
|
||||||
let depth = 0;
|
|
||||||
for (let aIdx = aboveNode.ancestors.length - 1; aIdx !== 0; aIdx--) {
|
|
||||||
depth = aIdx;
|
|
||||||
const aboveNodeParent = aboveNode.ancestors[aIdx];
|
|
||||||
for (let bIdx = belowNode.ancestors.length - 1; bIdx !== 0; bIdx--) {
|
|
||||||
if (belowNode.ancestors[bIdx] === aboveNodeParent) {
|
|
||||||
aboveParentID = aboveNodeParent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (aboveParentID) {
|
|
||||||
const parent = outline.relationships.get(aboveParentID) ?? null;
|
|
||||||
if (parent) {
|
|
||||||
return {
|
|
||||||
parent,
|
|
||||||
depth,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLastChildInBranch(outline: OutlineData, lastParentNode: OutlineNode) {
|
|
||||||
let curParentRelation = outline.relationships.get(lastParentNode.id);
|
|
||||||
if (!curParentRelation) {
|
|
||||||
return { id: lastParentNode.id, depth: 1 };
|
|
||||||
}
|
|
||||||
let hasChildren = lastParentNode.children !== 0;
|
|
||||||
let depth = 1;
|
|
||||||
let finalID: null | string = null;
|
|
||||||
while (hasChildren) {
|
|
||||||
if (curParentRelation) {
|
|
||||||
const lastChild = curParentRelation.children.sort((a, b) => a.position - b.position)[
|
|
||||||
curParentRelation.children.length - 1
|
|
||||||
];
|
|
||||||
depth += 1;
|
|
||||||
if (lastChild.children === 0) {
|
|
||||||
finalID = lastChild.id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
curParentRelation = outline.relationships.get(lastChild.id);
|
|
||||||
} else {
|
|
||||||
hasChildren = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (finalID !== null) {
|
|
||||||
return { id: finalID, depth };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCaretPosition(editableDiv: any) {
|
|
||||||
/*
|
|
||||||
let caretPos = 0;
|
|
||||||
let sel: any = null;
|
|
||||||
let range: any = null;
|
|
||||||
if (window.getSelection) {
|
|
||||||
sel = window.getSelection();
|
|
||||||
if (sel && sel.rangeCount) {
|
|
||||||
range = sel.getRangeAt(0);
|
|
||||||
if (range.commonAncestorContainer.parentNode === editableDiv.current) {
|
|
||||||
caretPos = range.endOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return editableDiv.selectionEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createRange(node: any, chars: any, range: any) {
|
|
||||||
if (!range) {
|
|
||||||
range = document.createRange();
|
|
||||||
range.selectNode(node);
|
|
||||||
range.setStart(node, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chars.count === 0) {
|
|
||||||
range.setEnd(node, chars.count);
|
|
||||||
} else if (node && chars.count > 0) {
|
|
||||||
if (node.nodeType === Node.TEXT_NODE) {
|
|
||||||
if (node.textContent.length < chars.count) {
|
|
||||||
chars.count -= node.textContent.length;
|
|
||||||
} else {
|
|
||||||
range.setEnd(node, chars.count);
|
|
||||||
chars.count = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (var lp = 0; lp < node.childNodes.length; lp++) {
|
|
||||||
range = createRange(node.childNodes[lp], chars, range);
|
|
||||||
|
|
||||||
if (chars.count === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setCurrentCursorPosition(element: any, chars: any) {
|
|
||||||
if (chars >= 0) {
|
|
||||||
const selection = window.getSelection();
|
|
||||||
const range = createRange(element, { count: chars }, false);
|
|
||||||
if (range && selection) {
|
|
||||||
range.collapse(false);
|
|
||||||
selection.removeAllRanges();
|
|
||||||
selection.addRange(range);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -280,7 +280,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.findProject.taskGroups = draftCache.findProject.taskGroups.filter(
|
draftCache.findProject.taskGroups = draftCache.findProject.taskGroups.filter(
|
||||||
(taskGroup: TaskGroup) => taskGroup.id !== deletedTaskGroupData.data?.deleteTaskGroup.taskGroup.id,
|
(taskGroup: TaskGroup) => taskGroup.id !== deletedTaskGroupData.data.deleteTaskGroup.taskGroup.id,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
@ -296,11 +296,9 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
const { taskGroups } = cache.findProject;
|
const { taskGroups } = cache.findProject;
|
||||||
const idx = taskGroups.findIndex(taskGroup => taskGroup.id === newTaskData.data?.createTask.taskGroup.id);
|
const idx = taskGroups.findIndex(taskGroup => taskGroup.id === newTaskData.data.createTask.taskGroup.id);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
if (newTaskData.data) {
|
draftCache.findProject.taskGroups[idx].tasks.push({ ...newTaskData.data.createTask });
|
||||||
draftCache.findProject.taskGroups[idx].tasks.push({ ...newTaskData.data.createTask });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
@ -315,9 +313,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (newTaskGroupData.data) {
|
draftCache.findProject.taskGroups.push({ ...newTaskGroupData.data.createTaskGroup, tasks: [] });
|
||||||
draftCache.findProject.taskGroups.push({ ...newTaskGroupData.data.createTaskGroup, tasks: [] });
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
);
|
);
|
||||||
@ -336,7 +332,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
const idx = cache.findProject.taskGroups.findIndex(
|
const idx = cache.findProject.taskGroups.findIndex(
|
||||||
t => t.id === resp.data?.deleteTaskGroupTasks.taskGroupID,
|
t => t.id === resp.data.deleteTaskGroupTasks.taskGroupID,
|
||||||
);
|
);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
draftCache.findProject.taskGroups[idx].tasks = [];
|
draftCache.findProject.taskGroups[idx].tasks = [];
|
||||||
@ -352,9 +348,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (resp.data) {
|
draftCache.findProject.taskGroups.push(resp.data.duplicateTaskGroup.taskGroup);
|
||||||
draftCache.findProject.taskGroups.push(resp.data.duplicateTaskGroup.taskGroup);
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
);
|
);
|
||||||
@ -370,24 +364,19 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (newTask.data) {
|
const { previousTaskGroupID, task } = newTask.data.updateTaskLocation;
|
||||||
const { previousTaskGroupID, task } = newTask.data.updateTaskLocation;
|
if (previousTaskGroupID !== task.taskGroup.id) {
|
||||||
if (previousTaskGroupID !== task.taskGroup.id) {
|
const { taskGroups } = cache.findProject;
|
||||||
const { taskGroups } = cache.findProject;
|
const oldTaskGroupIdx = taskGroups.findIndex((t: TaskGroup) => t.id === previousTaskGroupID);
|
||||||
const oldTaskGroupIdx = taskGroups.findIndex((t: TaskGroup) => t.id === previousTaskGroupID);
|
const newTaskGroupIdx = taskGroups.findIndex((t: TaskGroup) => t.id === task.taskGroup.id);
|
||||||
const newTaskGroupIdx = taskGroups.findIndex((t: TaskGroup) => t.id === task.taskGroup.id);
|
if (oldTaskGroupIdx !== -1 && newTaskGroupIdx !== -1) {
|
||||||
if (oldTaskGroupIdx !== -1 && newTaskGroupIdx !== -1) {
|
draftCache.findProject.taskGroups[oldTaskGroupIdx].tasks = taskGroups[oldTaskGroupIdx].tasks.filter(
|
||||||
const previousTask = cache.findProject.taskGroups[oldTaskGroupIdx].tasks.find(t => t.id === task.id);
|
(t: Task) => t.id !== task.id,
|
||||||
draftCache.findProject.taskGroups[oldTaskGroupIdx].tasks = taskGroups[oldTaskGroupIdx].tasks.filter(
|
);
|
||||||
(t: Task) => t.id !== task.id,
|
draftCache.findProject.taskGroups[newTaskGroupIdx].tasks = [
|
||||||
);
|
...taskGroups[newTaskGroupIdx].tasks,
|
||||||
if (previousTask) {
|
{ ...task },
|
||||||
draftCache.findProject.taskGroups[newTaskGroupIdx].tasks = [
|
];
|
||||||
...taskGroups[newTaskGroupIdx].tasks,
|
|
||||||
{ ...previousTask },
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -138,23 +138,21 @@ const Details: React.FC<DetailsProps> = ({
|
|||||||
FindTaskDocument,
|
FindTaskDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (response.data) {
|
const { prevChecklistID, checklistID, checklistItem } = response.data.updateTaskChecklistItemLocation;
|
||||||
const { prevChecklistID, taskChecklistID, checklistItem } = response.data.updateTaskChecklistItemLocation;
|
if (checklistID !== prevChecklistID) {
|
||||||
if (taskChecklistID !== prevChecklistID) {
|
const oldIdx = cache.findTask.checklists.findIndex(c => c.id === prevChecklistID);
|
||||||
const oldIdx = cache.findTask.checklists.findIndex(c => c.id === prevChecklistID);
|
const newIdx = cache.findTask.checklists.findIndex(c => c.id === checklistID);
|
||||||
const newIdx = cache.findTask.checklists.findIndex(c => c.id === taskChecklistID);
|
if (oldIdx > -1 && newIdx > -1) {
|
||||||
if (oldIdx > -1 && newIdx > -1) {
|
const item = cache.findTask.checklists[oldIdx].items.find(i => i.id === checklistItem.id);
|
||||||
const item = cache.findTask.checklists[oldIdx].items.find(i => i.id === checklistItem.id);
|
if (item) {
|
||||||
if (item) {
|
draftCache.findTask.checklists[oldIdx].items = cache.findTask.checklists[oldIdx].items.filter(
|
||||||
draftCache.findTask.checklists[oldIdx].items = cache.findTask.checklists[oldIdx].items.filter(
|
i => i.id !== checklistItem.id,
|
||||||
i => i.id !== checklistItem.id,
|
);
|
||||||
);
|
draftCache.findTask.checklists[newIdx].items.push({
|
||||||
draftCache.findTask.checklists[newIdx].items.push({
|
...item,
|
||||||
...item,
|
position: checklistItem.position,
|
||||||
position: checklistItem.position,
|
taskChecklistID: checklistID,
|
||||||
taskChecklistID: taskChecklistID,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +188,7 @@ const Details: React.FC<DetailsProps> = ({
|
|||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
const { checklists } = cache.findTask;
|
const { checklists } = cache.findTask;
|
||||||
draftCache.findTask.checklists = checklists.filter(
|
draftCache.findTask.checklists = checklists.filter(
|
||||||
c => c.id !== deleteData.data?.deleteTaskChecklist.taskChecklist.id,
|
c => c.id !== deleteData.data.deleteTaskChecklist.taskChecklist.id,
|
||||||
);
|
);
|
||||||
const { complete, total } = calculateChecklistBadge(draftCache.findTask.checklists);
|
const { complete, total } = calculateChecklistBadge(draftCache.findTask.checklists);
|
||||||
draftCache.findTask.badges.checklist = {
|
draftCache.findTask.badges.checklist = {
|
||||||
@ -214,10 +212,8 @@ const Details: React.FC<DetailsProps> = ({
|
|||||||
FindTaskDocument,
|
FindTaskDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (createData.data) {
|
const item = createData.data.createTaskChecklist;
|
||||||
const item = createData.data.createTaskChecklist;
|
draftCache.findTask.checklists.push({ ...item });
|
||||||
draftCache.findTask.checklists.push({ ...item });
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
{ taskID },
|
{ taskID },
|
||||||
);
|
);
|
||||||
@ -231,21 +227,19 @@ const Details: React.FC<DetailsProps> = ({
|
|||||||
FindTaskDocument,
|
FindTaskDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (deleteData.data) {
|
const item = deleteData.data.deleteTaskChecklistItem.taskChecklistItem;
|
||||||
const item = deleteData.data.deleteTaskChecklistItem.taskChecklistItem;
|
const targetIdx = cache.findTask.checklists.findIndex(c => c.id === item.taskChecklistID);
|
||||||
const targetIdx = cache.findTask.checklists.findIndex(c => c.id === item.taskChecklistID);
|
if (targetIdx > -1) {
|
||||||
if (targetIdx > -1) {
|
draftCache.findTask.checklists[targetIdx].items = cache.findTask.checklists[targetIdx].items.filter(
|
||||||
draftCache.findTask.checklists[targetIdx].items = cache.findTask.checklists[targetIdx].items.filter(
|
c => item.id !== c.id,
|
||||||
c => item.id !== c.id,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
const { complete, total } = calculateChecklistBadge(draftCache.findTask.checklists);
|
|
||||||
draftCache.findTask.badges.checklist = {
|
|
||||||
__typename: 'ChecklistBadge',
|
|
||||||
complete,
|
|
||||||
total,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
const { complete, total } = calculateChecklistBadge(draftCache.findTask.checklists);
|
||||||
|
draftCache.findTask.badges.checklist = {
|
||||||
|
__typename: 'ChecklistBadge',
|
||||||
|
complete,
|
||||||
|
total,
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
{ taskID },
|
{ taskID },
|
||||||
);
|
);
|
||||||
@ -258,26 +252,24 @@ const Details: React.FC<DetailsProps> = ({
|
|||||||
FindTaskDocument,
|
FindTaskDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (newTaskItem.data) {
|
const item = newTaskItem.data.createTaskChecklistItem;
|
||||||
const item = newTaskItem.data.createTaskChecklistItem;
|
const { checklists } = cache.findTask;
|
||||||
const { checklists } = cache.findTask;
|
const idx = checklists.findIndex(c => c.id === item.taskChecklistID);
|
||||||
const idx = checklists.findIndex(c => c.id === item.taskChecklistID);
|
if (idx !== -1) {
|
||||||
if (idx !== -1) {
|
draftCache.findTask.checklists[idx].items.push({ ...item });
|
||||||
draftCache.findTask.checklists[idx].items.push({ ...item });
|
const { complete, total } = calculateChecklistBadge(draftCache.findTask.checklists);
|
||||||
const { complete, total } = calculateChecklistBadge(draftCache.findTask.checklists);
|
draftCache.findTask.badges.checklist = {
|
||||||
draftCache.findTask.badges.checklist = {
|
__typename: 'ChecklistBadge',
|
||||||
__typename: 'ChecklistBadge',
|
complete,
|
||||||
complete,
|
total,
|
||||||
total,
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{ taskID },
|
{ taskID },
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { loading, data, refetch } = useFindTaskQuery({ variables: { taskID }, fetchPolicy: 'cache-and-network' });
|
const { loading, data, refetch } = useFindTaskQuery({ variables: { taskID } });
|
||||||
const [setTaskComplete] = useSetTaskCompleteMutation();
|
const [setTaskComplete] = useSetTaskCompleteMutation();
|
||||||
const [updateTaskDueDate] = useUpdateTaskDueDateMutation({
|
const [updateTaskDueDate] = useUpdateTaskDueDateMutation({
|
||||||
onCompleted: () => {
|
onCompleted: () => {
|
||||||
|
@ -36,9 +36,7 @@ const LabelManagerEditor: React.FC<LabelManagerEditorProps> = ({
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (newLabelData.data) {
|
draftCache.findProject.labels.push({ ...newLabelData.data.createProjectLabel });
|
||||||
draftCache.findProject.labels.push({ ...newLabelData.data.createProjectLabel });
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
projectID,
|
projectID,
|
||||||
@ -55,7 +53,7 @@ const LabelManagerEditor: React.FC<LabelManagerEditorProps> = ({
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.findProject.labels = cache.findProject.labels.filter(
|
draftCache.findProject.labels = cache.findProject.labels.filter(
|
||||||
label => label.id !== newLabelData.data?.deleteProjectLabel.id,
|
label => label.id !== newLabelData.data.deleteProjectLabel.id,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
|
@ -32,6 +32,7 @@ import {
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
FindProjectQuery,
|
FindProjectQuery,
|
||||||
} from 'shared/generated/graphql';
|
} from 'shared/generated/graphql';
|
||||||
|
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import UserContext, { useCurrentUser } from 'App/context';
|
import UserContext, { useCurrentUser } from 'App/context';
|
||||||
import Input from 'shared/components/Input';
|
import Input from 'shared/components/Input';
|
||||||
@ -422,16 +423,14 @@ const Project = () => {
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (resp.data) {
|
const taskGroupIdx = draftCache.findProject.taskGroups.findIndex(
|
||||||
const taskGroupIdx = draftCache.findProject.taskGroups.findIndex(
|
tg => tg.tasks.findIndex(t => t.id === resp.data.deleteTask.taskID) !== -1,
|
||||||
tg => tg.tasks.findIndex(t => t.id === resp.data?.deleteTask.taskID) !== -1,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (taskGroupIdx !== -1) {
|
if (taskGroupIdx !== -1) {
|
||||||
draftCache.findProject.taskGroups[taskGroupIdx].tasks = cache.findProject.taskGroups[
|
draftCache.findProject.taskGroups[taskGroupIdx].tasks = cache.findProject.taskGroups[
|
||||||
taskGroupIdx
|
taskGroupIdx
|
||||||
].tasks.filter(t => t.id !== resp.data?.deleteTask.taskID);
|
].tasks.filter(t => t.id !== resp.data.deleteTask.taskID);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
@ -451,7 +450,7 @@ const Project = () => {
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.findProject.name = newName.data?.updateProjectName.name ?? '';
|
draftCache.findProject.name = newName.data.updateProjectName.name;
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
);
|
);
|
||||||
@ -465,16 +464,14 @@ const Project = () => {
|
|||||||
FindProjectDocument,
|
FindProjectDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (response.data) {
|
draftCache.findProject.members = [
|
||||||
draftCache.findProject.members = [
|
...cache.findProject.members,
|
||||||
...cache.findProject.members,
|
...response.data.inviteProjectMembers.members,
|
||||||
...response.data.inviteProjectMembers.members,
|
];
|
||||||
];
|
draftCache.findProject.invitedMembers = [
|
||||||
draftCache.findProject.invitedMembers = [
|
...cache.findProject.invitedMembers,
|
||||||
...cache.findProject.invitedMembers,
|
...response.data.inviteProjectMembers.invitedMembers,
|
||||||
...response.data.inviteProjectMembers.invitedMembers,
|
];
|
||||||
];
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
);
|
);
|
||||||
@ -488,7 +485,7 @@ const Project = () => {
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.findProject.invitedMembers = cache.findProject.invitedMembers.filter(
|
draftCache.findProject.invitedMembers = cache.findProject.invitedMembers.filter(
|
||||||
m => m.email !== response.data?.deleteInvitedProjectMember.invitedMember.email ?? '',
|
m => m.email !== response.data.deleteInvitedProjectMember.invitedMember.email,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
@ -503,7 +500,7 @@ const Project = () => {
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.findProject.members = cache.findProject.members.filter(
|
draftCache.findProject.members = cache.findProject.members.filter(
|
||||||
m => m.id !== response.data?.deleteProjectMember.member.id,
|
m => m.id !== response.data.deleteProjectMember.member.id,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
{ projectID },
|
{ projectID },
|
||||||
|
@ -210,9 +210,7 @@ const Projects = () => {
|
|||||||
update: (client, newProject) => {
|
update: (client, newProject) => {
|
||||||
updateApolloCache<GetProjectsQuery>(client, GetProjectsDocument, cache =>
|
updateApolloCache<GetProjectsQuery>(client, GetProjectsDocument, cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (newProject.data) {
|
draftCache.projects.push({ ...newProject.data.createProject });
|
||||||
draftCache.projects.push({ ...newProject.data.createProject });
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -224,9 +222,7 @@ const Projects = () => {
|
|||||||
update: (client, createData) => {
|
update: (client, createData) => {
|
||||||
updateApolloCache<GetProjectsQuery>(client, GetProjectsDocument, cache =>
|
updateApolloCache<GetProjectsQuery>(client, GetProjectsDocument, cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (createData.data) {
|
draftCache.teams.push({ ...createData.data.createTeam });
|
||||||
draftCache.teams.push({ ...createData.data?.createTeam });
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -430,13 +430,11 @@ const Members: React.FC<MembersProps> = ({ teamID }) => {
|
|||||||
GetTeamDocument,
|
GetTeamDocument,
|
||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
if (response.data) {
|
draftCache.findTeam.members.push({
|
||||||
draftCache.findTeam.members.push({
|
...response.data.createTeamMember.teamMember,
|
||||||
...response.data.createTeamMember.teamMember,
|
member: { __typename: 'MemberList', projects: [], teams: [] },
|
||||||
member: { __typename: 'MemberList', projects: [], teams: [] },
|
owned: { __typename: 'OwnedList', projects: [], teams: [] },
|
||||||
owned: { __typename: 'OwnedList', projects: [], teams: [] },
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
{ teamID },
|
{ teamID },
|
||||||
);
|
);
|
||||||
@ -461,7 +459,7 @@ const Members: React.FC<MembersProps> = ({ teamID }) => {
|
|||||||
cache =>
|
cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.findTeam.members = cache.findTeam.members.filter(
|
draftCache.findTeam.members = cache.findTeam.members.filter(
|
||||||
member => member.id !== response.data?.deleteTeamMember.userID,
|
member => member.id !== response.data.deleteTeamMember.userID,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
{ teamID },
|
{ teamID },
|
||||||
|
@ -33,7 +33,7 @@ const Wrapper = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
type TeamPopupProps = {
|
type TeamPopupProps = {
|
||||||
history: History<any>;
|
history: History<History.PoorMansUnknown>;
|
||||||
name: string;
|
name: string;
|
||||||
teamID: string;
|
teamID: string;
|
||||||
};
|
};
|
||||||
@ -44,9 +44,9 @@ export const TeamPopup: React.FC<TeamPopupProps> = ({ history, name, teamID }) =
|
|||||||
update: (client, deleteData) => {
|
update: (client, deleteData) => {
|
||||||
updateApolloCache<GetProjectsQuery>(client, GetProjectsDocument, cache =>
|
updateApolloCache<GetProjectsQuery>(client, GetProjectsDocument, cache =>
|
||||||
produce(cache, draftCache => {
|
produce(cache, draftCache => {
|
||||||
draftCache.teams = cache.teams.filter((team: any) => team.id !== deleteData.data?.deleteTeam.team.id);
|
draftCache.teams = cache.teams.filter((team: any) => team.id !== deleteData.data.deleteTeam.team.id);
|
||||||
draftCache.projects = cache.projects.filter(
|
draftCache.projects = cache.projects.filter(
|
||||||
(project: any) => project.team.id !== deleteData.data?.deleteTeam.team.id,
|
(project: any) => project.team.id !== deleteData.data.deleteTeam.team.id,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -20,14 +20,14 @@ export const MemberManagerSearch = styled(TextareaAutosize)`
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
|
||||||
background: ${props => props.theme.colors.bg.secondary};
|
background: ${props => props.theme.colors.bgColor.secondary};
|
||||||
outline: none;
|
outline: none;
|
||||||
color: ${props => props.theme.colors.text.primary};
|
color: ${props => props.theme.colors.text.primary};
|
||||||
border-color: ${props => props.theme.colors.border};
|
border-color: ${props => props.theme.colors.border};
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
box-shadow: ${props => props.theme.colors.primary} 0px 0px 0px 1px;
|
box-shadow: ${props => props.theme.colors.primary} 0px 0px 0px 1px;
|
||||||
background: ${props => mixin.darken(props.theme.colors.bg.secondary, 0.15)};
|
background: ${props => mixin.darken(props.theme.colors.bgColor.secondary, 0.15)};
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ const NewProject: React.FC<NewProjectProps> = ({ initialTeamID, teams, onClose,
|
|||||||
onChange={(e: any) => {
|
onChange={(e: any) => {
|
||||||
setTeam(e.value);
|
setTeam(e.value);
|
||||||
}}
|
}}
|
||||||
value={options.find(d => d.value === team)}
|
value={options.filter(d => d.value === team)}
|
||||||
styles={colourStyles}
|
styles={colourStyles}
|
||||||
classNamePrefix="teamSelect"
|
classNamePrefix="teamSelect"
|
||||||
options={options}
|
options={options}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { TaskActivityData, ActivityType } from 'shared/generated/graphql';
|
|
||||||
|
|
||||||
type ActivityMessageProps = {
|
|
||||||
type: ActivityType;
|
|
||||||
data: Array<TaskActivityData>;
|
|
||||||
};
|
|
||||||
|
|
||||||
function getVariable(data: Array<TaskActivityData>, name: string) {
|
|
||||||
const target = data.find(d => d.name === name);
|
|
||||||
return target ? target.value : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ActivityMessage: React.FC<ActivityMessageProps> = ({ type, data }) => {
|
|
||||||
switch (type) {
|
|
||||||
case ActivityType.TaskAdded:
|
|
||||||
return <>`added this task to ${getVariable(data, 'TaskGroup')}`</>;
|
|
||||||
}
|
|
||||||
return <h1>hello</h1>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ActivityMessage;
|
|
@ -537,26 +537,25 @@ export const ActivityItem = styled.div`
|
|||||||
overflow-wrap: break-word;
|
overflow-wrap: break-word;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
display: flex;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const ActivityItemHeader = styled.div`
|
export const ActivityItemHeader = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
|
||||||
padding-left: 8px;
|
|
||||||
`;
|
`;
|
||||||
export const ActivityItemHeaderUser = styled(TaskAssignee)``;
|
export const ActivityItemHeaderUser = styled(TaskAssignee)`
|
||||||
|
margin-right: 4px;
|
||||||
|
`;
|
||||||
|
|
||||||
export const ActivityItemHeaderTitle = styled.div`
|
export const ActivityItemHeaderTitle = styled.div`
|
||||||
|
margin-left: 4px;
|
||||||
|
line-height: 18px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: ${props => props.theme.colors.text.primary};
|
|
||||||
padding-bottom: 2px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const ActivityItemHeaderTitleName = styled.span`
|
export const ActivityItemHeaderTitleName = styled.span`
|
||||||
|
color: ${props => props.theme.colors.text.primary};
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
padding-right: 2px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const ActivityItemTimestamp = styled.span<{ margin: number }>`
|
export const ActivityItemTimestamp = styled.span<{ margin: number }>`
|
||||||
|
@ -19,12 +19,8 @@ import styled from 'styled-components';
|
|||||||
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
|
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import ActivityMessage from './ActivityMessage';
|
|
||||||
import Task from 'shared/icons/Task';
|
import Task from 'shared/icons/Task';
|
||||||
import {
|
import {
|
||||||
ActivityItemHeader,
|
|
||||||
ActivityItemTimestamp,
|
|
||||||
ActivityItem,
|
|
||||||
TaskDetailLabel,
|
TaskDetailLabel,
|
||||||
CommentContainer,
|
CommentContainer,
|
||||||
MetaDetailContent,
|
MetaDetailContent,
|
||||||
@ -71,13 +67,9 @@ import {
|
|||||||
CommentInnerWrapper,
|
CommentInnerWrapper,
|
||||||
ActivitySection,
|
ActivitySection,
|
||||||
TaskDetailsEditor,
|
TaskDetailsEditor,
|
||||||
ActivityItemHeaderUser,
|
|
||||||
ActivityItemHeaderTitle,
|
|
||||||
ActivityItemHeaderTitleName,
|
|
||||||
} from './Styles';
|
} from './Styles';
|
||||||
import Checklist, { ChecklistItem, ChecklistItems } from '../Checklist';
|
import Checklist, { ChecklistItem, ChecklistItems } from '../Checklist';
|
||||||
import onDragEnd from './onDragEnd';
|
import onDragEnd from './onDragEnd';
|
||||||
import TaskAssignee from 'shared/components/TaskAssignee';
|
|
||||||
|
|
||||||
const ChecklistContainer = styled.div``;
|
const ChecklistContainer = styled.div``;
|
||||||
|
|
||||||
@ -433,36 +425,7 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({
|
|||||||
<TabBarSection>
|
<TabBarSection>
|
||||||
<TabBarItem>Activity</TabBarItem>
|
<TabBarItem>Activity</TabBarItem>
|
||||||
</TabBarSection>
|
</TabBarSection>
|
||||||
<ActivitySection>
|
<ActivitySection />
|
||||||
{task.activity &&
|
|
||||||
task.activity.map(activity => (
|
|
||||||
<ActivityItem>
|
|
||||||
<ActivityItemHeaderUser
|
|
||||||
size={32}
|
|
||||||
member={{
|
|
||||||
id: activity.causedBy.id,
|
|
||||||
fullName: activity.causedBy.fullName,
|
|
||||||
profileIcon: activity.causedBy.profileIcon
|
|
||||||
? activity.causedBy.profileIcon
|
|
||||||
: {
|
|
||||||
url: null,
|
|
||||||
initials: activity.causedBy.fullName.charAt(0),
|
|
||||||
bgColor: '#fff',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<ActivityItemHeader>
|
|
||||||
<ActivityItemHeaderTitle>
|
|
||||||
<ActivityItemHeaderTitleName>{activity.causedBy.fullName}</ActivityItemHeaderTitleName>
|
|
||||||
<ActivityMessage type={activity.type} data={activity.data} />
|
|
||||||
</ActivityItemHeaderTitle>
|
|
||||||
<ActivityItemTimestamp margin={0}>
|
|
||||||
{dayjs(activity.createdAt).format('MMM D [at] h:mm A')}
|
|
||||||
</ActivityItemTimestamp>
|
|
||||||
</ActivityItemHeader>
|
|
||||||
</ActivityItem>
|
|
||||||
))}
|
|
||||||
</ActivitySection>
|
|
||||||
</InnerContentContainer>
|
</InnerContentContainer>
|
||||||
<CommentContainer>
|
<CommentContainer>
|
||||||
{me && (
|
{me && (
|
||||||
|
@ -168,41 +168,6 @@ export type TaskBadges = {
|
|||||||
checklist?: Maybe<ChecklistBadge>;
|
checklist?: Maybe<ChecklistBadge>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CausedBy = {
|
|
||||||
__typename?: 'CausedBy';
|
|
||||||
id: Scalars['ID'];
|
|
||||||
fullName: Scalars['String'];
|
|
||||||
profileIcon?: Maybe<ProfileIcon>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type TaskActivityData = {
|
|
||||||
__typename?: 'TaskActivityData';
|
|
||||||
name: Scalars['String'];
|
|
||||||
value: Scalars['String'];
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum ActivityType {
|
|
||||||
TaskAdded = 'TASK_ADDED',
|
|
||||||
TaskMoved = 'TASK_MOVED',
|
|
||||||
TaskMarkedComplete = 'TASK_MARKED_COMPLETE',
|
|
||||||
TaskMarkedIncomplete = 'TASK_MARKED_INCOMPLETE',
|
|
||||||
TaskDueDateChanged = 'TASK_DUE_DATE_CHANGED',
|
|
||||||
TaskDueDateAdded = 'TASK_DUE_DATE_ADDED',
|
|
||||||
TaskDueDateRemoved = 'TASK_DUE_DATE_REMOVED',
|
|
||||||
TaskChecklistChanged = 'TASK_CHECKLIST_CHANGED',
|
|
||||||
TaskChecklistAdded = 'TASK_CHECKLIST_ADDED',
|
|
||||||
TaskChecklistRemoved = 'TASK_CHECKLIST_REMOVED'
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TaskActivity = {
|
|
||||||
__typename?: 'TaskActivity';
|
|
||||||
id: Scalars['ID'];
|
|
||||||
type: ActivityType;
|
|
||||||
data: Array<TaskActivityData>;
|
|
||||||
causedBy: CausedBy;
|
|
||||||
createdAt: Scalars['Time'];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Task = {
|
export type Task = {
|
||||||
__typename?: 'Task';
|
__typename?: 'Task';
|
||||||
id: Scalars['ID'];
|
id: Scalars['ID'];
|
||||||
@ -218,7 +183,6 @@ export type Task = {
|
|||||||
labels: Array<TaskLabel>;
|
labels: Array<TaskLabel>;
|
||||||
checklists: Array<TaskChecklist>;
|
checklists: Array<TaskChecklist>;
|
||||||
badges: TaskBadges;
|
badges: TaskBadges;
|
||||||
activity: Array<TaskActivity>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Organization = {
|
export type Organization = {
|
||||||
@ -245,11 +209,6 @@ export type TaskChecklist = {
|
|||||||
items: Array<TaskChecklistItem>;
|
items: Array<TaskChecklistItem>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum ShareStatus {
|
|
||||||
Invited = 'INVITED',
|
|
||||||
Joined = 'JOINED'
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum RoleLevel {
|
export enum RoleLevel {
|
||||||
Admin = 'ADMIN',
|
Admin = 'ADMIN',
|
||||||
Member = 'MEMBER'
|
Member = 'MEMBER'
|
||||||
@ -1091,16 +1050,17 @@ export type DeleteInvitedUserAccountPayload = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type MemberSearchFilter = {
|
export type MemberSearchFilter = {
|
||||||
searchFilter: Scalars['String'];
|
SearchFilter: Scalars['String'];
|
||||||
projectID?: Maybe<Scalars['UUID']>;
|
projectID?: Maybe<Scalars['UUID']>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MemberSearchResult = {
|
export type MemberSearchResult = {
|
||||||
__typename?: 'MemberSearchResult';
|
__typename?: 'MemberSearchResult';
|
||||||
similarity: Scalars['Int'];
|
similarity: Scalars['Int'];
|
||||||
id: Scalars['String'];
|
user: UserAccount;
|
||||||
user?: Maybe<UserAccount>;
|
confirmed: Scalars['Boolean'];
|
||||||
status: ShareStatus;
|
invited: Scalars['Boolean'];
|
||||||
|
joined: Scalars['Boolean'];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpdateUserInfoPayload = {
|
export type UpdateUserInfoPayload = {
|
||||||
@ -1384,21 +1344,7 @@ export type FindTaskQuery = (
|
|||||||
& { taskGroup: (
|
& { taskGroup: (
|
||||||
{ __typename?: 'TaskGroup' }
|
{ __typename?: 'TaskGroup' }
|
||||||
& Pick<TaskGroup, 'id' | 'name'>
|
& Pick<TaskGroup, 'id' | 'name'>
|
||||||
), activity: Array<(
|
), badges: (
|
||||||
{ __typename?: 'TaskActivity' }
|
|
||||||
& Pick<TaskActivity, 'id' | 'type' | 'createdAt'>
|
|
||||||
& { causedBy: (
|
|
||||||
{ __typename?: 'CausedBy' }
|
|
||||||
& Pick<CausedBy, 'id' | 'fullName'>
|
|
||||||
& { profileIcon?: Maybe<(
|
|
||||||
{ __typename?: 'ProfileIcon' }
|
|
||||||
& Pick<ProfileIcon, 'initials' | 'bgColor' | 'url'>
|
|
||||||
)> }
|
|
||||||
), data: Array<(
|
|
||||||
{ __typename?: 'TaskActivityData' }
|
|
||||||
& Pick<TaskActivityData, 'name' | 'value'>
|
|
||||||
)> }
|
|
||||||
)>, badges: (
|
|
||||||
{ __typename?: 'TaskBadges' }
|
{ __typename?: 'TaskBadges' }
|
||||||
& { checklist?: Maybe<(
|
& { checklist?: Maybe<(
|
||||||
{ __typename?: 'ChecklistBadge' }
|
{ __typename?: 'ChecklistBadge' }
|
||||||
@ -2879,24 +2825,6 @@ export const FindTaskDocument = gql`
|
|||||||
id
|
id
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
activity {
|
|
||||||
id
|
|
||||||
type
|
|
||||||
causedBy {
|
|
||||||
id
|
|
||||||
fullName
|
|
||||||
profileIcon {
|
|
||||||
initials
|
|
||||||
bgColor
|
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
createdAt
|
|
||||||
data {
|
|
||||||
name
|
|
||||||
value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
badges {
|
badges {
|
||||||
checklist {
|
checklist {
|
||||||
total
|
total
|
||||||
|
@ -10,24 +10,6 @@ query findTask($taskID: UUID!) {
|
|||||||
id
|
id
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
activity {
|
|
||||||
id
|
|
||||||
type
|
|
||||||
causedBy {
|
|
||||||
id
|
|
||||||
fullName
|
|
||||||
profileIcon {
|
|
||||||
initials
|
|
||||||
bgColor
|
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
createdAt
|
|
||||||
data {
|
|
||||||
name
|
|
||||||
value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
badges {
|
badges {
|
||||||
checklist {
|
checklist {
|
||||||
total
|
total
|
||||||
|
@ -9,7 +9,7 @@ export function updateApolloCache<T>(
|
|||||||
update: UpdateCacheFn<T>,
|
update: UpdateCacheFn<T>,
|
||||||
variables?: object,
|
variables?: object,
|
||||||
) {
|
) {
|
||||||
let queryArgs: DataProxy.Query<any, any>;
|
let queryArgs: DataProxy.Query<any>;
|
||||||
if (variables) {
|
if (variables) {
|
||||||
queryArgs = {
|
queryArgs = {
|
||||||
query: document,
|
query: document,
|
||||||
|
4
frontend/src/taskcafe.d.ts
vendored
4
frontend/src/taskcafe.d.ts
vendored
@ -206,14 +206,10 @@ type ImpactAction = {
|
|||||||
type ItemElement = {
|
type ItemElement = {
|
||||||
id: string;
|
id: string;
|
||||||
parent: null | string;
|
parent: null | string;
|
||||||
text: string;
|
|
||||||
focus: null | { caret: number | null };
|
|
||||||
zooming?: { x: number; y: number };
|
|
||||||
position: number;
|
position: number;
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
children?: Array<ItemElement>;
|
children?: Array<ItemElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type NodeDimensions = {
|
type NodeDimensions = {
|
||||||
entry: React.RefObject<HTMLElement>;
|
entry: React.RefObject<HTMLElement>;
|
||||||
children: React.RefObject<HTMLElement> | null;
|
children: React.RefObject<HTMLElement> | null;
|
||||||
|
33
frontend/src/types.d.ts
vendored
33
frontend/src/types.d.ts
vendored
@ -1,10 +1,3 @@
|
|||||||
type ProjectLabel = {
|
|
||||||
id: string;
|
|
||||||
createdDate: string;
|
|
||||||
name?: string | null;
|
|
||||||
labelColor: LabelColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ProfileIcon = {
|
type ProfileIcon = {
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
initials?: string | null;
|
initials?: string | null;
|
||||||
@ -63,24 +56,6 @@ type TaskBadges = {
|
|||||||
checklist?: ChecklistBadge | null;
|
checklist?: ChecklistBadge | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TaskActivityData = {
|
|
||||||
name: string;
|
|
||||||
value: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CausedBy = {
|
|
||||||
id: string;
|
|
||||||
fullName: string;
|
|
||||||
profileIcon?: null | ProfileIcon;
|
|
||||||
};
|
|
||||||
type TaskActivity = {
|
|
||||||
id: string;
|
|
||||||
type: any;
|
|
||||||
data: Array<TaskActivityData>;
|
|
||||||
causedBy: CausedBy;
|
|
||||||
createdAt: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Task = {
|
type Task = {
|
||||||
id: string;
|
id: string;
|
||||||
taskGroup: InnerTaskGroup;
|
taskGroup: InnerTaskGroup;
|
||||||
@ -94,7 +69,6 @@ type Task = {
|
|||||||
description?: string | null;
|
description?: string | null;
|
||||||
assigned?: Array<TaskUser>;
|
assigned?: Array<TaskUser>;
|
||||||
checklists?: Array<TaskChecklist> | null;
|
checklists?: Array<TaskChecklist> | null;
|
||||||
activity?: Array<TaskActivity> | null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type Project = {
|
type Project = {
|
||||||
@ -115,3 +89,10 @@ type Team = {
|
|||||||
name: string;
|
name: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ProjectLabel = {
|
||||||
|
id: string;
|
||||||
|
createdDate: string;
|
||||||
|
name?: string | null;
|
||||||
|
labelColor: LabelColor;
|
||||||
|
};
|
||||||
|
9142
frontend/yarn.lock
9142
frontend/yarn.lock
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,6 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -104,22 +103,6 @@ type Task struct {
|
|||||||
CompletedAt sql.NullTime `json:"completed_at"`
|
CompletedAt sql.NullTime `json:"completed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskActivity struct {
|
|
||||||
TaskActivityID uuid.UUID `json:"task_activity_id"`
|
|
||||||
Active bool `json:"active"`
|
|
||||||
TaskID uuid.UUID `json:"task_id"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
CausedBy uuid.UUID `json:"caused_by"`
|
|
||||||
ActivityTypeID int32 `json:"activity_type_id"`
|
|
||||||
Data json.RawMessage `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivityType struct {
|
|
||||||
TaskActivityTypeID int32 `json:"task_activity_type_id"`
|
|
||||||
Code string `json:"code"`
|
|
||||||
Template string `json:"template"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskAssigned struct {
|
type TaskAssigned struct {
|
||||||
TaskAssignedID uuid.UUID `json:"task_assigned_id"`
|
TaskAssignedID uuid.UUID `json:"task_assigned_id"`
|
||||||
TaskID uuid.UUID `json:"task_id"`
|
TaskID uuid.UUID `json:"task_id"`
|
||||||
|
@ -23,7 +23,6 @@ type Querier interface {
|
|||||||
CreateRefreshToken(ctx context.Context, arg CreateRefreshTokenParams) (RefreshToken, error)
|
CreateRefreshToken(ctx context.Context, arg CreateRefreshTokenParams) (RefreshToken, error)
|
||||||
CreateSystemOption(ctx context.Context, arg CreateSystemOptionParams) (SystemOption, error)
|
CreateSystemOption(ctx context.Context, arg CreateSystemOptionParams) (SystemOption, error)
|
||||||
CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error)
|
CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error)
|
||||||
CreateTaskActivity(ctx context.Context, arg CreateTaskActivityParams) (TaskActivity, error)
|
|
||||||
CreateTaskAll(ctx context.Context, arg CreateTaskAllParams) (Task, error)
|
CreateTaskAll(ctx context.Context, arg CreateTaskAllParams) (Task, error)
|
||||||
CreateTaskAssigned(ctx context.Context, arg CreateTaskAssignedParams) (TaskAssigned, error)
|
CreateTaskAssigned(ctx context.Context, arg CreateTaskAssignedParams) (TaskAssigned, error)
|
||||||
CreateTaskChecklist(ctx context.Context, arg CreateTaskChecklistParams) (TaskChecklist, error)
|
CreateTaskChecklist(ctx context.Context, arg CreateTaskChecklistParams) (TaskChecklist, error)
|
||||||
@ -56,7 +55,6 @@ type Querier interface {
|
|||||||
DeleteTeamMember(ctx context.Context, arg DeleteTeamMemberParams) error
|
DeleteTeamMember(ctx context.Context, arg DeleteTeamMemberParams) error
|
||||||
DeleteUserAccountByID(ctx context.Context, userID uuid.UUID) error
|
DeleteUserAccountByID(ctx context.Context, userID uuid.UUID) error
|
||||||
DeleteUserAccountInvitedForEmail(ctx context.Context, email string) error
|
DeleteUserAccountInvitedForEmail(ctx context.Context, email string) error
|
||||||
GetActivityForTaskID(ctx context.Context, taskID uuid.UUID) ([]TaskActivity, error)
|
|
||||||
GetAllNotificationsForUserID(ctx context.Context, notifierID uuid.UUID) ([]Notification, error)
|
GetAllNotificationsForUserID(ctx context.Context, notifierID uuid.UUID) ([]Notification, error)
|
||||||
GetAllOrganizations(ctx context.Context) ([]Organization, error)
|
GetAllOrganizations(ctx context.Context) ([]Organization, error)
|
||||||
GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) ([]Project, error)
|
GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) ([]Project, error)
|
||||||
@ -76,7 +74,6 @@ type Querier interface {
|
|||||||
GetInvitedUserByEmail(ctx context.Context, email string) (UserAccountInvited, error)
|
GetInvitedUserByEmail(ctx context.Context, email string) (UserAccountInvited, error)
|
||||||
GetLabelColorByID(ctx context.Context, labelColorID uuid.UUID) (LabelColor, error)
|
GetLabelColorByID(ctx context.Context, labelColorID uuid.UUID) (LabelColor, error)
|
||||||
GetLabelColors(ctx context.Context) ([]LabelColor, error)
|
GetLabelColors(ctx context.Context) ([]LabelColor, error)
|
||||||
GetLastMoveForTaskID(ctx context.Context, taskID uuid.UUID) (GetLastMoveForTaskIDRow, error)
|
|
||||||
GetMemberData(ctx context.Context, projectID uuid.UUID) ([]UserAccount, error)
|
GetMemberData(ctx context.Context, projectID uuid.UUID) ([]UserAccount, error)
|
||||||
GetMemberProjectIDsForUserID(ctx context.Context, userID uuid.UUID) ([]uuid.UUID, error)
|
GetMemberProjectIDsForUserID(ctx context.Context, userID uuid.UUID) ([]uuid.UUID, error)
|
||||||
GetMemberTeamIDsForUserID(ctx context.Context, userID uuid.UUID) ([]uuid.UUID, error)
|
GetMemberTeamIDsForUserID(ctx context.Context, userID uuid.UUID) ([]uuid.UUID, error)
|
||||||
@ -116,7 +113,6 @@ type Querier interface {
|
|||||||
GetTeamRolesForUserID(ctx context.Context, userID uuid.UUID) ([]GetTeamRolesForUserIDRow, error)
|
GetTeamRolesForUserID(ctx context.Context, userID uuid.UUID) ([]GetTeamRolesForUserIDRow, error)
|
||||||
GetTeamsForOrganization(ctx context.Context, organizationID uuid.UUID) ([]Team, error)
|
GetTeamsForOrganization(ctx context.Context, organizationID uuid.UUID) ([]Team, error)
|
||||||
GetTeamsForUserIDWhereAdmin(ctx context.Context, userID uuid.UUID) ([]Team, error)
|
GetTeamsForUserIDWhereAdmin(ctx context.Context, userID uuid.UUID) ([]Team, error)
|
||||||
GetTemplateForActivityID(ctx context.Context, taskActivityTypeID int32) (string, error)
|
|
||||||
GetUserAccountByEmail(ctx context.Context, email string) (UserAccount, error)
|
GetUserAccountByEmail(ctx context.Context, email string) (UserAccount, error)
|
||||||
GetUserAccountByID(ctx context.Context, userID uuid.UUID) (UserAccount, error)
|
GetUserAccountByID(ctx context.Context, userID uuid.UUID) (UserAccount, error)
|
||||||
GetUserAccountByUsername(ctx context.Context, username string) (UserAccount, error)
|
GetUserAccountByUsername(ctx context.Context, username string) (UserAccount, error)
|
||||||
@ -124,7 +120,6 @@ type Querier interface {
|
|||||||
HasActiveUser(ctx context.Context) (bool, error)
|
HasActiveUser(ctx context.Context) (bool, error)
|
||||||
HasAnyUser(ctx context.Context) (bool, error)
|
HasAnyUser(ctx context.Context) (bool, error)
|
||||||
SetFirstUserActive(ctx context.Context) (UserAccount, error)
|
SetFirstUserActive(ctx context.Context) (UserAccount, error)
|
||||||
SetInactiveLastMoveForTaskID(ctx context.Context, taskID uuid.UUID) error
|
|
||||||
SetTaskChecklistItemComplete(ctx context.Context, arg SetTaskChecklistItemCompleteParams) (TaskChecklistItem, error)
|
SetTaskChecklistItemComplete(ctx context.Context, arg SetTaskChecklistItemCompleteParams) (TaskChecklistItem, error)
|
||||||
SetTaskComplete(ctx context.Context, arg SetTaskCompleteParams) (Task, error)
|
SetTaskComplete(ctx context.Context, arg SetTaskCompleteParams) (Task, error)
|
||||||
SetTaskGroupName(ctx context.Context, arg SetTaskGroupNameParams) (TaskGroup, error)
|
SetTaskGroupName(ctx context.Context, arg SetTaskGroupNameParams) (TaskGroup, error)
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
-- name: CreateTaskActivity :one
|
|
||||||
INSERT INTO task_activity (task_id, caused_by, created_at, activity_type_id, data)
|
|
||||||
VALUES ($1, $2, $3, $4, $5) RETURNING *;
|
|
||||||
|
|
||||||
-- name: GetActivityForTaskID :many
|
|
||||||
SELECT * FROM task_activity WHERE task_id = $1 AND active = true;
|
|
||||||
|
|
||||||
-- name: GetTemplateForActivityID :one
|
|
||||||
SELECT template FROM task_activity_type WHERE task_activity_type_id = $1;
|
|
||||||
|
|
||||||
-- name: GetLastMoveForTaskID :one
|
|
||||||
SELECT active, created_at, data->>'CurTaskGroupID' AS cur_task_group_id, data->>'PrevTaskGroupID' AS prev_task_group_id FROM task_activity
|
|
||||||
WHERE task_id = $1 AND activity_type_id = 2 AND created_at >= NOW() - INTERVAL '5 minutes'
|
|
||||||
ORDER BY created_at DESC LIMIT 1;
|
|
||||||
|
|
||||||
-- name: SetInactiveLastMoveForTaskID :exec
|
|
||||||
UPDATE task_activity SET active = false WHERE task_activity_id = (
|
|
||||||
SELECT task_activity_id FROM task_activity AS ta
|
|
||||||
WHERE ta.activity_type_id = 2 AND ta.task_id = $1
|
|
||||||
AND ta.created_at >= NOW() - INTERVAL '5 minutes'
|
|
||||||
ORDER BY created_at DESC LIMIT 1
|
|
||||||
);
|
|
@ -1,131 +0,0 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
|
||||||
// source: task_activity.sql
|
|
||||||
|
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
|
||||||
|
|
||||||
const createTaskActivity = `-- name: CreateTaskActivity :one
|
|
||||||
INSERT INTO task_activity (task_id, caused_by, created_at, activity_type_id, data)
|
|
||||||
VALUES ($1, $2, $3, $4, $5) RETURNING task_activity_id, active, task_id, created_at, caused_by, activity_type_id, data
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateTaskActivityParams struct {
|
|
||||||
TaskID uuid.UUID `json:"task_id"`
|
|
||||||
CausedBy uuid.UUID `json:"caused_by"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
ActivityTypeID int32 `json:"activity_type_id"`
|
|
||||||
Data json.RawMessage `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateTaskActivity(ctx context.Context, arg CreateTaskActivityParams) (TaskActivity, error) {
|
|
||||||
row := q.db.QueryRowContext(ctx, createTaskActivity,
|
|
||||||
arg.TaskID,
|
|
||||||
arg.CausedBy,
|
|
||||||
arg.CreatedAt,
|
|
||||||
arg.ActivityTypeID,
|
|
||||||
arg.Data,
|
|
||||||
)
|
|
||||||
var i TaskActivity
|
|
||||||
err := row.Scan(
|
|
||||||
&i.TaskActivityID,
|
|
||||||
&i.Active,
|
|
||||||
&i.TaskID,
|
|
||||||
&i.CreatedAt,
|
|
||||||
&i.CausedBy,
|
|
||||||
&i.ActivityTypeID,
|
|
||||||
&i.Data,
|
|
||||||
)
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const getActivityForTaskID = `-- name: GetActivityForTaskID :many
|
|
||||||
SELECT task_activity_id, active, task_id, created_at, caused_by, activity_type_id, data FROM task_activity WHERE task_id = $1 AND active = true
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) GetActivityForTaskID(ctx context.Context, taskID uuid.UUID) ([]TaskActivity, error) {
|
|
||||||
rows, err := q.db.QueryContext(ctx, getActivityForTaskID, taskID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var items []TaskActivity
|
|
||||||
for rows.Next() {
|
|
||||||
var i TaskActivity
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.TaskActivityID,
|
|
||||||
&i.Active,
|
|
||||||
&i.TaskID,
|
|
||||||
&i.CreatedAt,
|
|
||||||
&i.CausedBy,
|
|
||||||
&i.ActivityTypeID,
|
|
||||||
&i.Data,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const getLastMoveForTaskID = `-- name: GetLastMoveForTaskID :one
|
|
||||||
SELECT active, created_at, data->>'CurTaskGroupID' AS cur_task_group_id, data->>'PrevTaskGroupID' AS prev_task_group_id FROM task_activity
|
|
||||||
WHERE task_id = $1 AND activity_type_id = 2 AND created_at >= NOW() - INTERVAL '5 minutes'
|
|
||||||
ORDER BY created_at DESC LIMIT 1
|
|
||||||
`
|
|
||||||
|
|
||||||
type GetLastMoveForTaskIDRow struct {
|
|
||||||
Active bool `json:"active"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
CurTaskGroupID interface{} `json:"cur_task_group_id"`
|
|
||||||
PrevTaskGroupID interface{} `json:"prev_task_group_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) GetLastMoveForTaskID(ctx context.Context, taskID uuid.UUID) (GetLastMoveForTaskIDRow, error) {
|
|
||||||
row := q.db.QueryRowContext(ctx, getLastMoveForTaskID, taskID)
|
|
||||||
var i GetLastMoveForTaskIDRow
|
|
||||||
err := row.Scan(
|
|
||||||
&i.Active,
|
|
||||||
&i.CreatedAt,
|
|
||||||
&i.CurTaskGroupID,
|
|
||||||
&i.PrevTaskGroupID,
|
|
||||||
)
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const getTemplateForActivityID = `-- name: GetTemplateForActivityID :one
|
|
||||||
SELECT template FROM task_activity_type WHERE task_activity_type_id = $1
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) GetTemplateForActivityID(ctx context.Context, taskActivityTypeID int32) (string, error) {
|
|
||||||
row := q.db.QueryRowContext(ctx, getTemplateForActivityID, taskActivityTypeID)
|
|
||||||
var template string
|
|
||||||
err := row.Scan(&template)
|
|
||||||
return template, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const setInactiveLastMoveForTaskID = `-- name: SetInactiveLastMoveForTaskID :exec
|
|
||||||
UPDATE task_activity SET active = false WHERE task_activity_id = (
|
|
||||||
SELECT task_activity_id FROM task_activity AS ta
|
|
||||||
WHERE ta.activity_type_id = 2 AND ta.task_id = $1
|
|
||||||
AND ta.created_at >= NOW() - INTERVAL '5 minutes'
|
|
||||||
ORDER BY created_at DESC LIMIT 1
|
|
||||||
)
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) SetInactiveLastMoveForTaskID(ctx context.Context, taskID uuid.UUID) error {
|
|
||||||
_, err := q.db.ExecContext(ctx, setInactiveLastMoveForTaskID, taskID)
|
|
||||||
return err
|
|
||||||
}
|
|
@ -47,7 +47,6 @@ type ResolverRoot interface {
|
|||||||
Query() QueryResolver
|
Query() QueryResolver
|
||||||
RefreshToken() RefreshTokenResolver
|
RefreshToken() RefreshTokenResolver
|
||||||
Task() TaskResolver
|
Task() TaskResolver
|
||||||
TaskActivity() TaskActivityResolver
|
|
||||||
TaskChecklist() TaskChecklistResolver
|
TaskChecklist() TaskChecklistResolver
|
||||||
TaskChecklistItem() TaskChecklistItemResolver
|
TaskChecklistItem() TaskChecklistItemResolver
|
||||||
TaskGroup() TaskGroupResolver
|
TaskGroup() TaskGroupResolver
|
||||||
@ -61,12 +60,6 @@ type DirectiveRoot struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ComplexityRoot struct {
|
type ComplexityRoot struct {
|
||||||
CausedBy struct {
|
|
||||||
FullName func(childComplexity int) int
|
|
||||||
ID func(childComplexity int) int
|
|
||||||
ProfileIcon func(childComplexity int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
ChecklistBadge struct {
|
ChecklistBadge struct {
|
||||||
Complete func(childComplexity int) int
|
Complete func(childComplexity int) int
|
||||||
Total func(childComplexity int) int
|
Total func(childComplexity int) int
|
||||||
@ -353,7 +346,6 @@ type ComplexityRoot struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Task struct {
|
Task struct {
|
||||||
Activity func(childComplexity int) int
|
|
||||||
Assigned func(childComplexity int) int
|
Assigned func(childComplexity int) int
|
||||||
Badges func(childComplexity int) int
|
Badges func(childComplexity int) int
|
||||||
Checklists func(childComplexity int) int
|
Checklists func(childComplexity int) int
|
||||||
@ -369,19 +361,6 @@ type ComplexityRoot struct {
|
|||||||
TaskGroup func(childComplexity int) int
|
TaskGroup func(childComplexity int) int
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskActivity struct {
|
|
||||||
CausedBy func(childComplexity int) int
|
|
||||||
CreatedAt func(childComplexity int) int
|
|
||||||
Data func(childComplexity int) int
|
|
||||||
ID func(childComplexity int) int
|
|
||||||
Type func(childComplexity int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskActivityData struct {
|
|
||||||
Name func(childComplexity int) int
|
|
||||||
Value func(childComplexity int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskBadges struct {
|
TaskBadges struct {
|
||||||
Checklist func(childComplexity int) int
|
Checklist func(childComplexity int) int
|
||||||
}
|
}
|
||||||
@ -604,13 +583,6 @@ type TaskResolver interface {
|
|||||||
Labels(ctx context.Context, obj *db.Task) ([]db.TaskLabel, error)
|
Labels(ctx context.Context, obj *db.Task) ([]db.TaskLabel, error)
|
||||||
Checklists(ctx context.Context, obj *db.Task) ([]db.TaskChecklist, error)
|
Checklists(ctx context.Context, obj *db.Task) ([]db.TaskChecklist, error)
|
||||||
Badges(ctx context.Context, obj *db.Task) (*TaskBadges, error)
|
Badges(ctx context.Context, obj *db.Task) (*TaskBadges, error)
|
||||||
Activity(ctx context.Context, obj *db.Task) ([]db.TaskActivity, error)
|
|
||||||
}
|
|
||||||
type TaskActivityResolver interface {
|
|
||||||
ID(ctx context.Context, obj *db.TaskActivity) (uuid.UUID, error)
|
|
||||||
Type(ctx context.Context, obj *db.TaskActivity) (ActivityType, error)
|
|
||||||
Data(ctx context.Context, obj *db.TaskActivity) ([]TaskActivityData, error)
|
|
||||||
CausedBy(ctx context.Context, obj *db.TaskActivity) (*CausedBy, error)
|
|
||||||
}
|
}
|
||||||
type TaskChecklistResolver interface {
|
type TaskChecklistResolver interface {
|
||||||
ID(ctx context.Context, obj *db.TaskChecklist) (uuid.UUID, error)
|
ID(ctx context.Context, obj *db.TaskChecklist) (uuid.UUID, error)
|
||||||
@ -662,27 +634,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||||||
_ = ec
|
_ = ec
|
||||||
switch typeName + "." + field {
|
switch typeName + "." + field {
|
||||||
|
|
||||||
case "CausedBy.fullName":
|
|
||||||
if e.complexity.CausedBy.FullName == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.CausedBy.FullName(childComplexity), true
|
|
||||||
|
|
||||||
case "CausedBy.id":
|
|
||||||
if e.complexity.CausedBy.ID == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.CausedBy.ID(childComplexity), true
|
|
||||||
|
|
||||||
case "CausedBy.profileIcon":
|
|
||||||
if e.complexity.CausedBy.ProfileIcon == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.CausedBy.ProfileIcon(childComplexity), true
|
|
||||||
|
|
||||||
case "ChecklistBadge.complete":
|
case "ChecklistBadge.complete":
|
||||||
if e.complexity.ChecklistBadge.Complete == nil {
|
if e.complexity.ChecklistBadge.Complete == nil {
|
||||||
break
|
break
|
||||||
@ -2175,13 +2126,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||||||
|
|
||||||
return e.complexity.SortTaskGroupPayload.Tasks(childComplexity), true
|
return e.complexity.SortTaskGroupPayload.Tasks(childComplexity), true
|
||||||
|
|
||||||
case "Task.activity":
|
|
||||||
if e.complexity.Task.Activity == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.Task.Activity(childComplexity), true
|
|
||||||
|
|
||||||
case "Task.assigned":
|
case "Task.assigned":
|
||||||
if e.complexity.Task.Assigned == nil {
|
if e.complexity.Task.Assigned == nil {
|
||||||
break
|
break
|
||||||
@ -2273,55 +2217,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||||||
|
|
||||||
return e.complexity.Task.TaskGroup(childComplexity), true
|
return e.complexity.Task.TaskGroup(childComplexity), true
|
||||||
|
|
||||||
case "TaskActivity.causedBy":
|
|
||||||
if e.complexity.TaskActivity.CausedBy == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivity.CausedBy(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskActivity.createdAt":
|
|
||||||
if e.complexity.TaskActivity.CreatedAt == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivity.CreatedAt(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskActivity.data":
|
|
||||||
if e.complexity.TaskActivity.Data == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivity.Data(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskActivity.id":
|
|
||||||
if e.complexity.TaskActivity.ID == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivity.ID(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskActivity.type":
|
|
||||||
if e.complexity.TaskActivity.Type == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivity.Type(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskActivityData.name":
|
|
||||||
if e.complexity.TaskActivityData.Name == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivityData.Name(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskActivityData.value":
|
|
||||||
if e.complexity.TaskActivityData.Value == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.TaskActivityData.Value(childComplexity), true
|
|
||||||
|
|
||||||
case "TaskBadges.checklist":
|
case "TaskBadges.checklist":
|
||||||
if e.complexity.TaskBadges.Checklist == nil {
|
if e.complexity.TaskBadges.Checklist == nil {
|
||||||
break
|
break
|
||||||
@ -2901,38 +2796,6 @@ type TaskBadges {
|
|||||||
checklist: ChecklistBadge
|
checklist: ChecklistBadge
|
||||||
}
|
}
|
||||||
|
|
||||||
type CausedBy {
|
|
||||||
id: ID!
|
|
||||||
fullName: String!
|
|
||||||
profileIcon: ProfileIcon
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivityData {
|
|
||||||
name: String!
|
|
||||||
value: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ActivityType {
|
|
||||||
TASK_ADDED
|
|
||||||
TASK_MOVED
|
|
||||||
TASK_MARKED_COMPLETE
|
|
||||||
TASK_MARKED_INCOMPLETE
|
|
||||||
TASK_DUE_DATE_CHANGED
|
|
||||||
TASK_DUE_DATE_ADDED
|
|
||||||
TASK_DUE_DATE_REMOVED
|
|
||||||
TASK_CHECKLIST_CHANGED
|
|
||||||
TASK_CHECKLIST_ADDED
|
|
||||||
TASK_CHECKLIST_REMOVED
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivity {
|
|
||||||
id: ID!
|
|
||||||
type: ActivityType!
|
|
||||||
data: [TaskActivityData!]!
|
|
||||||
causedBy: CausedBy!
|
|
||||||
createdAt: Time!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Task {
|
type Task {
|
||||||
id: ID!
|
id: ID!
|
||||||
taskGroup: TaskGroup!
|
taskGroup: TaskGroup!
|
||||||
@ -2947,7 +2810,6 @@ type Task {
|
|||||||
labels: [TaskLabel!]!
|
labels: [TaskLabel!]!
|
||||||
checklists: [TaskChecklist!]!
|
checklists: [TaskChecklist!]!
|
||||||
badges: TaskBadges!
|
badges: TaskBadges!
|
||||||
activity: [TaskActivity!]!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Organization {
|
type Organization {
|
||||||
@ -4570,105 +4432,6 @@ func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArg
|
|||||||
|
|
||||||
// region **************************** field.gotpl *****************************
|
// region **************************** field.gotpl *****************************
|
||||||
|
|
||||||
func (ec *executionContext) _CausedBy_id(ctx context.Context, field graphql.CollectedField, obj *CausedBy) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "CausedBy",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.ID, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(uuid.UUID)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _CausedBy_fullName(ctx context.Context, field graphql.CollectedField, obj *CausedBy) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "CausedBy",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.FullName, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(string)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _CausedBy_profileIcon(ctx context.Context, field graphql.CollectedField, obj *CausedBy) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "CausedBy",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.ProfileIcon, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(*ProfileIcon)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalOProfileIcon2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐProfileIcon(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _ChecklistBadge_complete(ctx context.Context, field graphql.CollectedField, obj *ChecklistBadge) (ret graphql.Marshaler) {
|
func (ec *executionContext) _ChecklistBadge_complete(ctx context.Context, field graphql.CollectedField, obj *ChecklistBadge) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@ -13012,278 +12775,6 @@ func (ec *executionContext) _Task_badges(ctx context.Context, field graphql.Coll
|
|||||||
return ec.marshalNTaskBadges2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskBadges(ctx, field.Selections, res)
|
return ec.marshalNTaskBadges2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskBadges(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Task_activity(ctx context.Context, field graphql.CollectedField, obj *db.Task) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "Task",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return ec.resolvers.Task().Activity(rctx, obj)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.([]db.TaskActivity)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNTaskActivity2ᚕgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋdbᚐTaskActivityᚄ(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivity_id(ctx context.Context, field graphql.CollectedField, obj *db.TaskActivity) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivity",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return ec.resolvers.TaskActivity().ID(rctx, obj)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(uuid.UUID)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivity_type(ctx context.Context, field graphql.CollectedField, obj *db.TaskActivity) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivity",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return ec.resolvers.TaskActivity().Type(rctx, obj)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(ActivityType)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNActivityType2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐActivityType(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivity_data(ctx context.Context, field graphql.CollectedField, obj *db.TaskActivity) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivity",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return ec.resolvers.TaskActivity().Data(rctx, obj)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.([]TaskActivityData)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNTaskActivityData2ᚕgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskActivityDataᚄ(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivity_causedBy(ctx context.Context, field graphql.CollectedField, obj *db.TaskActivity) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivity",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return ec.resolvers.TaskActivity().CausedBy(rctx, obj)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(*CausedBy)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNCausedBy2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCausedBy(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivity_createdAt(ctx context.Context, field graphql.CollectedField, obj *db.TaskActivity) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivity",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.CreatedAt, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(time.Time)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivityData_name(ctx context.Context, field graphql.CollectedField, obj *TaskActivityData) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivityData",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.Name, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(string)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivityData_value(ctx context.Context, field graphql.CollectedField, obj *TaskActivityData) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "TaskActivityData",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.Value, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(string)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskBadges_checklist(ctx context.Context, field graphql.CollectedField, obj *TaskBadges) (ret graphql.Marshaler) {
|
func (ec *executionContext) _TaskBadges_checklist(ctx context.Context, field graphql.CollectedField, obj *TaskBadges) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@ -17662,40 +17153,6 @@ func (ec *executionContext) unmarshalInputUpdateUserRole(ctx context.Context, ob
|
|||||||
|
|
||||||
// region **************************** object.gotpl ****************************
|
// region **************************** object.gotpl ****************************
|
||||||
|
|
||||||
var causedByImplementors = []string{"CausedBy"}
|
|
||||||
|
|
||||||
func (ec *executionContext) _CausedBy(ctx context.Context, sel ast.SelectionSet, obj *CausedBy) graphql.Marshaler {
|
|
||||||
fields := graphql.CollectFields(ec.OperationContext, sel, causedByImplementors)
|
|
||||||
|
|
||||||
out := graphql.NewFieldSet(fields)
|
|
||||||
var invalids uint32
|
|
||||||
for i, field := range fields {
|
|
||||||
switch field.Name {
|
|
||||||
case "__typename":
|
|
||||||
out.Values[i] = graphql.MarshalString("CausedBy")
|
|
||||||
case "id":
|
|
||||||
out.Values[i] = ec._CausedBy_id(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
invalids++
|
|
||||||
}
|
|
||||||
case "fullName":
|
|
||||||
out.Values[i] = ec._CausedBy_fullName(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
invalids++
|
|
||||||
}
|
|
||||||
case "profileIcon":
|
|
||||||
out.Values[i] = ec._CausedBy_profileIcon(ctx, field, obj)
|
|
||||||
default:
|
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.Dispatch()
|
|
||||||
if invalids > 0 {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
var checklistBadgeImplementors = []string{"ChecklistBadge"}
|
var checklistBadgeImplementors = []string{"ChecklistBadge"}
|
||||||
|
|
||||||
func (ec *executionContext) _ChecklistBadge(ctx context.Context, sel ast.SelectionSet, obj *ChecklistBadge) graphql.Marshaler {
|
func (ec *executionContext) _ChecklistBadge(ctx context.Context, sel ast.SelectionSet, obj *ChecklistBadge) graphql.Marshaler {
|
||||||
@ -19808,135 +19265,6 @@ func (ec *executionContext) _Task(ctx context.Context, sel ast.SelectionSet, obj
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
case "activity":
|
|
||||||
field := field
|
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
res = ec._Task_activity(ctx, field, obj)
|
|
||||||
if res == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
default:
|
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.Dispatch()
|
|
||||||
if invalids > 0 {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
var taskActivityImplementors = []string{"TaskActivity"}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivity(ctx context.Context, sel ast.SelectionSet, obj *db.TaskActivity) graphql.Marshaler {
|
|
||||||
fields := graphql.CollectFields(ec.OperationContext, sel, taskActivityImplementors)
|
|
||||||
|
|
||||||
out := graphql.NewFieldSet(fields)
|
|
||||||
var invalids uint32
|
|
||||||
for i, field := range fields {
|
|
||||||
switch field.Name {
|
|
||||||
case "__typename":
|
|
||||||
out.Values[i] = graphql.MarshalString("TaskActivity")
|
|
||||||
case "id":
|
|
||||||
field := field
|
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
res = ec._TaskActivity_id(ctx, field, obj)
|
|
||||||
if res == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
case "type":
|
|
||||||
field := field
|
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
res = ec._TaskActivity_type(ctx, field, obj)
|
|
||||||
if res == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
case "data":
|
|
||||||
field := field
|
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
res = ec._TaskActivity_data(ctx, field, obj)
|
|
||||||
if res == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
case "causedBy":
|
|
||||||
field := field
|
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
res = ec._TaskActivity_causedBy(ctx, field, obj)
|
|
||||||
if res == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
case "createdAt":
|
|
||||||
out.Values[i] = ec._TaskActivity_createdAt(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.Dispatch()
|
|
||||||
if invalids > 0 {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
var taskActivityDataImplementors = []string{"TaskActivityData"}
|
|
||||||
|
|
||||||
func (ec *executionContext) _TaskActivityData(ctx context.Context, sel ast.SelectionSet, obj *TaskActivityData) graphql.Marshaler {
|
|
||||||
fields := graphql.CollectFields(ec.OperationContext, sel, taskActivityDataImplementors)
|
|
||||||
|
|
||||||
out := graphql.NewFieldSet(fields)
|
|
||||||
var invalids uint32
|
|
||||||
for i, field := range fields {
|
|
||||||
switch field.Name {
|
|
||||||
case "__typename":
|
|
||||||
out.Values[i] = graphql.MarshalString("TaskActivityData")
|
|
||||||
case "name":
|
|
||||||
out.Values[i] = ec._TaskActivityData_name(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
invalids++
|
|
||||||
}
|
|
||||||
case "value":
|
|
||||||
out.Values[i] = ec._TaskActivityData_value(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
invalids++
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
panic("unknown field " + strconv.Quote(field.Name))
|
||||||
}
|
}
|
||||||
@ -20996,15 +20324,6 @@ func (ec *executionContext) marshalNActionType2githubᚗcomᚋjordanknottᚋtask
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalNActivityType2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐActivityType(ctx context.Context, v interface{}) (ActivityType, error) {
|
|
||||||
var res ActivityType
|
|
||||||
return res, res.UnmarshalGQL(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNActivityType2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐActivityType(ctx context.Context, sel ast.SelectionSet, v ActivityType) graphql.Marshaler {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalNActorType2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐActorType(ctx context.Context, v interface{}) (ActorType, error) {
|
func (ec *executionContext) unmarshalNActorType2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐActorType(ctx context.Context, v interface{}) (ActorType, error) {
|
||||||
var res ActorType
|
var res ActorType
|
||||||
return res, res.UnmarshalGQL(v)
|
return res, res.UnmarshalGQL(v)
|
||||||
@ -21028,20 +20347,6 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) marshalNCausedBy2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCausedBy(ctx context.Context, sel ast.SelectionSet, v CausedBy) graphql.Marshaler {
|
|
||||||
return ec._CausedBy(ctx, sel, &v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNCausedBy2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCausedBy(ctx context.Context, sel ast.SelectionSet, v *CausedBy) graphql.Marshaler {
|
|
||||||
if v == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return ec._CausedBy(ctx, sel, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalNCreateTaskChecklist2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCreateTaskChecklist(ctx context.Context, v interface{}) (CreateTaskChecklist, error) {
|
func (ec *executionContext) unmarshalNCreateTaskChecklist2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCreateTaskChecklist(ctx context.Context, v interface{}) (CreateTaskChecklist, error) {
|
||||||
return ec.unmarshalInputCreateTaskChecklist(ctx, v)
|
return ec.unmarshalInputCreateTaskChecklist(ctx, v)
|
||||||
}
|
}
|
||||||
@ -22225,88 +21530,6 @@ func (ec *executionContext) marshalNTask2ᚖgithubᚗcomᚋjordanknottᚋtaskcaf
|
|||||||
return ec._Task(ctx, sel, v)
|
return ec._Task(ctx, sel, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) marshalNTaskActivity2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋdbᚐTaskActivity(ctx context.Context, sel ast.SelectionSet, v db.TaskActivity) graphql.Marshaler {
|
|
||||||
return ec._TaskActivity(ctx, sel, &v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNTaskActivity2ᚕgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋdbᚐTaskActivityᚄ(ctx context.Context, sel ast.SelectionSet, v []db.TaskActivity) graphql.Marshaler {
|
|
||||||
ret := make(graphql.Array, len(v))
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
isLen1 := len(v) == 1
|
|
||||||
if !isLen1 {
|
|
||||||
wg.Add(len(v))
|
|
||||||
}
|
|
||||||
for i := range v {
|
|
||||||
i := i
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Index: &i,
|
|
||||||
Result: &v[i],
|
|
||||||
}
|
|
||||||
ctx := graphql.WithFieldContext(ctx, fc)
|
|
||||||
f := func(i int) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = nil
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if !isLen1 {
|
|
||||||
defer wg.Done()
|
|
||||||
}
|
|
||||||
ret[i] = ec.marshalNTaskActivity2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋdbᚐTaskActivity(ctx, sel, v[i])
|
|
||||||
}
|
|
||||||
if isLen1 {
|
|
||||||
f(i)
|
|
||||||
} else {
|
|
||||||
go f(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNTaskActivityData2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskActivityData(ctx context.Context, sel ast.SelectionSet, v TaskActivityData) graphql.Marshaler {
|
|
||||||
return ec._TaskActivityData(ctx, sel, &v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNTaskActivityData2ᚕgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskActivityDataᚄ(ctx context.Context, sel ast.SelectionSet, v []TaskActivityData) graphql.Marshaler {
|
|
||||||
ret := make(graphql.Array, len(v))
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
isLen1 := len(v) == 1
|
|
||||||
if !isLen1 {
|
|
||||||
wg.Add(len(v))
|
|
||||||
}
|
|
||||||
for i := range v {
|
|
||||||
i := i
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Index: &i,
|
|
||||||
Result: &v[i],
|
|
||||||
}
|
|
||||||
ctx := graphql.WithFieldContext(ctx, fc)
|
|
||||||
f := func(i int) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = nil
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if !isLen1 {
|
|
||||||
defer wg.Done()
|
|
||||||
}
|
|
||||||
ret[i] = ec.marshalNTaskActivityData2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskActivityData(ctx, sel, v[i])
|
|
||||||
}
|
|
||||||
if isLen1 {
|
|
||||||
f(i)
|
|
||||||
} else {
|
|
||||||
go f(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNTaskBadges2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskBadges(ctx context.Context, sel ast.SelectionSet, v TaskBadges) graphql.Marshaler {
|
func (ec *executionContext) marshalNTaskBadges2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐTaskBadges(ctx context.Context, sel ast.SelectionSet, v TaskBadges) graphql.Marshaler {
|
||||||
return ec._TaskBadges(ctx, sel, &v)
|
return ec._TaskBadges(ctx, sel, &v)
|
||||||
}
|
}
|
||||||
@ -23235,17 +22458,6 @@ func (ec *executionContext) marshalOChecklistBadge2ᚖgithubᚗcomᚋjordanknott
|
|||||||
return ec._ChecklistBadge(ctx, sel, v)
|
return ec._ChecklistBadge(ctx, sel, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) marshalOProfileIcon2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐProfileIcon(ctx context.Context, sel ast.SelectionSet, v ProfileIcon) graphql.Marshaler {
|
|
||||||
return ec._ProfileIcon(ctx, sel, &v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalOProfileIcon2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐProfileIcon(ctx context.Context, sel ast.SelectionSet, v *ProfileIcon) graphql.Marshaler {
|
|
||||||
if v == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return ec._ProfileIcon(ctx, sel, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalOProjectsFilter2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐProjectsFilter(ctx context.Context, v interface{}) (ProjectsFilter, error) {
|
func (ec *executionContext) unmarshalOProjectsFilter2githubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐProjectsFilter(ctx context.Context, v interface{}) (ProjectsFilter, error) {
|
||||||
return ec.unmarshalInputProjectsFilter(ctx, v)
|
return ec.unmarshalInputProjectsFilter(ctx, v)
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func NewHandler(repo db.Repository) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var subjectID uuid.UUID
|
var subjectID uuid.UUID
|
||||||
in := graphql.GetFieldContext(ctx).Args["input"]
|
in := graphql.GetResolverContext(ctx).Args["input"]
|
||||||
val := reflect.ValueOf(in) // could be any underlying type
|
val := reflect.ValueOf(in) // could be any underlying type
|
||||||
if val.Kind() == reflect.Ptr {
|
if val.Kind() == reflect.Ptr {
|
||||||
val = reflect.Indirect(val)
|
val = reflect.Indirect(val)
|
||||||
@ -255,15 +255,3 @@ func GetActionType(actionType int32) ActionType {
|
|||||||
panic("Not a valid entity type!")
|
panic("Not a valid entity type!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
MemberTypeInvited MemberType = "INVITED"
|
|
||||||
MemberTypeJoined MemberType = "JOINED"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MasterEntry struct {
|
|
||||||
MemberType MemberType
|
|
||||||
ID uuid.UUID
|
|
||||||
}
|
|
||||||
|
@ -41,7 +41,3 @@ func GetMemberList(ctx context.Context, r db.Repository, user db.UserAccount) (*
|
|||||||
|
|
||||||
return &MemberList{Teams: teams, Projects: projects}, nil
|
return &MemberList{Teams: teams, Projects: projects}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActivityData struct {
|
|
||||||
Data map[string]string
|
|
||||||
}
|
|
||||||
|
@ -22,12 +22,6 @@ type AssignTaskInput struct {
|
|||||||
UserID uuid.UUID `json:"userID"`
|
UserID uuid.UUID `json:"userID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CausedBy struct {
|
|
||||||
ID uuid.UUID `json:"id"`
|
|
||||||
FullName string `json:"fullName"`
|
|
||||||
ProfileIcon *ProfileIcon `json:"profileIcon"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChecklistBadge struct {
|
type ChecklistBadge struct {
|
||||||
Complete int `json:"complete"`
|
Complete int `json:"complete"`
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
@ -380,11 +374,6 @@ type SortTaskGroupPayload struct {
|
|||||||
Tasks []db.Task `json:"tasks"`
|
Tasks []db.Task `json:"tasks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskActivityData struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskBadges struct {
|
type TaskBadges struct {
|
||||||
Checklist *ChecklistBadge `json:"checklist"`
|
Checklist *ChecklistBadge `json:"checklist"`
|
||||||
}
|
}
|
||||||
@ -626,63 +615,6 @@ func (e ActionType) MarshalGQL(w io.Writer) {
|
|||||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActivityType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ActivityTypeTaskAdded ActivityType = "TASK_ADDED"
|
|
||||||
ActivityTypeTaskMoved ActivityType = "TASK_MOVED"
|
|
||||||
ActivityTypeTaskMarkedComplete ActivityType = "TASK_MARKED_COMPLETE"
|
|
||||||
ActivityTypeTaskMarkedIncomplete ActivityType = "TASK_MARKED_INCOMPLETE"
|
|
||||||
ActivityTypeTaskDueDateChanged ActivityType = "TASK_DUE_DATE_CHANGED"
|
|
||||||
ActivityTypeTaskDueDateAdded ActivityType = "TASK_DUE_DATE_ADDED"
|
|
||||||
ActivityTypeTaskDueDateRemoved ActivityType = "TASK_DUE_DATE_REMOVED"
|
|
||||||
ActivityTypeTaskChecklistChanged ActivityType = "TASK_CHECKLIST_CHANGED"
|
|
||||||
ActivityTypeTaskChecklistAdded ActivityType = "TASK_CHECKLIST_ADDED"
|
|
||||||
ActivityTypeTaskChecklistRemoved ActivityType = "TASK_CHECKLIST_REMOVED"
|
|
||||||
)
|
|
||||||
|
|
||||||
var AllActivityType = []ActivityType{
|
|
||||||
ActivityTypeTaskAdded,
|
|
||||||
ActivityTypeTaskMoved,
|
|
||||||
ActivityTypeTaskMarkedComplete,
|
|
||||||
ActivityTypeTaskMarkedIncomplete,
|
|
||||||
ActivityTypeTaskDueDateChanged,
|
|
||||||
ActivityTypeTaskDueDateAdded,
|
|
||||||
ActivityTypeTaskDueDateRemoved,
|
|
||||||
ActivityTypeTaskChecklistChanged,
|
|
||||||
ActivityTypeTaskChecklistAdded,
|
|
||||||
ActivityTypeTaskChecklistRemoved,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e ActivityType) IsValid() bool {
|
|
||||||
switch e {
|
|
||||||
case ActivityTypeTaskAdded, ActivityTypeTaskMoved, ActivityTypeTaskMarkedComplete, ActivityTypeTaskMarkedIncomplete, ActivityTypeTaskDueDateChanged, ActivityTypeTaskDueDateAdded, ActivityTypeTaskDueDateRemoved, ActivityTypeTaskChecklistChanged, ActivityTypeTaskChecklistAdded, ActivityTypeTaskChecklistRemoved:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e ActivityType) String() string {
|
|
||||||
return string(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *ActivityType) UnmarshalGQL(v interface{}) error {
|
|
||||||
str, ok := v.(string)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("enums must be strings")
|
|
||||||
}
|
|
||||||
|
|
||||||
*e = ActivityType(str)
|
|
||||||
if !e.IsValid() {
|
|
||||||
return fmt.Errorf("%s is not a valid ActivityType", str)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e ActivityType) MarshalGQL(w io.Writer) {
|
|
||||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActorType string
|
type ActorType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -135,38 +135,6 @@ type TaskBadges {
|
|||||||
checklist: ChecklistBadge
|
checklist: ChecklistBadge
|
||||||
}
|
}
|
||||||
|
|
||||||
type CausedBy {
|
|
||||||
id: ID!
|
|
||||||
fullName: String!
|
|
||||||
profileIcon: ProfileIcon
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivityData {
|
|
||||||
name: String!
|
|
||||||
value: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ActivityType {
|
|
||||||
TASK_ADDED
|
|
||||||
TASK_MOVED
|
|
||||||
TASK_MARKED_COMPLETE
|
|
||||||
TASK_MARKED_INCOMPLETE
|
|
||||||
TASK_DUE_DATE_CHANGED
|
|
||||||
TASK_DUE_DATE_ADDED
|
|
||||||
TASK_DUE_DATE_REMOVED
|
|
||||||
TASK_CHECKLIST_CHANGED
|
|
||||||
TASK_CHECKLIST_ADDED
|
|
||||||
TASK_CHECKLIST_REMOVED
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivity {
|
|
||||||
id: ID!
|
|
||||||
type: ActivityType!
|
|
||||||
data: [TaskActivityData!]!
|
|
||||||
causedBy: CausedBy!
|
|
||||||
createdAt: Time!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Task {
|
type Task {
|
||||||
id: ID!
|
id: ID!
|
||||||
taskGroup: TaskGroup!
|
taskGroup: TaskGroup!
|
||||||
@ -181,7 +149,6 @@ type Task {
|
|||||||
labels: [TaskLabel!]!
|
labels: [TaskLabel!]!
|
||||||
checklists: [TaskChecklist!]!
|
checklists: [TaskChecklist!]!
|
||||||
badges: TaskBadges!
|
badges: TaskBadges!
|
||||||
activity: [TaskActivity!]!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Organization {
|
type Organization {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
@ -17,11 +17,12 @@ import (
|
|||||||
"github.com/jordanknott/taskcafe/internal/db"
|
"github.com/jordanknott/taskcafe/internal/db"
|
||||||
"github.com/jordanknott/taskcafe/internal/logger"
|
"github.com/jordanknott/taskcafe/internal/logger"
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
|
gomail "gopkg.in/mail.v2"
|
||||||
|
|
||||||
hermes "github.com/matcornic/hermes/v2"
|
hermes "github.com/matcornic/hermes/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
gomail "gopkg.in/mail.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *labelColorResolver) ID(ctx context.Context, obj *db.LabelColor) (uuid.UUID, error) {
|
func (r *labelColorResolver) ID(ctx context.Context, obj *db.LabelColor) (uuid.UUID, error) {
|
||||||
@ -362,26 +363,6 @@ func (r *mutationResolver) CreateTask(ctx context.Context, input NewTask) (*db.T
|
|||||||
createdAt := time.Now().UTC()
|
createdAt := time.Now().UTC()
|
||||||
logger.New(ctx).WithFields(log.Fields{"positon": input.Position, "taskGroupID": input.TaskGroupID}).Info("creating task")
|
logger.New(ctx).WithFields(log.Fields{"positon": input.Position, "taskGroupID": input.TaskGroupID}).Info("creating task")
|
||||||
task, err := r.Repository.CreateTask(ctx, db.CreateTaskParams{input.TaskGroupID, createdAt, input.Name, input.Position})
|
task, err := r.Repository.CreateTask(ctx, db.CreateTaskParams{input.TaskGroupID, createdAt, input.Name, input.Position})
|
||||||
if err != nil {
|
|
||||||
logger.New(ctx).WithError(err).Error("issue while creating task")
|
|
||||||
return &db.Task{}, err
|
|
||||||
}
|
|
||||||
taskGroup, err := r.Repository.GetTaskGroupByID(ctx, input.TaskGroupID)
|
|
||||||
if err != nil {
|
|
||||||
logger.New(ctx).WithError(err).Error("issue while creating task")
|
|
||||||
return &db.Task{}, err
|
|
||||||
}
|
|
||||||
data := map[string]string{
|
|
||||||
"TaskGroup": taskGroup.Name,
|
|
||||||
}
|
|
||||||
d, err := json.Marshal(data)
|
|
||||||
_, err = r.Repository.CreateTaskActivity(ctx, db.CreateTaskActivityParams{
|
|
||||||
TaskID: task.TaskID,
|
|
||||||
Data: d,
|
|
||||||
CreatedAt: createdAt,
|
|
||||||
ActivityTypeID: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.New(ctx).WithError(err).Error("issue while creating task")
|
logger.New(ctx).WithError(err).Error("issue while creating task")
|
||||||
return &db.Task{}, err
|
return &db.Task{}, err
|
||||||
@ -406,44 +387,12 @@ func (r *mutationResolver) UpdateTaskDescription(ctx context.Context, input Upda
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *mutationResolver) UpdateTaskLocation(ctx context.Context, input NewTaskLocation) (*UpdateTaskLocationPayload, error) {
|
func (r *mutationResolver) UpdateTaskLocation(ctx context.Context, input NewTaskLocation) (*UpdateTaskLocationPayload, error) {
|
||||||
userID, _ := GetUserID(ctx)
|
|
||||||
previousTask, err := r.Repository.GetTaskByID(ctx, input.TaskID)
|
previousTask, err := r.Repository.GetTaskByID(ctx, input.TaskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &UpdateTaskLocationPayload{}, err
|
return &UpdateTaskLocationPayload{}, err
|
||||||
}
|
}
|
||||||
task, _ := r.Repository.UpdateTaskLocation(ctx, db.UpdateTaskLocationParams{TaskID: input.TaskID, TaskGroupID: input.TaskGroupID, Position: input.Position})
|
task, err := r.Repository.UpdateTaskLocation(ctx, db.UpdateTaskLocationParams{input.TaskID, input.TaskGroupID, input.Position})
|
||||||
if previousTask.TaskGroupID != input.TaskGroupID {
|
|
||||||
skipAndDelete := false
|
|
||||||
lastMove, err := r.Repository.GetLastMoveForTaskID(ctx, input.TaskID)
|
|
||||||
if err == nil {
|
|
||||||
if lastMove.Active && lastMove.PrevTaskGroupID == input.TaskGroupID.String() {
|
|
||||||
skipAndDelete = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if skipAndDelete {
|
|
||||||
_ = r.Repository.SetInactiveLastMoveForTaskID(ctx, input.TaskID)
|
|
||||||
} else {
|
|
||||||
prevTaskGroup, _ := r.Repository.GetTaskGroupByID(ctx, previousTask.TaskGroupID)
|
|
||||||
curTaskGroup, _ := r.Repository.GetTaskGroupByID(ctx, input.TaskGroupID)
|
|
||||||
|
|
||||||
data := map[string]string{
|
|
||||||
"PrevTaskGroup": prevTaskGroup.Name,
|
|
||||||
"PrevTaskGroupID": prevTaskGroup.TaskGroupID.String(),
|
|
||||||
"CurTaskGroup": curTaskGroup.Name,
|
|
||||||
"CurTaskGroupID": curTaskGroup.TaskGroupID.String(),
|
|
||||||
}
|
|
||||||
|
|
||||||
createdAt := time.Now().UTC()
|
|
||||||
d, _ := json.Marshal(data)
|
|
||||||
_, err = r.Repository.CreateTaskActivity(ctx, db.CreateTaskActivityParams{
|
|
||||||
TaskID: task.TaskID,
|
|
||||||
Data: d,
|
|
||||||
CausedBy: userID,
|
|
||||||
CreatedAt: createdAt,
|
|
||||||
ActivityTypeID: 2,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &UpdateTaskLocationPayload{Task: &task, PreviousTaskGroupID: previousTask.TaskGroupID}, err
|
return &UpdateTaskLocationPayload{Task: &task, PreviousTaskGroupID: previousTask.TaskGroupID}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1609,72 +1558,6 @@ func (r *taskResolver) Badges(ctx context.Context, obj *db.Task) (*TaskBadges, e
|
|||||||
return &TaskBadges{Checklist: &ChecklistBadge{Total: total, Complete: complete}}, nil
|
return &TaskBadges{Checklist: &ChecklistBadge{Total: total, Complete: complete}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *taskResolver) Activity(ctx context.Context, obj *db.Task) ([]db.TaskActivity, error) {
|
|
||||||
activity, err := r.Repository.GetActivityForTaskID(ctx, obj.TaskID)
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return []db.TaskActivity{}, nil
|
|
||||||
}
|
|
||||||
return activity, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *taskActivityResolver) ID(ctx context.Context, obj *db.TaskActivity) (uuid.UUID, error) {
|
|
||||||
return obj.TaskActivityID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *taskActivityResolver) Type(ctx context.Context, obj *db.TaskActivity) (ActivityType, error) {
|
|
||||||
switch obj.ActivityTypeID {
|
|
||||||
case 1:
|
|
||||||
return ActivityTypeTaskAdded, nil
|
|
||||||
case 2:
|
|
||||||
return ActivityTypeTaskMoved, nil
|
|
||||||
case 3:
|
|
||||||
return ActivityTypeTaskMarkedComplete, nil
|
|
||||||
case 4:
|
|
||||||
return ActivityTypeTaskMarkedIncomplete, nil
|
|
||||||
case 5:
|
|
||||||
return ActivityTypeTaskDueDateChanged, nil
|
|
||||||
case 6:
|
|
||||||
return ActivityTypeTaskDueDateAdded, nil
|
|
||||||
case 7:
|
|
||||||
return ActivityTypeTaskDueDateRemoved, nil
|
|
||||||
case 8:
|
|
||||||
return ActivityTypeTaskChecklistChanged, nil
|
|
||||||
case 9:
|
|
||||||
return ActivityTypeTaskChecklistAdded, nil
|
|
||||||
case 10:
|
|
||||||
return ActivityTypeTaskChecklistRemoved, nil
|
|
||||||
default:
|
|
||||||
return ActivityTypeTaskAdded, errors.New("unknown type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *taskActivityResolver) Data(ctx context.Context, obj *db.TaskActivity) ([]TaskActivityData, error) {
|
|
||||||
var data map[string]string
|
|
||||||
_ = json.Unmarshal(obj.Data, &data)
|
|
||||||
activity := []TaskActivityData{}
|
|
||||||
for name, value := range data {
|
|
||||||
activity = append(activity, TaskActivityData{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return activity, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *taskActivityResolver) CausedBy(ctx context.Context, obj *db.TaskActivity) (*CausedBy, error) {
|
|
||||||
user, err := r.Repository.GetUserAccountByID(ctx, obj.CausedBy)
|
|
||||||
var url *string
|
|
||||||
if user.ProfileAvatarUrl.Valid {
|
|
||||||
url = &user.ProfileAvatarUrl.String
|
|
||||||
}
|
|
||||||
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
|
|
||||||
return &CausedBy{
|
|
||||||
ID: obj.CausedBy,
|
|
||||||
FullName: user.FullName,
|
|
||||||
ProfileIcon: profileIcon,
|
|
||||||
}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *taskChecklistResolver) ID(ctx context.Context, obj *db.TaskChecklist) (uuid.UUID, error) {
|
func (r *taskChecklistResolver) ID(ctx context.Context, obj *db.TaskChecklist) (uuid.UUID, error) {
|
||||||
return obj.TaskChecklistID, nil
|
return obj.TaskChecklistID, nil
|
||||||
}
|
}
|
||||||
@ -1736,7 +1619,6 @@ func (r *teamResolver) Members(ctx context.Context, obj *db.Team) ([]Member, err
|
|||||||
if user.ProfileAvatarUrl.Valid {
|
if user.ProfileAvatarUrl.Valid {
|
||||||
url = &user.ProfileAvatarUrl.String
|
url = &user.ProfileAvatarUrl.String
|
||||||
}
|
}
|
||||||
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
|
|
||||||
role, err := r.Repository.GetRoleForTeamMember(ctx, db.GetRoleForTeamMemberParams{UserID: user.UserID, TeamID: obj.TeamID})
|
role, err := r.Repository.GetRoleForTeamMember(ctx, db.GetRoleForTeamMemberParams{UserID: user.UserID, TeamID: obj.TeamID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.New(ctx).WithError(err).Error("get role for projet member by user ID")
|
logger.New(ctx).WithError(err).Error("get role for projet member by user ID")
|
||||||
@ -1752,6 +1634,7 @@ func (r *teamResolver) Members(ctx context.Context, obj *db.Team) ([]Member, err
|
|||||||
return members, err
|
return members, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
|
||||||
members = append(members, Member{ID: user.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
|
members = append(members, Member{ID: user.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
|
||||||
Username: user.Username, Owned: ownedList, Member: memberList, Role: &db.Role{Code: role.Code, Name: role.Name},
|
Username: user.Username, Owned: ownedList, Member: memberList, Role: &db.Role{Code: role.Code, Name: role.Name},
|
||||||
})
|
})
|
||||||
@ -1841,9 +1724,6 @@ func (r *Resolver) RefreshToken() RefreshTokenResolver { return &refreshTokenRes
|
|||||||
// Task returns TaskResolver implementation.
|
// Task returns TaskResolver implementation.
|
||||||
func (r *Resolver) Task() TaskResolver { return &taskResolver{r} }
|
func (r *Resolver) Task() TaskResolver { return &taskResolver{r} }
|
||||||
|
|
||||||
// TaskActivity returns TaskActivityResolver implementation.
|
|
||||||
func (r *Resolver) TaskActivity() TaskActivityResolver { return &taskActivityResolver{r} }
|
|
||||||
|
|
||||||
// TaskChecklist returns TaskChecklistResolver implementation.
|
// TaskChecklist returns TaskChecklistResolver implementation.
|
||||||
func (r *Resolver) TaskChecklist() TaskChecklistResolver { return &taskChecklistResolver{r} }
|
func (r *Resolver) TaskChecklist() TaskChecklistResolver { return &taskChecklistResolver{r} }
|
||||||
|
|
||||||
@ -1873,10 +1753,27 @@ type projectLabelResolver struct{ *Resolver }
|
|||||||
type queryResolver struct{ *Resolver }
|
type queryResolver struct{ *Resolver }
|
||||||
type refreshTokenResolver struct{ *Resolver }
|
type refreshTokenResolver struct{ *Resolver }
|
||||||
type taskResolver struct{ *Resolver }
|
type taskResolver struct{ *Resolver }
|
||||||
type taskActivityResolver struct{ *Resolver }
|
|
||||||
type taskChecklistResolver struct{ *Resolver }
|
type taskChecklistResolver struct{ *Resolver }
|
||||||
type taskChecklistItemResolver struct{ *Resolver }
|
type taskChecklistItemResolver struct{ *Resolver }
|
||||||
type taskGroupResolver struct{ *Resolver }
|
type taskGroupResolver struct{ *Resolver }
|
||||||
type taskLabelResolver struct{ *Resolver }
|
type taskLabelResolver struct{ *Resolver }
|
||||||
type teamResolver struct{ *Resolver }
|
type teamResolver struct{ *Resolver }
|
||||||
type userAccountResolver struct{ *Resolver }
|
type userAccountResolver struct{ *Resolver }
|
||||||
|
|
||||||
|
// !!! WARNING !!!
|
||||||
|
// The code below was going to be deleted when updating resolvers. It has been copied here so you have
|
||||||
|
// one last chance to move it out of harms way if you want. There are two reasons this happens:
|
||||||
|
// - When renaming or deleting a resolver the old code will be put in here. You can safely delete
|
||||||
|
// it when you're done.
|
||||||
|
// - You have helper methods in this file. Move them out to keep these resolver files clean.
|
||||||
|
type MemberType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
MemberTypeInvited MemberType = "INVITED"
|
||||||
|
MemberTypeJoined MemberType = "JOINED"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MasterEntry struct {
|
||||||
|
MemberType MemberType
|
||||||
|
ID uuid.UUID
|
||||||
|
}
|
||||||
|
@ -135,38 +135,6 @@ type TaskBadges {
|
|||||||
checklist: ChecklistBadge
|
checklist: ChecklistBadge
|
||||||
}
|
}
|
||||||
|
|
||||||
type CausedBy {
|
|
||||||
id: ID!
|
|
||||||
fullName: String!
|
|
||||||
profileIcon: ProfileIcon
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivityData {
|
|
||||||
name: String!
|
|
||||||
value: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ActivityType {
|
|
||||||
TASK_ADDED
|
|
||||||
TASK_MOVED
|
|
||||||
TASK_MARKED_COMPLETE
|
|
||||||
TASK_MARKED_INCOMPLETE
|
|
||||||
TASK_DUE_DATE_CHANGED
|
|
||||||
TASK_DUE_DATE_ADDED
|
|
||||||
TASK_DUE_DATE_REMOVED
|
|
||||||
TASK_CHECKLIST_CHANGED
|
|
||||||
TASK_CHECKLIST_ADDED
|
|
||||||
TASK_CHECKLIST_REMOVED
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskActivity {
|
|
||||||
id: ID!
|
|
||||||
type: ActivityType!
|
|
||||||
data: [TaskActivityData!]!
|
|
||||||
causedBy: CausedBy!
|
|
||||||
createdAt: Time!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Task {
|
type Task {
|
||||||
id: ID!
|
id: ID!
|
||||||
taskGroup: TaskGroup!
|
taskGroup: TaskGroup!
|
||||||
@ -181,7 +149,6 @@ type Task {
|
|||||||
labels: [TaskLabel!]!
|
labels: [TaskLabel!]!
|
||||||
checklists: [TaskChecklist!]!
|
checklists: [TaskChecklist!]!
|
||||||
badges: TaskBadges!
|
badges: TaskBadges!
|
||||||
activity: [TaskActivity!]!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Organization {
|
type Organization {
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
CREATE TABLE task_activity_type (
|
|
||||||
task_activity_type_id int PRIMARY KEY,
|
|
||||||
code text NOT NULL,
|
|
||||||
template text NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO task_activity_type (task_activity_type_id, code, template) VALUES
|
|
||||||
(1, 'task_added_to_task_group', 'added this task to {{ index .Data "TaskGroup" }}'),
|
|
||||||
(2, 'task_moved_to_task_group', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
|
|
||||||
(3, 'task_mark_complete', 'marked this task complete'),
|
|
||||||
(4, 'task_mark_incomplete', 'marked this task incomplete'),
|
|
||||||
(5, 'task_due_date_changed', 'changed the due date to {{ index .Data "DueDate" }}'),
|
|
||||||
(6, 'task_due_date_added', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
|
|
||||||
(7, 'task_due_date_removed', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
|
|
||||||
(8, 'task_checklist_changed', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
|
|
||||||
(9, 'task_checklist_added', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
|
|
||||||
(10, 'task_checklist_removed', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}');
|
|
||||||
|
|
||||||
CREATE TABLE task_activity (
|
|
||||||
task_activity_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
||||||
active boolean NOT NULL DEFAULT true,
|
|
||||||
task_id uuid NOT NULL REFERENCES task(task_id),
|
|
||||||
created_at timestamptz NOT NULL,
|
|
||||||
caused_by uuid NOT NULL,
|
|
||||||
activity_type_id int NOT NULL REFERENCES task_activity_type(task_activity_type_id),
|
|
||||||
data jsonb
|
|
||||||
);
|
|
||||||
|
|
Reference in New Issue
Block a user