-
Notifications
You must be signed in to change notification settings - Fork 5
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
[api] Add cost surface piece exporter and importer [MRXN23-111] [MRXN23-19] [MRXN23-112] [MRXN23-20] #1503
[api] Add cost surface piece exporter and importer [MRXN23-111] [MRXN23-19] [MRXN23-112] [MRXN23-20] #1503
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
82e65e1
to
f0ae0ec
Compare
a7b1036
to
a7730dc
Compare
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.
@yulia-bel thanks, and apologies for taking so long to review this - I've been mostly down the rabbit hole of trying to make the functionality of this feature to work in practice in a variety of contexts (projects with or without scenarios, with run scenarios, etc.) and as you know this has been a royal headache in its own right because of the moving pieces in related PRs 😬
As it stands, the code itself looks fine, but:
- please rebase it on the latest
develop
and consider what to do with the check that I highlighted inline in my review, as after rebasing we'd be "guaranteed" (except if any bugs, etc) that by the time we clone a project, this would have at least the default cost surface - check the functionality after rebasing - so far I have only been able to get cloning to work with a very specific combination of factors
const costSurfacesIds = costSurfaces.map((costSurface) => costSurface.id); | ||
let costSurfaceData: CostSurfaceDataSelectResult[] = []; | ||
let projectPusMap: Record<string, number> = {}; | ||
if (costSurfacesIds.length > 0) { |
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 wonder if we should just give up in case we don't have any cost surfaces, or even skip this check and go ahead (in which case we'd have an empty fileContent
later on.
In practice, once rebasing this PR on the latest develop
, we should never have projects without any cost surface (at least the default
one must be created for the project to be ready). I don't think we should necessarily check here if a is ready/well formed, because we have these checks in place elsewhere and we should not be able to even clone a project if the project is not fully ready.
On the other hand, if we did not care here (basically avoiding altogether the if (costSurfacesIds.length > 0)
check), we'd have a malformed export that should fail on import (garbage in, garbage out).
But, with the current implementation, more or less we end up with some kind of inconsistent state if costSurfacesIds.length === 0
, so I am not sure. I'd err on avoiding the check altogether, and maybe logging an error. Or making the export fail altogether.
const fileContent: ProjectCostSurfacesContent = { | ||
costSurfaces: costSurfaces.map(({ id, ...costSurface }) => ({ | ||
...costSurface, | ||
data: costSurfaceData | ||
.filter( | ||
(data: CostSurfaceDataSelectResult) => data.cost_surface_id === id, | ||
) | ||
.map(({ cost_surface_id, projects_pu_id, ...data }) => { | ||
const puid = projectPusMap[projects_pu_id]; | ||
return { puid, ...data }; | ||
}), | ||
})), | ||
}; |
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.
just a note on style - my recommendation for these kinds of "augmentations" is to use named functions to make what we're doing via array operations (filter, map, etc.), spreads and so on clearer.
In practice here we're combining a lookup of cost surface costs with the setter part of a lens, using lower-level primitives: which is ok and works, but makes even a tiny snippet of code like this less legible than something like const fileContent: ProjectCostSurfacesContent = addCostDataToCostSurfaces(costSurfaces, costSurfaceCostData)
but no need to do anything here! (and as always, these kinds of style comments can be highly opinable)
a7730dc
to
7b762b5
Compare
f6be445
to
56ea7bd
Compare
e2a944b
to
29e3b93
Compare
Add cost surface piece exporter
Overview
Please write a description. If the PR is hard to understand, provide a quick explanation of the code.
Designs
Link to the related design prototypes (if applicable)
Testing instructions
Please explain how to test the PR: ID of a dataset, steps to reach the feature, etc.
Feature relevant tickets
Link to the related task manager tickets
Checklist before submitting
develop
.deploying to staging/production, please add brief testing instructions
to the deploy checklist (
docs/deployment-checklist.md
)