-
Notifications
You must be signed in to change notification settings - Fork 1
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
add sharing step #472
Merged
MiquelAdell
merged 9 commits into
development-project-configurator
from
feature/share-step
Jan 13, 2025
Merged
add sharing step #472
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
330badf
add sharing step
eperedo 85d8b17
Merge branch 'feature/add-indicators' of github.com:EyeSeeTea/dataset…
eperedo 1a1bc02
Align the search input with the data table component
eperedo f9a8c05
use a custom className
eperedo d85d170
Merge pull request #473 from EyeSeeTea/fix/search-space
MiquelAdell 8ee1c9c
Merge branch 'feature/add-indicators' of github.com:EyeSeeTea/dataset…
eperedo 61c7841
Merge branch 'feature/share-step' of github.com:EyeSeeTea/dataset-con…
eperedo 1f048b7
refactor fn to get region code, move permissions to its own file, imp…
eperedo e39eb53
move extract code logic to domain
eperedo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { apiToFuture } from "$/data/api-futures"; | ||
import { metadataCodes } from "$/data/repositories/D2ApiMetadata"; | ||
import { Config, UserGroup } from "$/domain/entities/Config"; | ||
import { Region } from "$/domain/entities/Region"; | ||
import { Future, FutureData } from "$/domain/entities/generic/Future"; | ||
import { ConfigRepository } from "$/domain/repositories/ConfigRepository"; | ||
import { D2Api } from "$/types/d2-api"; | ||
import { extractFirstTwoLetters, extractPrefix } from "$/utils/string"; | ||
|
||
export class ConfigD2Repository implements ConfigRepository { | ||
constructor(private api: D2Api) {} | ||
|
||
get(): FutureData<Config> { | ||
return this.getOrgUnitLevelGroup().flatMap(orgUnitLevel => { | ||
return Future.joinObj({ | ||
regions: this.getRegions(orgUnitLevel), | ||
userGroups: this.getUserGroups(), | ||
}); | ||
}); | ||
} | ||
|
||
private getOrgUnitLevelGroup(): FutureData<number> { | ||
return apiToFuture( | ||
this.api.models.organisationUnitLevels.get({ | ||
fields: { id: true, level: true }, | ||
filter: { name: { eq: metadataCodes.orgUnitLevels.country } }, | ||
}) | ||
).flatMap(d2Response => { | ||
const orgUnitLevel = d2Response.objects[0]; | ||
return orgUnitLevel | ||
? Future.success(orgUnitLevel.level) | ||
: Future.error(new Error("Country level not found")); | ||
}); | ||
} | ||
|
||
private getRegions(level: number): FutureData<Region[]> { | ||
return apiToFuture( | ||
this.api.models.organisationUnits.get({ | ||
fields: { id: true, code: true, name: true }, | ||
filter: { level: { eq: String(level) }, children: { gt: "0" } }, | ||
paging: false, | ||
}) | ||
).map(d2Response => { | ||
return d2Response.objects.map(region => ({ | ||
id: region.id, | ||
name: region.name, | ||
// org. unit code includes the region code in the first two letters before the underscore | ||
code: extractFirstTwoLetters(region.code), | ||
})); | ||
}); | ||
} | ||
|
||
private getUserGroups(): FutureData<UserGroup[]> { | ||
return apiToFuture( | ||
this.api.models.userGroups.get({ | ||
fields: { id: true, name: true }, | ||
paging: false, | ||
}) | ||
).map(d2Response => { | ||
return d2Response.objects.map(d2UserGroup => ({ | ||
id: d2UserGroup.id, | ||
name: d2UserGroup.name, | ||
// user group name includes the region code in the first two letters | ||
code: extractPrefix(d2UserGroup.name), | ||
})); | ||
}); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { NamedCodeRef } from "$/domain/entities/Ref"; | ||
import { Region } from "$/domain/entities/Region"; | ||
|
||
export type UserGroup = NamedCodeRef; | ||
|
||
export type Config = { regions: Region[]; userGroups: UserGroup[] }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Adding methods to some utils file in the root folder is only advisable for extremely generic functions. I don't think that's the case. The abstraction we are looking for is not "extractFirstTwoLetters", but some function that references the processing over the code (similar to the naming you had before).
This function is used in data and domain, right? So if this is something the domain must be aware of, let's move the function there, with another name (possible in Region and/or OrgUnit).