Add check of account creation time to show carousel (#1284)

Co-authored-by: artrejo <ato9000@users.noreply.github.com>
This commit is contained in:
victor-meng 2022-06-01 15:25:56 -07:00 committed by GitHub
parent 46ca952955
commit 7e1343e84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 29 additions and 29 deletions

View File

@ -7,6 +7,11 @@ export interface DatabaseAccount {
type: string; type: string;
kind: string; kind: string;
properties: DatabaseAccountExtendedProperties; properties: DatabaseAccountExtendedProperties;
systemData?: DatabaseAccountSystemData;
}
export interface DatabaseAccountSystemData {
createdAt: string;
} }
export interface DatabaseAccountExtendedProperties { export interface DatabaseAccountExtendedProperties {

View File

@ -34,7 +34,6 @@ export const QuickstartCarousel: React.FC<QuickstartCarouselProps> = ({
<DefaultButton text="Previous" style={{ margin: "16px 8px 16px 0" }} onClick={() => setPage(page - 1)} /> <DefaultButton text="Previous" style={{ margin: "16px 8px 16px 0" }} onClick={() => setPage(page - 1)} />
)} )}
<PrimaryButton <PrimaryButton
id="carouselNextBtn"
style={{ margin: "16px 16px 16px 0" }} style={{ margin: "16px 16px 16px 0" }}
text={page === 3 ? "Finish" : "Next"} text={page === 3 ? "Finish" : "Next"}
onClick={() => { onClick={() => {

View File

@ -56,6 +56,8 @@ interface UserContext {
export type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra"; export type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra";
export type PortalEnv = "localhost" | "blackforest" | "fairfax" | "mooncake" | "prod" | "dev"; export type PortalEnv = "localhost" | "blackforest" | "fairfax" | "mooncake" | "prod" | "dev";
const ONE_WEEK_IN_MS = 604800000;
const features = extractFeatures(); const features = extractFeatures();
const { enableSDKoperations: useSDKOperations } = features; const { enableSDKoperations: useSDKOperations } = features;
@ -71,10 +73,30 @@ const userContext: UserContext = {
collectionCreationDefaults: CollectionCreationDefaults, collectionCreationDefaults: CollectionCreationDefaults,
}; };
function isAccountNewerThanThresholdInMs(createdAt: string, threshold: number) {
let createdAtMs: number = Date.parse(createdAt);
if (isNaN(createdAtMs)) {
createdAtMs = 0;
}
const nowMs: number = Date.now();
const millisecsSinceAccountCreation = nowMs - createdAtMs;
return threshold > millisecsSinceAccountCreation;
}
function updateUserContext(newContext: Partial<UserContext>): void { function updateUserContext(newContext: Partial<UserContext>): void {
if (newContext.databaseAccount) { if (newContext.databaseAccount) {
newContext.apiType = apiType(newContext.databaseAccount); newContext.apiType = apiType(newContext.databaseAccount);
if (!localStorage.getItem(newContext.databaseAccount.id)) {
const isNewAccount = isAccountNewerThanThresholdInMs(
newContext.databaseAccount?.systemData?.createdAt || "",
ONE_WEEK_IN_MS
);
if (
!localStorage.getItem(newContext.databaseAccount.id) &&
(userContext.isTryCosmosDBSubscription || isNewAccount)
) {
useCarousel.getState().setShouldOpen(true); useCarousel.getState().setShouldOpen(true);
localStorage.setItem(newContext.databaseAccount.id, "true"); localStorage.setItem(newContext.databaseAccount.id, "true");
} }

View File

@ -352,6 +352,7 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
hasWriteAccess: inputs.hasWriteAccess ?? true, hasWriteAccess: inputs.hasWriteAccess ?? true,
addCollectionFlight: inputs.addCollectionDefaultFlight || CollectionCreation.DefaultAddCollectionDefaultFlight, addCollectionFlight: inputs.addCollectionDefaultFlight || CollectionCreation.DefaultAddCollectionDefaultFlight,
collectionCreationDefaults: inputs.defaultCollectionThroughput, collectionCreationDefaults: inputs.defaultCollectionThroughput,
isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
}); });
if (inputs.features) { if (inputs.features) {
Object.assign(userContext.features, extractFeatures(new URLSearchParams(inputs.features))); Object.assign(userContext.features, extractFeatures(new URLSearchParams(inputs.features)));

View File

@ -13,10 +13,6 @@ test("Cassandra keyspace and table CRUD", async () => {
await page.waitForSelector("iframe"); await page.waitForSelector("iframe");
const explorer = await waitForExplorer(); const explorer = await waitForExplorer();
// Click through quick start carousel
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
await explorer.click('[data-test="New Table"]'); await explorer.click('[data-test="New Table"]');
await explorer.click('[aria-label="Keyspace id"]'); await explorer.click('[aria-label="Keyspace id"]');
await explorer.fill('[aria-label="Keyspace id"]', keyspaceId); await explorer.fill('[aria-label="Keyspace id"]', keyspaceId);

View File

@ -12,10 +12,6 @@ test("Graph CRUD", async () => {
await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-gremlin-runner"); await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-gremlin-runner");
const explorer = await waitForExplorer(); const explorer = await waitForExplorer();
// Click through quick start carousel
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
// Create new database and graph // Create new database and graph
await explorer.click('[data-test="New Graph"]'); await explorer.click('[data-test="New Graph"]');
await explorer.fill('[aria-label="New database id"]', databaseId); await explorer.fill('[aria-label="New database id"]', databaseId);

View File

@ -12,11 +12,6 @@ test("Mongo CRUD", async () => {
await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-mongo-runner"); await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-mongo-runner");
const explorer = await waitForExplorer(); const explorer = await waitForExplorer();
// Click through quick start carousel
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
// Create new database and collection // Create new database and collection
await explorer.click('[data-test="New Collection"]'); await explorer.click('[data-test="New Collection"]');
await explorer.fill('[aria-label="New database id"]', databaseId); await explorer.fill('[aria-label="New database id"]', databaseId);

View File

@ -12,11 +12,6 @@ test("Mongo CRUD", async () => {
await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-mongo32-runner"); await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-mongo32-runner");
const explorer = await waitForExplorer(); const explorer = await waitForExplorer();
// Click through quick start carousel
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
// Create new database and collection // Create new database and collection
await explorer.click('[data-test="New Collection"]'); await explorer.click('[data-test="New Collection"]');
await explorer.fill('[aria-label="New database id"]', databaseId); await explorer.fill('[aria-label="New database id"]', databaseId);

View File

@ -12,11 +12,6 @@ test("SQL CRUD", async () => {
await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-sql-runner-west-us"); await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-sql-runner-west-us");
const explorer = await waitForExplorer(); const explorer = await waitForExplorer();
// Click through quick start carousel
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
await explorer.click('[data-test="New Container"]'); await explorer.click('[data-test="New Container"]');
await explorer.fill('[aria-label="New database id"]', databaseId); await explorer.fill('[aria-label="New database id"]', databaseId);
await explorer.fill('[aria-label="Container id"]', containerId); await explorer.fill('[aria-label="Container id"]', containerId);

View File

@ -12,10 +12,6 @@ test("Tables CRUD", async () => {
await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-tables-runner"); await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-tables-runner");
const explorer = await waitForExplorer(); const explorer = await waitForExplorer();
// Click through quick start carousel
await explorer.click("#carouselNextBtn");
await explorer.click("#carouselNextBtn");
await page.waitForSelector('text="Querying databases"', { state: "detached" }); await page.waitForSelector('text="Querying databases"', { state: "detached" });
await explorer.click('[data-test="New Table"]'); await explorer.click('[data-test="New Table"]');
await explorer.fill('[aria-label="Table id"]', tableId); await explorer.fill('[aria-label="Table id"]', tableId);