-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Recents + Popular API Format - Frontend (#42305)
* fix tests * new API payload format for recents and populars * update url generation * update recents components * update tests * only show 5 recents in command palette * remove unused types * update tests * obey the linter * type updates * fix unit test * change where we filter recents --------- Co-authored-by: Bryan Maass <bryan.maass@gmail.com>
- Loading branch information
Showing
27 changed files
with
362 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,53 @@ | ||
import type { CollectionId } from "./collection"; | ||
import type { DatabaseId } from "./database"; | ||
import type { UserId } from "./user"; | ||
import type { CardDisplayType } from "./card"; | ||
import type { InitialSyncStatus } from "./database"; | ||
|
||
export const ACTIVITY_MODELS = [ | ||
"table", | ||
"card", | ||
"dataset", | ||
"dashboard", | ||
"collection", | ||
] as const; | ||
export type ActivityModel = typeof ACTIVITY_MODELS[number]; | ||
export type ActivityModelId = number; | ||
|
||
export interface ActivityModelObject { | ||
export interface BaseRecentItem { | ||
id: number; | ||
name: string; | ||
display_name?: string; | ||
moderated_status?: string; | ||
collection_id?: CollectionId | null; | ||
collection_name?: string; | ||
database_name?: string; | ||
db_id?: DatabaseId; | ||
model: ActivityModel; | ||
description?: string | null; | ||
timestamp: string; | ||
} | ||
|
||
export interface RecentItem { | ||
cnt: number; | ||
max_ts: string; | ||
user_id: UserId; | ||
model: ActivityModel; | ||
model_id: ActivityModelId; | ||
model_object: ActivityModelObject; | ||
export interface RecentTableItem extends BaseRecentItem { | ||
model: "table"; | ||
display_name: string; | ||
database: { | ||
id: number; | ||
name: string; | ||
initial_sync_status: InitialSyncStatus; | ||
}; | ||
} | ||
|
||
export interface PopularItem { | ||
model: ActivityModel; | ||
model_id: ActivityModelId; | ||
model_object: ActivityModelObject; | ||
export interface RecentCollectionItem extends BaseRecentItem { | ||
model: "collection" | "dashboard" | "dataset" | "card"; | ||
parent_collection: { | ||
id: number | null; | ||
name: string; | ||
authority_level?: "official" | null; | ||
}; | ||
authority_level?: "official" | null; // for collections | ||
moderated_status?: "verified" | null; // for models | ||
display?: CardDisplayType; // for questions | ||
} | ||
|
||
export type RecentItem = RecentTableItem | RecentCollectionItem; | ||
|
||
export interface RecentItemsResponse { | ||
recent_views: RecentItem[]; | ||
} | ||
|
||
export type PopularItem = RecentItem; | ||
|
||
export interface PopularItemsResponse { | ||
popular_items: PopularItem[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
import type { | ||
ActivityModelObject, | ||
PopularItem, | ||
RecentItem, | ||
RecentTableItem, | ||
RecentCollectionItem, | ||
} from "metabase-types/api"; | ||
|
||
export const createMockModelObject = ( | ||
opts?: Partial<ActivityModelObject>, | ||
): ActivityModelObject => ({ | ||
name: "Orders", | ||
...opts, | ||
}); | ||
|
||
export const createMockRecentItem = ( | ||
opts?: Partial<RecentItem>, | ||
export const createMockRecentTableItem = ( | ||
opts?: Partial<RecentTableItem>, | ||
): RecentItem => ({ | ||
id: 1, | ||
model: "table", | ||
model_id: 1, | ||
model_object: createMockModelObject(), | ||
cnt: 1, | ||
max_ts: "2021-03-01T00:00:00.000Z", | ||
user_id: 1, | ||
name: "my_cool_table", | ||
display_name: "My Cool Table", | ||
timestamp: "2021-03-01T00:00:00.000Z", | ||
database: { | ||
id: 1, | ||
name: "My Cool Collection", | ||
initial_sync_status: "complete", | ||
}, | ||
...opts, | ||
}); | ||
|
||
export const createMockPopularItem = ( | ||
opts?: Partial<PopularItem>, | ||
): PopularItem => ({ | ||
model: "table", | ||
model_id: 1, | ||
model_object: createMockModelObject(), | ||
export const createMockRecentCollectionItem = ( | ||
opts?: Partial<RecentCollectionItem>, | ||
): RecentItem => ({ | ||
id: 1, | ||
model: "card", | ||
name: "My Cool Question", | ||
timestamp: "2021-03-01T00:00:00.000Z", | ||
parent_collection: { | ||
id: 1, | ||
name: "My Cool Collection", | ||
}, | ||
...opts, | ||
}); | ||
|
||
export const createMockPopularTableItem = ( | ||
opts?: Partial<RecentTableItem>, | ||
): PopularItem => createMockRecentTableItem(opts); | ||
|
||
export const createMockPopularCollectionItem = ( | ||
opts?: Partial<RecentCollectionItem>, | ||
): PopularItem => createMockRecentCollectionItem(opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.