feat: apply new label to task when available

This commit is contained in:
Jordan Knott 2021-04-30 23:49:12 -05:00
parent 167d285d02
commit 5a9a66effe
3 changed files with 11 additions and 0 deletions

View File

@ -767,6 +767,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
onLabelToggle={labelID => { onLabelToggle={labelID => {
toggleTaskLabel({ variables: { taskID: task.id, projectLabelID: labelID } }); toggleTaskLabel({ variables: { taskID: task.id, projectLabelID: labelID } });
}} }}
taskID={task.id}
labelColors={data.labelColors} labelColors={data.labelColors}
labels={labelsRef} labels={labelsRef}
taskLabels={taskLabelsRef} taskLabels={taskLabelsRef}

View File

@ -8,11 +8,13 @@ import {
FindProjectDocument, FindProjectDocument,
useCreateProjectLabelMutation, useCreateProjectLabelMutation,
FindProjectQuery, FindProjectQuery,
useToggleTaskLabelMutation,
} from 'shared/generated/graphql'; } from 'shared/generated/graphql';
import LabelManager from 'shared/components/PopupMenu/LabelManager'; import LabelManager from 'shared/components/PopupMenu/LabelManager';
import LabelEditor from 'shared/components/PopupMenu/LabelEditor'; import LabelEditor from 'shared/components/PopupMenu/LabelEditor';
type LabelManagerEditorProps = { type LabelManagerEditorProps = {
taskID?: string;
labels: React.RefObject<Array<ProjectLabel>>; labels: React.RefObject<Array<ProjectLabel>>;
taskLabels: null | React.RefObject<Array<TaskLabel>>; taskLabels: null | React.RefObject<Array<TaskLabel>>;
projectID: string; projectID: string;
@ -21,6 +23,7 @@ type LabelManagerEditorProps = {
}; };
const LabelManagerEditor: React.FC<LabelManagerEditorProps> = ({ const LabelManagerEditor: React.FC<LabelManagerEditorProps> = ({
taskID,
labels: labelsRef, labels: labelsRef,
projectID, projectID,
labelColors, labelColors,
@ -29,7 +32,13 @@ const LabelManagerEditor: React.FC<LabelManagerEditorProps> = ({
}) => { }) => {
const [currentLabel, setCurrentLabel] = useState(''); const [currentLabel, setCurrentLabel] = useState('');
const { setTab, hidePopup } = usePopup(); const { setTab, hidePopup } = usePopup();
const [toggleTaskLabel] = useToggleTaskLabelMutation();
const [createProjectLabel] = useCreateProjectLabelMutation({ const [createProjectLabel] = useCreateProjectLabelMutation({
onCompleted: data => {
if (taskID) {
toggleTaskLabel({ variables: { taskID, projectLabelID: data.createProjectLabel.id } });
}
},
update: (client, newLabelData) => { update: (client, newLabelData) => {
updateApolloCache<FindProjectQuery>( updateApolloCache<FindProjectQuery>(
client, client,

View File

@ -267,6 +267,7 @@ const Project = () => {
onLabelToggle={labelID => { onLabelToggle={labelID => {
toggleTaskLabel({ variables: { taskID: task.id, projectLabelID: labelID } }); toggleTaskLabel({ variables: { taskID: task.id, projectLabelID: labelID } });
}} }}
taskID={task.id}
labelColors={data.labelColors} labelColors={data.labelColors}
labels={labelsRef} labels={labelsRef}
taskLabels={taskLabelsRef} taskLabels={taskLabelsRef}