Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cs-7456-move-executio…
Browse files Browse the repository at this point in the history
…n-of-database-migrations-to-dedicated-actions
  • Loading branch information
habdelra committed Nov 11, 2024
2 parents 0291bbe + 953143e commit 3c07142
Show file tree
Hide file tree
Showing 21 changed files with 1,610 additions and 897 deletions.
98 changes: 38 additions & 60 deletions packages/base/cards-grid.gts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
realmInfo,
realmURL,
type BaseDef,
linksToMany,
} from './card-api';
import {
AddButton,
Expand Down Expand Up @@ -45,7 +44,6 @@ import { MenuItem } from '@cardstack/boxel-ui/helpers';
import LayoutGridPlusIcon from '@cardstack/boxel-icons/layout-grid-plus';
import Captions from '@cardstack/boxel-icons/captions';
import CardsIcon from '@cardstack/boxel-icons/cards';
import Star from '@cardstack/boxel-icons/star';
import { registerDestructor } from '@ember/destroyable';

type IconComponent = typeof Captions;
Expand Down Expand Up @@ -149,43 +147,41 @@ class Isolated extends Component<typeof CardsGrid> {
</div>

<ul class='cards' data-test-cards-grid-cards>
{{#if this.isShowingCards}}
{{#let
(component @context.prerenderedCardSearchComponent)
as |PrerenderedCardSearch|
}}
<PrerenderedCardSearch
@query={{this.query}}
@format='fitted'
@realms={{this.realms}}
>

<:loading>
Loading...
</:loading>
<:response as |cards|>
{{#each cards as |card|}}
<li
class='card'
{{@context.cardComponentModifier
cardId=card.url
format='data'
fieldType=undefined
fieldName=undefined
}}
data-test-cards-grid-item={{removeFileExtension card.url}}
{{! In order to support scrolling cards into view we use a selector that is not pruned out in production builds }}
data-cards-grid-item={{removeFileExtension card.url}}
>
<CardContainer @displayBoundaries='true'>
{{card.component}}
</CardContainer>
</li>
{{/each}}
</:response>
</PrerenderedCardSearch>
{{/let}}
{{/if}}
{{#let
(component @context.prerenderedCardSearchComponent)
as |PrerenderedCardSearch|
}}
<PrerenderedCardSearch
@query={{this.query}}
@format='fitted'
@realms={{this.realms}}
>

<:loading>
Loading...
</:loading>
<:response as |cards|>
{{#each cards as |card|}}
<li
class='card'
{{@context.cardComponentModifier
cardId=card.url
format='data'
fieldType=undefined
fieldName=undefined
}}
data-test-cards-grid-item={{removeFileExtension card.url}}
{{! In order to support scrolling cards into view we use a selector that is not pruned out in production builds }}
data-cards-grid-item={{removeFileExtension card.url}}
>
<CardContainer @displayBoundaries='true'>
{{card.component}}
</CardContainer>
</li>
{{/each}}
</:response>
</PrerenderedCardSearch>
{{/let}}
</ul>

{{#if @context.actions.createCard}}
Expand Down Expand Up @@ -330,18 +326,6 @@ class Isolated extends Component<typeof CardsGrid> {

filters: { displayName: string; icon: IconComponent; query: any }[] =
new TrackedArray([
{
displayName: 'Favorites',
icon: Star,
query: {
filter: {
any:
this.args.model.favorites?.map((card) => {
return { eq: { id: card.id } } ?? {};
}) ?? [],
},
},
},
{
displayName: 'All Cards',
icon: CardsIcon,
Expand Down Expand Up @@ -401,13 +385,6 @@ class Isolated extends Component<typeof CardsGrid> {
return { ...this.activeFilter.query, sort: this.selectedSortOption.sort };
}

private get isShowingCards() {
return (
this.activeFilter.displayName !== 'Favorites' ||
(this.args.model.favorites && this.args.model.favorites.length > 0)
);
}

private createCard = restartableTask(async () => {
let preselectedCardTypeQuery: Query | undefined;
let activeFilterRef = this.activeFilter?.query?.filter?.type;
Expand Down Expand Up @@ -464,7 +441,9 @@ class Isolated extends Component<typeof CardsGrid> {
`${baseRealm.url}cards-grid/CardsGrid`,
];

this.filters.splice(2, this.filters.length);
// Remove all filter items except the first one,
// as 'All Cards' is a predefined filter and not a result from the card type summary API.
this.filters.splice(1, this.filters.length);
cardTypeSummaries.forEach((summary) => {
if (excludedCardTypeIds.includes(summary.id)) {
return;
Expand Down Expand Up @@ -513,7 +492,6 @@ export class CardsGrid extends CardDef {
return this.realmName;
},
});
@field favorites = linksToMany(CardDef);

static getDisplayName(instance: BaseDef) {
if (isCardInstance(instance)) {
Expand Down
63 changes: 62 additions & 1 deletion packages/billing/billing-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ export async function getPlanByStripeId(
} as Plan;
}

export async function getPlan(dbAdapter: DBAdapter, id: string): Promise<Plan> {
let results = await query(dbAdapter, [
`SELECT * FROM plans WHERE id = `,
param(id),
]);

if (results.length !== 1) {
throw new Error(`No plan found with id: ${id}`);
}

return {
id: results[0].id,
name: results[0].name,
monthlyPrice: results[0].monthly_price,
creditsIncluded: results[0].credits_included,
} as Plan;
}

export async function updateUserStripeCustomerId(
dbAdapter: DBAdapter,
userId: string,
Expand Down Expand Up @@ -140,6 +158,26 @@ export async function getUserByStripeId(
} as User;
}

export async function getUserByMatrixUserId(
dbAdapter: DBAdapter,
matrixUserId: string,
): Promise<User | null> {
let results = await query(dbAdapter, [
`SELECT * FROM users WHERE matrix_user_id = `,
param(matrixUserId),
]);

if (results.length !== 1) {
return null;
}

return {
id: results[0].id,
matrixUserId: results[0].matrix_user_id,
stripeCustomerId: results[0].stripe_customer_id,
} as User;
}

export async function insertSubscriptionCycle(
dbAdapter: DBAdapter,
subscriptionCycle: {
Expand Down Expand Up @@ -283,7 +321,7 @@ export async function sumUpCreditsLedger(

let results = await query(dbAdapter, ledgerQuery);

return parseInt(results[0].sum as string);
return results[0].sum != null ? parseInt(results[0].sum as string) : 0;
}

export async function getCurrentActiveSubscription(
Expand Down Expand Up @@ -315,6 +353,29 @@ export async function getCurrentActiveSubscription(
} as Subscription;
}

export async function getMostRecentSubscription(
dbAdapter: DBAdapter,
userId: string,
) {
let results = await query(dbAdapter, [
`SELECT * FROM subscriptions WHERE user_id = `,
param(userId),
`ORDER BY started_at DESC`,
]);
if (results.length === 0) {
return null;
}

return {
id: results[0].id,
userId: results[0].user_id,
planId: results[0].plan_id,
startedAt: results[0].started_at,
status: results[0].status,
stripeSubscriptionId: results[0].stripe_subscription_id,
} as Subscription;
}

export async function getMostRecentSubscriptionCycle(
dbAdapter: DBAdapter,
subscriptionId: string,
Expand Down
67 changes: 36 additions & 31 deletions packages/boxel-ui/addon/src/components/drag-and-drop/index.gts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export interface DndKanbanBoardArgs<DndColumn> {
columns: DndColumn[];
isDisabled?: boolean;
isLoading?: boolean;
onMove?: (card: DndItem, column: DndColumn) => void;
onMove?: (
draggedCard: DndItem,
targetCard: DndItem,
sourceColumn: DndColumn,
targetColumn: DndColumn,
) => void;
}

export class DndColumn {
Expand Down Expand Up @@ -101,41 +106,41 @@ export default class DndKanbanBoard extends Component<
edge,
},
}: any) {
if (dropTargetParent.cards.length === 0) {
draggedItemParent.cards = this.removeItem(
draggedItemParent.cards,
draggedItem,
);
dropTargetParent.cards = this.insertAt(
dropTargetParent.cards,
0,
draggedItem,
);
} else {
if (dropTarget !== undefined) {
draggedItemParent.cards = this.removeItem(
draggedItemParent.cards,
draggedItemParent.cards = this.removeItem(
draggedItemParent.cards,
draggedItem,
);

if (dropTarget !== undefined) {
if (edge === 'top') {
dropTargetParent.cards = this.insertBefore(
dropTargetParent.cards,
dropTarget,
draggedItem,
);
if (edge === 'top') {
dropTargetParent.cards = this.insertBefore(
dropTargetParent.cards,
dropTarget,
draggedItem,
);
} else if (edge === 'bottom') {
dropTargetParent.cards = this.insertAfter(
dropTargetParent.cards,
dropTarget,
draggedItem,
);
} else {
throw new Error('Invalid edge');
}
} else if (edge === 'bottom') {
dropTargetParent.cards = this.insertAfter(
dropTargetParent.cards,
dropTarget,
draggedItem,
);
} else {
throw new Error('Invalid edge');
}
} else {
if (dropTargetParent !== undefined) {
// If the drop target is undefined, but the dropTargetParent is defined, we are dropping the card into last index of the drop target of the column
dropTargetParent.cards = [...dropTargetParent.cards, draggedItem];
}
}

if (this.args.onMove) {
this.args.onMove(draggedItem, dropTargetParent);
this.args.onMove(
draggedItem,
dropTarget,
draggedItemParent,
dropTargetParent,
);
}
}

Expand Down
Loading

0 comments on commit 3c07142

Please sign in to comment.