Skip to content

Commit

Permalink
Merged branch feature/create-under-big-plan into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
horia141 committed Jun 2, 2024
1 parent feb0264 commit 0af0f40
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class InboxTaskFindArgs:
filter_ref_ids (Union[List[str], None, Unset]):
filter_project_ref_ids (Union[List[str], None, Unset]):
filter_sources (Union[List[InboxTaskSource], None, Unset]):
filter_big_plan_ref_ids (Union[List[str], None, Unset]):
"""

allow_archived: bool
Expand All @@ -28,6 +29,7 @@ class InboxTaskFindArgs:
filter_ref_ids: Union[List[str], None, Unset] = UNSET
filter_project_ref_ids: Union[List[str], None, Unset] = UNSET
filter_sources: Union[List[InboxTaskSource], None, Unset] = UNSET
filter_big_plan_ref_ids: Union[List[str], None, Unset] = UNSET
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
Expand Down Expand Up @@ -71,6 +73,15 @@ def to_dict(self) -> Dict[str, Any]:
else:
filter_sources = self.filter_sources

filter_big_plan_ref_ids: Union[List[str], None, Unset]
if isinstance(self.filter_big_plan_ref_ids, Unset):
filter_big_plan_ref_ids = UNSET
elif isinstance(self.filter_big_plan_ref_ids, list):
filter_big_plan_ref_ids = self.filter_big_plan_ref_ids

else:
filter_big_plan_ref_ids = self.filter_big_plan_ref_ids

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
Expand All @@ -87,6 +98,8 @@ def to_dict(self) -> Dict[str, Any]:
field_dict["filter_project_ref_ids"] = filter_project_ref_ids
if filter_sources is not UNSET:
field_dict["filter_sources"] = filter_sources
if filter_big_plan_ref_ids is not UNSET:
field_dict["filter_big_plan_ref_ids"] = filter_big_plan_ref_ids

return field_dict

Expand Down Expand Up @@ -162,13 +175,31 @@ def _parse_filter_sources(data: object) -> Union[List[InboxTaskSource], None, Un

filter_sources = _parse_filter_sources(d.pop("filter_sources", UNSET))

def _parse_filter_big_plan_ref_ids(data: object) -> Union[List[str], None, Unset]:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, list):
raise TypeError()
filter_big_plan_ref_ids_type_0 = cast(List[str], data)

return filter_big_plan_ref_ids_type_0
except: # noqa: E722
pass
return cast(Union[List[str], None, Unset], data)

filter_big_plan_ref_ids = _parse_filter_big_plan_ref_ids(d.pop("filter_big_plan_ref_ids", UNSET))

inbox_task_find_args = cls(
allow_archived=allow_archived,
include_notes=include_notes,
filter_just_workable=filter_just_workable,
filter_ref_ids=filter_ref_ids,
filter_project_ref_ids=filter_project_ref_ids,
filter_sources=filter_sources,
filter_big_plan_ref_ids=filter_big_plan_ref_ids,
)

inbox_task_find_args.additional_properties = d
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Any, Dict, List, Type, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

T = TypeVar("T", bound="TimePlanLoadResultActivityDonenessType0")


@_attrs_define
class TimePlanLoadResultActivityDonenessType0:
""" """

additional_properties: Dict[str, bool] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
time_plan_load_result_activity_doneness_type_0 = cls()

time_plan_load_result_activity_doneness_type_0.additional_properties = d
return time_plan_load_result_activity_doneness_type_0

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> bool:
return self.additional_properties[key]

def __setitem__(self, key: str, value: bool) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
1 change: 1 addition & 0 deletions gen/ts/webapi-client/gen/models/InboxTaskFindArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export type InboxTaskFindArgs = {
filter_ref_ids?: (Array<EntityId> | null);
filter_project_ref_ids?: (Array<EntityId> | null);
filter_sources?: (Array<InboxTaskSource> | null);
filter_big_plan_ref_ids?: (Array<EntityId> | null);
};

2 changes: 2 additions & 0 deletions src/core/jupiter/core/use_cases/inbox_tasks/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class InboxTaskFindArgs(UseCaseArgsBase):
filter_ref_ids: list[EntityId] | None
filter_project_ref_ids: list[EntityId] | None
filter_sources: list[InboxTaskSource] | None
filter_big_plan_ref_ids: list[EntityId] | None


@use_case_result_part
Expand Down Expand Up @@ -180,6 +181,7 @@ async def _perform_transactional_read(
status=filter_status,
source=filter_sources,
project_ref_id=args.filter_project_ref_ids or NoFilter(),
big_plan_ref_id=args.filter_big_plan_ref_ids or NoFilter(),
)

habits = await uow.get_for(Habit).find_all(
Expand Down
21 changes: 11 additions & 10 deletions src/webui/app/routes/workspace/inbox-tasks/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,24 @@ export async function action({ request }: ActionArgs) {
: undefined,
});

switch (bigPlanReason) {
switch (timePlanReason) {
case "for-time-plan":
return redirect(
`/workspace/time-plans/${result.new_time_plan_activity?.time_plan_ref_id}/${result.new_time_plan_activity?.ref_id}`
);

case "standard":
switch (timePlanReason) {
case "standard":
switch (bigPlanReason) {
case "for-big-plan":
return redirect(
`/workspace/inbox-tasks/${result.new_inbox_task.ref_id}`
`/workspace/big-plans/${query.bigPlanRefId as string}`
);

case "for-time-plan":
case "standard":
return redirect(
`/workspace/time-plans/${result.new_time_plan_activity?.time_plan_ref_id}/${result.new_time_plan_activity?.ref_id}`
`/workspace/inbox-tasks/${result.new_inbox_task.ref_id}`
);
}
break;

case "for-big-plan":
return redirect(`/workspace/big-plans/${query.bigPlanRefId as string}`);
}
} catch (error) {
if (
Expand Down
27 changes: 26 additions & 1 deletion src/webui/app/routes/workspace/time-plans/$id/$activityId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { ActionArgs, LoaderArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import type { ShouldRevalidateFunction } from "@remix-run/react";
import {
Link,
useActionData,
useFetcher,
useParams,
Expand All @@ -39,6 +40,7 @@ import { validationErrorToUIErrorInfo } from "~/logic/action-result";
import { timePlanActivityFeasabilityName } from "~/logic/domain/time-plan-activity-feasability";
import { timePlanActivityKindName } from "~/logic/domain/time-plan-activity-kind";
import { isWorkspaceFeatureAvailable } from "~/logic/domain/workspace";
import { LeafPanelExpansionState } from "~/rendering/leaf-panel-expansion";
import { standardShouldRevalidate } from "~/rendering/standard-should-revalidate";
import { useLoaderDataSafeForAnimation } from "~/rendering/use-loader-data-for-animation";
import { DisplayType } from "~/rendering/use-nested-entities";
Expand Down Expand Up @@ -191,6 +193,7 @@ export default function TimePlanActivity() {
showArchiveButton
enableArchiveButton={inputsEnabled}
returnLocation={`/workspace/time-plans/${id}`}
initialExpansionState={LeafPanelExpansionState.MEDIUM}
>
<GlobalError actionResult={actionData} />
<SectionCard
Expand Down Expand Up @@ -293,7 +296,29 @@ export default function TimePlanActivity() {
WorkspaceFeature.BIG_PLANS
) &&
loaderData.targetBigPlan && (
<SectionCard title="Target Big Plan">
<SectionCard
title="Target Big Plan"
actions={[
<Button
key="new-inbox-task"
variant="outlined"
disabled={!inputsEnabled}
to={`/workspace/inbox-tasks/new?timePlanReason=for-time-plan&timePlanRefId=${id}&bigPlanReason=for-big-plan&bigPlanRefId=${loaderData.targetBigPlan.ref_id}`}
component={Link}
>
New Inbox Task
</Button>,
<Button
key="from-current-inbox-tasks"
variant="outlined"
disabled={!inputsEnabled}
to={`/workspace/time-plans/${id}/add-from-current-inbox-tasks?bigPlanReason=for-big-plan&bigPlanRefId=${loaderData.targetBigPlan.ref_id}`}
component={Link}
>
From Current Inbox Tasks
</Button>,
]}
>
<BigPlanStack
topLevelInfo={topLevelInfo}
showOptions={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useActionData, useParams, useTransition } from "@remix-run/react";
import { ReasonPhrases, StatusCodes } from "http-status-codes";
import { useContext, useState } from "react";
import { z } from "zod";
import { parseForm, parseParams } from "zodix";
import { parseForm, parseParams, parseQuery } from "zodix";
import { getLoggedInApiClient } from "~/api-clients";
import { InboxTaskCard } from "~/components/inbox-task-card";
import { makeCatchBoundary } from "~/components/infra/catch-boundary";
Expand All @@ -32,6 +32,11 @@ const ParamsSchema = {
id: z.string(),
};

const QuerySchema = {
bigPlanReason: z.literal("for-big-plan").optional(),
bigPlanRefId: z.string().optional(),
};

const UpdateFormSchema = {
intent: z.string(),
targetInboxTaskRefIds: z.string().transform((s) => s.split(",")),
Expand All @@ -44,6 +49,15 @@ export const handle = {
export async function loader({ request, params }: LoaderArgs) {
const session = await getSession(request.headers.get("Cookie"));
const { id } = parseParams(params, ParamsSchema);
const query = parseQuery(request, QuerySchema);

const bigPlanReason = query.bigPlanReason || "standard";

if (bigPlanReason === "for-big-plan") {
if (!query.bigPlanRefId) {
throw new Response("Missing Big Plan Id", { status: 500 });
}
}

try {
const timePlanResult = await getLoggedInApiClient(
Expand All @@ -62,6 +76,8 @@ export async function loader({ request, params }: LoaderArgs) {
allow_archived: false,
include_notes: false,
filter_just_workable: true,
filter_big_plan_ref_ids:
query.bigPlanRefId !== undefined ? [query.bigPlanRefId] : undefined,
});

return json({
Expand Down

0 comments on commit 0af0f40

Please sign in to comment.