Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
feat: priority for items (#249)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Trümper <privat@truemper-nord.de>
  • Loading branch information
dennistruemper and dennistruemper authored Nov 11, 2023
1 parent 877bc43 commit d50e835
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 32 deletions.
17 changes: 14 additions & 3 deletions packages/backend/src/adapter/ampt/data/itemRepositoryAmpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export class ItemRepositoryAmpt implements ItemRepository {
id: item.value.itemId,
name: item.value.itemName,
description: item.value.itemDescription,
completed: item.value.completed
completed: item.value.completed,
priority: item.value.priority
};
})
);
Expand All @@ -120,8 +121,18 @@ export class ItemRepositoryAmpt implements ItemRepository {
const dependents = await data.get(`DEPENDS_ON_ITEM#${update.itemId}:*`, { label: 'label1' });
dependents.items.forEach(async (item) => {
const updateData = {
itemName: update.updatedFields?.name,
itemDescription: update.updatedFields?.description
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
itemName: update.updatedFields?.name ?? item.value.itemName,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
itemDescription: update.updatedFields?.description ?? item.value.itemDescription,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
priority: update.updatedFields?.priority ?? item.value.priority,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
completed: update.updatedFields?.completed ?? item.value.completed
}
await data.set(item.key, updateData);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/adapter/ampt/data/listRepositoryAmpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ export class ListRepositoryAmpt implements ListRepository {
itemId: input.itemId,
itemName: input.itemName,
itemDescription: input.itemDescription,
itemCompleted: input.itemCompleted
itemCompleted: input.itemCompleted,
priority: input.priority
};


const label1key = `DEPENDS_ON_ITEM${delimiter}${input.itemId}${amptDelimiter}LIST${delimiter}${input.listId}`;

await data.set(key, connectionDocument, {
Expand Down
24 changes: 14 additions & 10 deletions packages/backend/src/adapter/http/itemRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from 'express';
import { GetListDetailsResponse } from '../../domain/definitions/communication/getListDetailsRequestResponse';
import { GetItemDetailsResponse } from '../../domain/definitions/communication/getItemDetailsRequestResponse';
import {
CreateItemResponse,
GetItemsResponse,
Expand Down Expand Up @@ -72,7 +72,8 @@ function addGetItemDetailsRoute(router: Router, dependencies: Dependencies) {
name: loaded.value.item.name,
id: loaded.value.item.id,
description: loaded.value.item.description,
completed: loaded.value.item.completed
completed: loaded.value.item.completed,
priority: loaded.value.item.priority ?? 0
};

return res.status(200).send(response);
Expand Down Expand Up @@ -103,7 +104,8 @@ function addCreateItemForListRoute(router: Router, dependencies: Dependencies) {
itemName: data.name,
itemDescription: data.description,
listId: data.listId,
extraListIds: data.extraListIds
extraListIds: data.extraListIds,
priority: data.priority
});

if (created.success === false) {
Expand All @@ -125,7 +127,8 @@ function addCreateItemForListRoute(router: Router, dependencies: Dependencies) {
id: item.id,
name: item.name,
description: item.description,
listId: data.listId
listId: data.listId,
priority: item.priority ?? 0
};

return res.status(200).send(result);
Expand Down Expand Up @@ -166,11 +169,12 @@ function addGetItemDetailsForListRoute(router: Router, dependencies: Dependencie
}
}

const response: GetListDetailsResponse[] = loaded.value.items.map((list) => ({
id: list.id,
name: list.name,
description: list.description,
completed: list.completed
const response: GetItemDetailsResponse[] = loaded.value.items.map((item) => ({
id: item.id,
name: item.name,
description: item.description,
completed: item.completed,
priority: item.priority ?? 0
}));

return res.status(200).send(response);
Expand Down Expand Up @@ -206,7 +210,7 @@ function addUpdateItemDetailsRoute(router: Router, dependencies: Dependencies) {
itemId,
listId,
userId,
changes: {...paredBody.data, completed: paredBody.data.completed ?? null}
changes: {...paredBody.data, completed: paredBody.data.completed ?? null, priority: paredBody.data.priority}
});

if (loaded.success === false) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import z from 'zod';

export const getItemDetailsResponseSchema = z.object({
name: z.string(),
description: z.string().optional(),
id: z.string(),
priority: z.number()
});

export type GetItemDetailsResponse = z.infer<typeof getItemDetailsResponseSchema>;
export const getItemDetailsArrayResponseSchema = getItemDetailsResponseSchema.array();
export type GetItemDetailsArrayResponse = z.infer<typeof getItemDetailsArrayResponseSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const createItemRequestSchema = z.object({
listId: z.string(),
extraListIds: z.array(z.string()).optional(),
name: z.string(),
description: z.string().optional()
description: z.string().optional(),
priority: z.number().default(0)
});
export type CreateItemRequest = z.infer<typeof createItemRequestSchema>;

Expand All @@ -15,7 +16,8 @@ export const getItemResponseSchema = z.object({
name: z.string(),
description: z.string().optional(),
id: z.string(),
completed: z.string().optional()
completed: z.string().optional(),
priority: z.number().default(0)
});
export type GetItemsResponse = z.infer<typeof getItemResponseSchema>;

Expand All @@ -24,7 +26,8 @@ export const getItemsResponseSchema = getItemResponseSchema.array();
export const updateItemRequestSchema = z.object({
name: z.string().nullish(),
description: z.string().nullish(),
completed: z.string().nullish()
completed: z.string().nullish(),
priority: z.number().default(0)
});

export const updateItemResponseSchema = z.object({
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/domain/definitions/itemPink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const itemSchema = z.object({
id: z.string(),
name: z.string(),
description: z.string().optional(),
completed: z.string().datetime({ offset: false }).optional()
completed: z.string().datetime({ offset: false }).optional(),
priority: z.number().optional()
});

export type ItemPink = z.infer<typeof itemSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const listToItemConnectionSchema = z.object({
itemName: z.string(),
itemDescription: z.string().optional(),
itemCompleted: z.string().optional(),
completed: z.string().optional()
completed: z.string().optional(),
priority: z.number().default(0)
});
export type ListToItemConnection = z.infer<typeof listToItemConnectionSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type ConnectItemToListInput = {
itemName: string;
itemDescription?: string;
itemCompleted?: string;
priority: number
};

export type CreateListErrors = UNKNOWN_DATA_SHAPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CreateItemInput {
itemDescription?: string;
listId: string;
extraListIds?: string[];
priority: number;
}

export type CreateItemOutput = {
Expand All @@ -34,7 +35,8 @@ export class CreateItemForListUsecase
async execute(data: CreateItemInput): Promise<Result<CreateItemOutput, Errors>> {
const created = await this.itemRepository.create({
name: data.itemName,
description: data.itemDescription
description: data.itemDescription,
priority: data.priority
});
if (created.success === false) {
return failure('Item not created', created.code);
Expand All @@ -54,7 +56,8 @@ export class CreateItemForListUsecase
listId: data.listId,
itemId: created.value.id,
itemName: data.itemName,
itemDescription: data.itemDescription
itemDescription: data.itemDescription,
priority: data.priority
});

if (connectResult.success === false)
Expand Down
17 changes: 16 additions & 1 deletion packages/frontend-elm/src/Api/Item.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type alias CreateItemPink =
{ name : String
, description : Maybe String
, listId : String
, priority : Int
}


Expand Down Expand Up @@ -51,11 +52,22 @@ getItemById options =

itemDecoder : Decoder ItemPink
itemDecoder =
Decode.map4 ItemPink
Decode.map5 (\id name description completed priority -> { id = id, name = name, description = description, completed = completed, priority = priority })
(Decode.field "id" Decode.string)
(Decode.field "name" Decode.string)
(Decode.maybe (Decode.field "description" Decode.string))
(Decode.maybe (Decode.field "completed" Decode.string))
(Decode.maybe (Decode.field "priority" Decode.int)
|> Decode.andThen
(\priority ->
case priority of
Just value ->
Decode.succeed value

Nothing ->
Decode.succeed 0
)
)


createItem : { onResponse : Result (Http.Detailed.Error String) ( Http.Metadata, ItemPink ) -> msg, baseUrl : String, token : String, body : CreateItemPink } -> Effect msg
Expand All @@ -72,6 +84,7 @@ createItem options =
(Encode.object
([ ( "name", Encode.string options.body.name )
, ( "listId", Encode.string options.body.listId )
, ( "priority", Encode.int options.body.priority )
]
++ (case options.body.description of
Just description ->
Expand Down Expand Up @@ -115,6 +128,7 @@ type alias UpdateItemBody =
, itemId : String
, name : Maybe String
, description : Maybe String
, priority : Int
}


Expand Down Expand Up @@ -145,6 +159,7 @@ updateItem options =
Nothing ->
[]
)
++ [ ( "priority", Encode.int options.body.priority ) ]
)
)
, expect = Http.Detailed.expectJson options.onResponse itemDecoder
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-elm/src/Components/ActionBarWrapper.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ viewActionBarWrapper : List (Html.Html msg) -> List (Html.Html msg) -> Html.Html
viewActionBarWrapper items content =
Html.div [ class "" ]
[ Html.div
[ class "bg-pink-200 h-16 rounded-t-xl lg:rounded-xl p-2 pb-4 lg:pb-2 lg:mb-4 flex flex-row justify-between justify-items-center fixed lg:relative bottom-0 lg:top-0 left-0 w-full" ]
[ class "bg-pink-200 h-16 rounded-t-xl lg:rounded-xl p-2 pb-4 lg:pb-2 lg:mb-4 flex flex-row justify-between justify-items-center fixed lg:relative bottom-0 lg:top-0 left-0 w-full z-50" ]
(if List.length items > 1 then
items

Expand Down
47 changes: 47 additions & 0 deletions packages/frontend-elm/src/Components/Dropdown.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Components.Dropdown exposing (ExactOneSelection(..), viewDropdown)

import Html exposing (Html)
import Html.Attributes as Attr exposing (class)
import Html.Events as Events


type ExactOneSelection a
= ExactOneSelection (List a) a (List a)


viewDropdown : { id : String, name : String, variants : ExactOneSelection { value : a, text : String }, valueToString : a -> String, selectedMsg : String -> msg } -> Html msg
viewDropdown options =
Html.div [ class "relative" ]
[ Html.label
[ Attr.for options.id
, class "absolute -top-2 left-2 inline-block px-1 text-xs font-medium text-pink-900"
]
[ Html.text options.name ]
, Html.select
[ Attr.id options.id
, Attr.name options.name
, Events.onInput options.selectedMsg
, class "bg-pink-50 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-pink-200 placeholder:text-gray-500 text-pink-900 focus:ring-2 focus:ring-inset focus:ring-pink-300 sm:text-sm sm:leading-6"
]
(case options.variants of
ExactOneSelection before selected after ->
List.map
(\variant ->
Html.option [ Attr.value (options.valueToString variant.value) ]
[ Html.text variant.text ]
)
before
++ [ Html.option
[ Attr.selected True
, Attr.value (options.valueToString selected.value)
]
[ Html.text selected.text ]
]
++ List.map
(\variant ->
Html.option [ Attr.value (options.valueToString variant.value) ]
[ Html.text variant.text ]
)
after
)
]
Loading

0 comments on commit d50e835

Please sign in to comment.