Skip to content

feat: download insights raw data as csv#11645

Merged
CarinaWolli merged 5 commits intomainfrom
feat-insights-be-able-to-access-raw-data-via-csv-api-endpoint-10747-cal-2347
Oct 16, 2023
Merged

feat: download insights raw data as csv#11645
CarinaWolli merged 5 commits intomainfrom
feat-insights-be-able-to-access-raw-data-via-csv-api-endpoint-10747-cal-2347

Conversation

@alannnc
Copy link
Copy Markdown
Contributor

@alannnc alannnc commented Oct 1, 2023

What does this PR do?

  • Adds button to insights that triggers new api endpoint that return file download of same data used for all the insights graphs.

Fixes #10747

image

Requirement/Documentation

Type of change

  • New feature (non-breaking change which adds functionality)

How should this be tested?

  • Are there environment variables that should be set? No
  • What are the minimal test data to have? using yarn seed-insights from packages/playwright would be useful to have an entire insights setup with bookings/users/event-types ready.
  • What is expected (happy path) to have (input and output)? Download data that was used for the same count for the graphs
  • Any other important info that could help to test that PR

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

@alannnc alannnc linked an issue Oct 1, 2023 that may be closed by this pull request
@linear
Copy link
Copy Markdown

linear Bot commented Oct 1, 2023

CAL-2347 /insights: be able to access raw data via csv api endpoint

same as metabase, it would be great if you can copy the link to the real-time raw data as a csv:

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 1:12pm
api ❌ Failed (Inspect) Oct 12, 2023 1:12pm
cal 🔄 Building (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 1:12pm
cal-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 1:12pm
dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 1:12pm
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 1:12pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
qa ⬜️ Ignored (Inspect) Visit Preview Oct 12, 2023 1:12pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 1, 2023

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link to collect XP and win prizes!

@github-actions github-actions Bot added insights area: insights, analytics Medium priority Created by Linear-GitHub Sync ✨ feature New feature or request ❗️ migrations contains migration files and removed ✨ feature New feature or request Medium priority Created by Linear-GitHub Sync insights area: insights, analytics labels Oct 1, 2023
@zomars zomars added the core area: core, team members only label Oct 1, 2023
"u"."username" AS "username"
FROM "Booking"
LEFT JOIN "EventType" et ON "Booking"."eventTypeId" = et.id
LEFT JOIN users u ON u.id = "Booking"."userId";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed unused membership left join here and added new users to get user->email and username

Comment thread apps/web/pages/api/insights/download.ts Outdated
});

const csvAsString = objectToCsv(csvData);
const downloadAs = `Insights-${dayjs(startDate).format("YYYY-MM-DD")}-${dayjs(endDate).format(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Felt that this name convention was right.

Comment thread apps/web/pages/api/insights/download.ts Outdated
return "";
}
const header = Object.keys(data[0]).join(",") + "\n";
const rows = data.map((obj: any) => Object.values(obj).join(",") + "\n");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

returning props of object as first line for headers.


test.describe.configure({ mode: "parallel" });

const createTeamsAndMembership = async (userIdOne: number, userIdTwo: number) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is another PR that have more test here, reused some logic but only added required test here.

endTime: true,
paid: true,
userEmail: true,
username: true,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should be fine for now for this values.

* @param props
* @returns
*/
static obtainWhereConditional = async (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reusing logic from insights router, to be used later and avoid duplicated code.

* - memberUserId
* - eventTypeId
* - userId
* - teamId
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Important to know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 1, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@deploysentinel
Copy link
Copy Markdown

deploysentinel Bot commented Oct 1, 2023

Current Playwright Test Results Summary

✅ 148 Passing - ⚠️ 2 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 10/12/2023 01:14:53pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: d5be128

Started: 10/12/2023 01:12:00pm UTC

⚠️ Flakes

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should be able to reschedule
Retry 1Initial Attempt
5.28% (17) 17 / 322 runs
failed over last 7 days
94.10% (303) 303 / 322 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/inline.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Inline Iframe Inline Iframe - Configured with Dark Theme
Retry 1Initial Attempt
2.80% (9) 9 / 322 runs
failed over last 7 days
9.94% (32) 32 / 322 runs
flaked over last 7 days

View Detailed Build Results


@PeerRich
Copy link
Copy Markdown
Member

PeerRich commented Oct 2, 2023

getting a real-time URL comes later, right?

@PeerRich PeerRich requested review from a team and zomars October 2, 2023 10:10
Copy link
Copy Markdown
Member

@CarinaWolli CarinaWolli left a comment

Choose a reason for hiding this comment

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

Tested and works, but please address my comments first 🙏

Comment thread packages/features/insights/filters/Download/index.tsx
Comment thread packages/features/insights/filters/Download/index.tsx Outdated
Comment thread apps/web/pages/api/insights/download.ts Outdated
Comment thread apps/web/pages/api/insights/download.ts Outdated
@github-actions github-actions Bot added the 🚨 merge conflict This PR has a merge conflict that has to be addressed label Oct 4, 2023
@alannnc
Copy link
Copy Markdown
Contributor Author

alannnc commented Oct 4, 2023

I'm gonna try the trpc approach while also adding public url link for this PR.

Copy link
Copy Markdown
Member

@CarinaWolli CarinaWolli left a comment

Choose a reason for hiding this comment

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

Looks good, my requested changes are fixed 👍

@CarinaWolli CarinaWolli merged commit fefb6ac into main Oct 16, 2023
@CarinaWolli CarinaWolli deleted the feat-insights-be-able-to-access-raw-data-via-csv-api-endpoint-10747-cal-2347 branch October 16, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only Medium priority Created by Linear-GitHub Sync ❗️ migrations contains migration files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CAL-2347] /insights: be able to access raw data via csv api endpoint

4 participants