-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Metabase module controller and service #4072
Conversation
import { getTeamIdAndMetabaseId } from "./getTeamIdAndMetabaseId.js"; | ||
import { createCollection } from "./createCollection.js"; | ||
|
||
const client = createMetabaseClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this line is needed, the client
doesn't appear to be used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth following this kind of pattern in all these places where client is used - see the getClient
pattern in this file:
const $client = getClient(); |
We're also getting an API test failure here in a test suite unrelated to metabase: https://github.com/theopensystemslab/planx-new/blob/47aba73d1eefdf8782b12493264a925e1a58969c/api.planx.uk/modules/send/s3/index.test.ts I think this is because there we are globally mocking axios and not accounting for the new use case we have in metabase/shared/client.ts: |
Thanks @jamdelion, I sought Claude's advice on restricting the mock in this file and tried a few things out but to no avail. It looked like the axios spy in Maybe we can flag at dev call on Thursday? |
Happy to pick this one up and take a look once rebased and the merge conflicts are resolved 👍 |
778b6d4
to
6f251b1
Compare
Cheers @DafyddLlyr I've just resolved those--up for talking things through tomorrow if you've got time then but no rush :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a quick pass through with some initial comments - always happy to catch up and talk through if you'd like.
I'll checkout the branch and see if I can get to the bottom of the issue with tests and point you in the right direction.
In my mind, we're aiming for something like this - does this match your mental model?
sequenceDiagram
participant User
participant Hasura
participant API
participant MetabaseClient
Note over User, Hasura: User Integration
User->>Hasura: Create Team
Hasura->>Hasura: Add record to teams table
Hasura-->>User: Success
Note over Hasura, MetabaseClient: Async action
Hasura->>Hasura: Event: New team created
Hasura->>API: Create collection request
API->>MetabaseClient: Create collection
MetabaseClient-->>API: Success
API->>Hasura: Update Team Table
Hasura-->>API: Success
Once we have an API endpoint that we can call to create a collection for a team, the next step will be to call it automatically when a team is created, and to populate the current production db with the existing collection ids.
api.planx.uk/modules/analytics/metabase/collection/createCollection.ts
Outdated
Show resolved
Hide resolved
api.planx.uk/modules/analytics/metabase/collection/createCollection.ts
Outdated
Show resolved
Hide resolved
api.planx.uk/modules/analytics/metabase/collection/getCollection.ts
Outdated
Show resolved
Hide resolved
Made this back into a draft because I realised that I've just made team slugs the name of the Metabase collections too--will fix that (and look into |
a7c471e
to
e1a5032
Compare
e1a5032
to
f4dea96
Compare
Okay I think we're back up and running (aside from the failing tests 😅). No rush at all for feedback. To respond to @DafyddLlyr's previous point:
Largely yes, asides from the script being triggered by the User - Create Team event (but as mentioned above, this is outside the scope of this PR). Originally, since not all services will have analytics and not all teams will have Metabase collections, I thought the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looking great!
Just looking a bit deeper at tests now to sort out CI. One initial issue is that we don't have the right env vars set up on AWS (again 🤦♂️).
The good news is that I think I worked out the cause of our headaches here. There's been a few PRs like this recently which have update the env file - #4094. I think that these have just pushed a new .env file without first pulling, thus overwriting your new variables. The timing seems to line up. Could you please update the .env
files on S3 again please (pull then push)?
Thanks for the review once again @DafyddLlyr! Sadly things aren't quite working yet🫠 I've done the tidying up tasks, hopefully those are now resolved. I also re-pulled / pushed the vars ( API tests are also failing despite 55d089b. I don't quite understand the issue, since it looks like there aren't explicit error messages, just warnings. I also thought the 'code style' issues should be addressed through pre-commit scripts, but maybe I've misunderstood? |
api.planx.uk/modules/analytics/metabase/collection/getCollection.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of nits to do with comments but overall great work getting this in good shape! 👍 (I assume Daf's request for changes is stale now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great - a few very minor suggestions but no blockers at all! 👏
test("handles missing slug", async () => { | ||
await expect( | ||
createTeamCollection({ | ||
slug: "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also check this with zod using .min(1)
What does this PR do
createCollectionIfDoesNotExist
servicecreateCollection
Metabase API callWhy
This is the second PR that breaks up #3971 (follows #4071)