Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Queue Dynamo conversion to Typescript, and number of fixes #2603

Merged
merged 14 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions src/client/components/featuredQueue/MoveModal.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions src/client/components/featuredQueue/QueueItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import { Col, Flexbox } from 'components/base/Layout';
import Text from 'components/base/Text';
import CSRFForm from 'components/CSRFForm';
import CubePreview from 'components/cube/CubePreview';
import MoveModal from 'components/featuredQueue/MoveModal';
import withModal from 'components/WithModal';
import Cube from 'datatypes/Cube';

const MoveButton = withModal(Button, MoveModal);

interface QueueItemProps {
cube: Cube;
index: number;
Expand Down Expand Up @@ -42,9 +38,6 @@ const QueueItem: React.FC<QueueItemProps> = ({ cube, index }) => {
Remove
</Button>
</CSRFForm>
<MoveButton block color="accent" disabled={index < 2} modalprops={{ cube, index }}>
Move
</MoveButton>
</Flexbox>
</Flexbox>
</CardBody>
Expand Down
14 changes: 12 additions & 2 deletions src/client/pages/FeaturedCubesQueuePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import MainLayout from 'layouts/MainLayout';
interface FeaturedCubesQueuePageProps {
cubes: Cube[];
daysBetweenRotations: number;
lastRotation: Date;
lastRotation: number;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the backend and frontend code, it is a number

loginCallback: string;
}

Expand All @@ -38,7 +38,17 @@ const FeaturedCubesQueuePage: React.FC<FeaturedCubesQueuePageProps> = ({ cubes,
<Flexbox direction="col" gap="2">
<Flexbox direction="row" gap="2" alignItems="center">
<AddCubeButton color="primary">Add Cube to Queue</AddCubeButton>
<RotateButton color="accent">Rotate featured cubes</RotateButton>
<RotateButton
color="accent"
modalprops={{
target: `/admin/featuredcubes/rotate`,
title: 'Confirm Rotation',
message: 'Are you sure you want to rotate the featured cubes?',
buttonText: 'Submit',
}}
>
Rotate featured cubes
</RotateButton>
<Text sm semibold>
Last rotation: {new Date(lastRotation).toLocaleDateString()}
</Text>
Expand Down
15 changes: 15 additions & 0 deletions src/datatypes/FeaturedQueue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum FeaturedQueueStatus {
ACTIVE = 'a',
INACTIVE = 'i',
}

export type NewFeaturedQueueItem = {
cube: string; //Cube ID
date: number;
owner: string; //User id
featuredOn: number | null; //Null indicates not yet featured
};

export type FeaturedQueueItem = NewFeaturedQueueItem & {
status: FeaturedQueueStatus;
};
104 changes: 0 additions & 104 deletions src/dynamo/models/featuredQueue.js

This file was deleted.

95 changes: 95 additions & 0 deletions src/dynamo/models/featuredQueue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { DocumentClient } from 'aws-sdk2-types/lib/dynamodb/document_client';

import { FeaturedQueueItem, FeaturedQueueStatus, NewFeaturedQueueItem } from '../../datatypes/FeaturedQueue';
import createClient, { QueryInput } from '../util';

const client = createClient({
name: 'FEATURED_QUEUE',
partitionKey: 'cube',
indexes: [
{
name: 'ByDate',
partitionKey: 'status',
sortKey: 'date',
},
],
attributes: {
cube: 'S',
date: 'N',
status: 'S',
},
});

module.exports = {
getByCube: async (id: string): Promise<FeaturedQueueItem> => {
return (await client.get(id)).Item as FeaturedQueueItem;
},
put: async (document: NewFeaturedQueueItem): Promise<void> => {
await client.put({
...document,
status: FeaturedQueueStatus.ACTIVE,
});
},
querySortedByDate: async (
lastKey?: DocumentClient.Key,
limit = 36,
): Promise<{ items?: FeaturedQueueItem[]; lastKey?: DocumentClient.Key }> => {
//Using keyof .. provides static checking that the attribute exists in the type. Also its own const b/c inline "as keyof" not validating
const statusAttr: keyof FeaturedQueueItem = 'status';

const query: QueryInput = {
IndexName: 'ByDate',
KeyConditionExpression: '#status = :status',
ExpressionAttributeNames: {
'#status': statusAttr,
},
ExpressionAttributeValues: {
':status': FeaturedQueueStatus.ACTIVE,
},
Limit: limit,
};
if (lastKey) {
query.ExclusiveStartKey = lastKey;
}
const result = await client.query(query);

return {
items: result.Items as FeaturedQueueItem[],
lastKey: result.LastEvaluatedKey,
};
},
queryWithOwnerFilter: async (
ownerID: string,
lastKey?: DocumentClient.Key,
): Promise<{ items?: FeaturedQueueItem[]; lastKey?: DocumentClient.Key }> => {
//Using keyof .. provides static checking that the attribute exists in the type. Also its own const b/c inline "as keyof" not validating
const statusAttr: keyof FeaturedQueueItem = 'status';
const ownerAttr: keyof FeaturedQueueItem = 'owner';

const query: QueryInput = {
IndexName: 'ByDate',
KeyConditionExpression: '#status = :status',
FilterExpression: '#owner = :owner',
ExpressionAttributeNames: {
'#status': statusAttr,
'#owner': ownerAttr,
},
ExpressionAttributeValues: {
':status': FeaturedQueueStatus.ACTIVE,
':owner': ownerID,
},
};
if (lastKey) {
query.ExclusiveStartKey = lastKey;
}
const result = await client.query(query);

return {
items: result.Items as FeaturedQueueItem[],
lastKey: result.LastEvaluatedKey,
};
},
batchPut: async (documents: FeaturedQueueItem[]): Promise<void> => client.batchPut(documents),
createTable: async (): Promise<DocumentClient.CreateTableOutput> => client.createTable(),
delete: async (id: string): Promise<void> => client.delete({ cube: id }),
};
3 changes: 2 additions & 1 deletion src/jobs/rotate_featured.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console -- Debugging */
const fq = require('../util/featuredQueue');
const FeaturedQueue = require('../dynamo/models/featuredQueue');
const util = require('../util/util');
Expand All @@ -16,7 +17,7 @@ const User = require('../dynamo/models/user');
console.warn(message);
}

if (rotate.status === 'false') {
if (rotate.success === 'false') {
console.error('featured cube rotation failed!');
return;
}
Expand Down
Loading
Loading