Skip to content

Commit

Permalink
Add 'isStarred' to table and mutate from client
Browse files Browse the repository at this point in the history
Co-Authored-By: Tom Richards <[email protected]>
  • Loading branch information
frederickobrien and twrichards committed Sep 15, 2023
1 parent 46861fd commit 7630d6d
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 28 deletions.
67 changes: 45 additions & 22 deletions cdk/lib/__snapshots__/stack.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,7 @@ type Mutation {
editItem(itemId: String!, input: EditItemInput!): Item
deleteItem(itemId: String!): Item
claimItem(itemId: String!): Claimed
setIsStarred(itemId: String!, isStarred: Boolean!): Item
seenItem(input: LastItemSeenByUserInput!): LastItemSeenByUser
setWebPushSubscriptionForUser(webPushSubscription: AWSJSON): MyUser
addManuallyOpenedPinboardIds(pinboardId: String!, maybeEmailOverride: String): MyUser
Expand All @@ -2278,7 +2279,7 @@ type Mutation {
type Subscription {
onMutateItem(
pinboardId: String
): Item @aws_subscribe(mutations: [\\"createItem\\", \\"editItem\\", \\"deleteItem\\"])
): Item @aws_subscribe(mutations: [\\"createItem\\", \\"editItem\\", \\"deleteItem\\", \\"setIsStarred\\"])
onClaimItem(
pinboardId: String
Expand Down Expand Up @@ -2313,6 +2314,7 @@ type Item {
relatedItemId: String
editHistory: [AWSDateTime!]
deletedAt: AWSDateTime
isStarred: Boolean!
}
type LastItemSeenByUser {
Expand Down Expand Up @@ -2467,7 +2469,7 @@ type PinboardIdWithItemCounts {
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "addManuallyOpenedPinboardIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2488,7 +2490,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "claimItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2509,7 +2511,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "createItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2530,7 +2532,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "deleteItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2551,7 +2553,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "editItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2572,7 +2574,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "removeManuallyOpenedPinboardIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2593,7 +2595,28 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "seenItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
"Type": "AWS::AppSync::Resolver",
},
"pinboardappsyncapidatabasebridgelambdadsMutationsetIsStarredResolver7A053545": Object {
"DependsOn": Array [
"pinboardappsyncapidatabasebridgelambdads970CB9A7",
"pinboardappsyncapiSchema868D9F5B",
],
"Properties": Object {
"ApiId": Object {
"Fn::GetAtt": Array [
"pinboardappsyncapi9D519400",
"ApiId",
],
},
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "setIsStarred",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2614,7 +2637,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "setWebPushSubscriptionForUser",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2635,7 +2658,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "visitTourStep",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2656,7 +2679,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getGroupPinboardIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2677,7 +2700,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getItemCounts",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2698,7 +2721,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getMyUser",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2719,7 +2742,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getUsers",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2740,7 +2763,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "listItems",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2761,7 +2784,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "listLastItemSeenByUsers",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2782,7 +2805,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "searchMentionableUsers",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand Down Expand Up @@ -2907,7 +2930,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "grid_bridge_lambda_ds",
"FieldName": "asGridPayload",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2928,7 +2951,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "grid_bridge_lambda_ds",
"FieldName": "getGridSearchSummary",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand Down Expand Up @@ -3053,7 +3076,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "workflow_bridge_lambda_ds",
"FieldName": "getPinboardByComposerId",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -3074,7 +3097,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "workflow_bridge_lambda_ds",
"FieldName": "getPinboardsByIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -3095,7 +3118,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "workflow_bridge_lambda_ds",
"FieldName": "listPinboards",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : b72f387aabaad7462e0e00a8ab981ffc
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand Down
9 changes: 9 additions & 0 deletions client/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const itemReturnFields = `
relatedItemId
editHistory
deletedAt
isStarred
`;

// TODO: consider updating the resolver (cdk/stack.ts) to use a Query with a secondary index (if performance degrades when we have lots of items)
Expand Down Expand Up @@ -241,6 +242,14 @@ export const gqlOnClaimItem = (pinboardId: string) => gql`
}
`;

export const gqlSetIsStarred = gql`
mutation SetIsStarred($itemId: String!, $isStarred: Boolean!) {
setIsStarred(itemId: $itemId, isStarred: $isStarred) {
${itemReturnFields}
}
}
`;

const gridBadgeFields = `
text
color
Expand Down
11 changes: 8 additions & 3 deletions client/src/itemHoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useConfirmModal } from "./modal";
import { scrollbarsCss } from "./styling";
import { composer } from "../colours";
import { useMutation } from "@apollo/client";
import { gqlDeleteItem } from "../gql";
import { gqlDeleteItem, gqlSetIsStarred } from "../gql";
import { Item } from "shared/graphql/graphql";
import { PINBOARD_TELEMETRY_TYPE, TelemetryContext } from "./types/Telemetry";
import { useTourProgress } from "./tour/tourState";
Expand Down Expand Up @@ -55,7 +55,12 @@ export const ItemHoverMenu = ({
</div>
</React.Fragment>
);
const [isStarred, setIsStarred] = React.useState(false);

const isStarred = item.isStarred;
const [setIsStarred] = useMutation(gqlSetIsStarred);
const toggleIsStarred = () => {
setIsStarred({ variables: { itemId: item.id, isStarred: !isStarred } });
};

useEffect(
() => setMaybeDeleteItemModalElement(deleteConfirmModalElement),
Expand Down Expand Up @@ -141,7 +146,7 @@ export const ItemHoverMenu = ({
`}
>
<button
onClick={() => setIsStarred((isStarred) => !isStarred)}
onClick={toggleIsStarred}
title={isStarred ? "Unstar" : "Star"}
>
{isStarred ? <SvgStar /> : <SvgStarOutline />}
Expand Down
4 changes: 2 additions & 2 deletions client/src/starred/starredMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import ReactDOM from "react-dom";

export const STARRED_MESSAGES_HTML_TAG = "pinboard-starred-messages";

interface StarredMessagesProps {}
// interface StarredMessagesProps {}

const StarredMessages = (props: StarredMessagesProps) => (
const StarredMessages = (/* props: StarredMessagesProps */) => (
<div>
<p>Starred Messages</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions client/src/tour/tourMessageReplies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const buildMessageItem = (
claimedByEmail: null,
claimable: false,
pinboardId: demoPinboardData.id,
isStarred: false,
});

export const replyTo = (
Expand Down
1 change: 1 addition & 0 deletions client/src/tour/tourState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export const TourStateProvider: React.FC = ({ children }) => {
})),
groupMentions: [], //TODO - map variables.input.groupMentions to mention handle,
claimable: variables.input.claimable || false,
isStarred: false,
};
setSuccessfulSends((prevSuccessfulSends) => [
...prevSuccessfulSends,
Expand Down
3 changes: 3 additions & 0 deletions database-bridge-lambda/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getGroupPinboardIds,
getItemCounts,
listItems,
setIsStarred,
} from "./sql/Item";
import { Sql } from "../../shared/database/types";
import { listLastItemSeenByUsers, seenItem } from "./sql/LastItemSeenByUser";
Expand Down Expand Up @@ -42,6 +43,8 @@ const run = (
return deleteItem(sql, args, userEmail);
case "claimItem":
return claimItem(sql, args, userEmail);
case "setIsStarred":
return setIsStarred(sql, args, userEmail);
case "listItems":
return listItems(sql, args, userEmail);
case "seenItem":
Expand Down
13 changes: 13 additions & 0 deletions database-bridge-lambda/src/sql/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ export const claimItem = (
};
});

export const setIsStarred = async (
sql: Sql,
args: { itemId: string; isStarred: boolean },
userEmail: string
) =>
sql`
UPDATE "Item"
SET
"isStarred" = ${args.isStarred}
WHERE "id" = ${args.itemId}
RETURNING ${fragmentItemFields(sql, userEmail)}
`.then((rows) => rows[0]);

export const getGroupPinboardIds = async (
sql: Sql,
userEmail: string
Expand Down
1 change: 1 addition & 0 deletions notifications-lambda/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Item } from "shared/graphql/graphql";
relatedItemId: null,
editHistory: null,
deletedAt: null,
isStarred: false,
} satisfies Item,
users: [yourUser as UserWithWebPushSubscription],
});
Expand Down
2 changes: 2 additions & 0 deletions shared/database/local/runDatabaseSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const runSetupTriggerSqlFile = (
getEmailLambdaFunctionName(stage),
EMAIL_DATABASE_TRIGGER_NAME
),
"add isStarred column to Item table": () =>
runSetupSqlFile(sql, "020-AddIsStarredColumnToItemTable.sql"),
};

const allSteps = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "Item"
ADD COLUMN "isStarred" BOOLEAN NOT NULL DEFAULT FALSE;
1 change: 1 addition & 0 deletions shared/graphql/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const MUTATIONS = {
"editItem",
"deleteItem",
"claimItem",
"setIsStarred",
"seenItem",
"setWebPushSubscriptionForUser",
"addManuallyOpenedPinboardIds",
Expand Down
Loading

0 comments on commit 7630d6d

Please sign in to comment.