-
Notifications
You must be signed in to change notification settings - Fork 9
feat(cat-voices): new datasource of proposal data #3845
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
Open
LynxLynxx
wants to merge
27
commits into
feat/co-proposers-3677
Choose a base branch
from
feat/proposal-viewer-v2
base: feat/co-proposers-3677
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
b32c807
feat: first version of models
LynxLynxx 0e1e3ad
feat: first version of query
LynxLynxx 5c4411a
feat: extract common subqueries
LynxLynxx 0e17eb9
feat: add tests
LynxLynxx b501960
feat: mapping collaborators
LynxLynxx 88df5f8
chore: remove comments
LynxLynxx 08e3c16
Merge branch 'feat/co-proposers-3677' into feat/proposal-viewer-v2
LynxLynxx b20fe6f
chore: add tests
LynxLynxx 703826f
Merge branch 'feat/proposal-viewer-v2' of github.com:input-output-hk/…
LynxLynxx 1438281
chore: update getPreviousOf
LynxLynxx c36f47c
chore: adding test for setting collaborators statuses
LynxLynxx d86fa5e
chore: find actions for proposal id
LynxLynxx bf9aa43
Merge branch 'feat/co-proposers-3677' into feat/proposal-viewer-v2
LynxLynxx e5c31d3
chore: fix spelling
LynxLynxx dbaa150
Merge branch 'feat/proposal-viewer-v2' of github.com:input-output-hk/…
LynxLynxx 121cfb0
Merge branch 'feat/co-proposers-3677' into feat/proposal-viewer-v2
LynxLynxx 78e2330
chore: no setup for actions in raw proposal
LynxLynxx 4ac77c2
Merge branch 'feat/co-proposers-3677' into feat/proposal-viewer-v2
LynxLynxx 6270aab
feat: upate action getter
LynxLynxx 99a180f
merge
LynxLynxx d8c9734
fix: tests
LynxLynxx cc9180c
chore: add unit test for proposals_v2_dao
LynxLynxx e80e0e2
chore: adding test
LynxLynxx 1a6170e
fix: format
LynxLynxx d5a8cdf
Merge branch 'feat/co-proposers-3677' into feat/proposal-viewer-v2
LynxLynxx c7b84c7
chore: refactor review
LynxLynxx b8bd667
chore: clean up todo
LynxLynxx 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 hidden or 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 hidden or 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
73 changes: 73 additions & 0 deletions
73
...ges/internal/catalyst_voices_models/lib/src/proposal/data/proposal_data_collaborator.dart
This file contains hidden or 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,73 @@ | ||
| import 'package:catalyst_voices_models/catalyst_voices_models.dart'; | ||
| import 'package:collection/collection.dart'; | ||
| import 'package:equatable/equatable.dart'; | ||
|
|
||
| class ProposalDataCollaborator extends Equatable { | ||
| final CatalystId id; | ||
| final ProposalsCollaborationStatus status; | ||
|
|
||
| const ProposalDataCollaborator({required this.id, required this.status}); | ||
|
|
||
| /// Creates a collaborator with status derived from the submission action. | ||
| /// | ||
| /// Status mapping: | ||
| /// - `null` action → [ProposalsCollaborationStatus.pending] | ||
| /// - [ProposalSubmissionAction.aFinal] → [ProposalsCollaborationStatus.accepted] | ||
| /// - [ProposalSubmissionAction.draft] when proposal is final → [ProposalsCollaborationStatus.pending] | ||
| /// - [ProposalSubmissionAction.draft] when proposal is draft → [ProposalsCollaborationStatus.accepted] | ||
| /// - [ProposalSubmissionAction.hide] → [ProposalsCollaborationStatus.rejected] | ||
| factory ProposalDataCollaborator.fromAction({ | ||
| required CatalystId id, | ||
| required ProposalSubmissionAction? action, | ||
| required bool isProposalFinal, | ||
| }) { | ||
| final status = switch (action) { | ||
| null => ProposalsCollaborationStatus.pending, | ||
| ProposalSubmissionAction.aFinal => ProposalsCollaborationStatus.accepted, | ||
| // When proposal is final, draft action does not mean it's accepted | ||
| ProposalSubmissionAction.draft when isProposalFinal => ProposalsCollaborationStatus.pending, | ||
| ProposalSubmissionAction.draft => ProposalsCollaborationStatus.accepted, | ||
| ProposalSubmissionAction.hide => ProposalsCollaborationStatus.rejected, | ||
| }; | ||
|
|
||
| return ProposalDataCollaborator(id: id, status: status); | ||
| } | ||
|
|
||
| @override | ||
| List<Object?> get props => [id, status]; | ||
|
|
||
| static List<ProposalDataCollaborator> resolveCollaboratorStatuses({ | ||
| required bool isProposalFinal, | ||
| List<CatalystId> currentCollaborators = const [], | ||
| Map<CatalystId, RawCollaboratorAction> collaboratorsActions = const {}, | ||
| List<CatalystId> prevCollaborators = const [], | ||
| List<CatalystId> prevAuthors = const [], | ||
| }) { | ||
| final currentCollaboratorsStatuses = currentCollaborators.map((id) { | ||
| return ProposalDataCollaborator.fromAction( | ||
| id: id, | ||
| action: collaboratorsActions[id.toSignificant()]?.action, | ||
| isProposalFinal: isProposalFinal, | ||
| ); | ||
| }); | ||
|
|
||
| final missingCollaborators = prevCollaborators.where( | ||
| (prev) => currentCollaborators.none((current) => prev.isSameAs(current)), | ||
| ); | ||
|
|
||
| final missingCollaboratorsStatuses = missingCollaborators.map((id) { | ||
| final didAuthorPrevVersion = prevAuthors.any((author) => author.isSameAs(id)); | ||
| // If they authored the previous version, they left voluntarily. | ||
| // Otherwise, they were removed by someone else. | ||
| final status = didAuthorPrevVersion | ||
| ? ProposalsCollaborationStatus.left | ||
| : ProposalsCollaborationStatus.removed; | ||
| return ProposalDataCollaborator(id: id, status: status); | ||
| }); | ||
|
|
||
| return [ | ||
| ...missingCollaboratorsStatuses, | ||
| ...currentCollaboratorsStatuses, | ||
| ]; | ||
| } | ||
| } |
92 changes: 92 additions & 0 deletions
92
...ices/packages/internal/catalyst_voices_models/lib/src/proposal/data/proposal_data_v2.dart
This file contains hidden or 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,92 @@ | ||
| import 'package:catalyst_voices_models/catalyst_voices_models.dart'; | ||
| import 'package:equatable/equatable.dart'; | ||
|
|
||
| final class ProposalDataV2 extends Equatable { | ||
| final DocumentRef id; | ||
|
|
||
| /// The parsed proposal document with template schema. | ||
| /// | ||
| /// This is `null` when the template couldn't be retrieved. | ||
| /// The UI should show an error message in this case. | ||
| final ProposalOrDocument proposalOrDocument; | ||
| final ProposalSubmissionAction? submissionAction; | ||
| final bool isFavorite; | ||
| final String categoryName; | ||
| final ProposalBriefDataVotes? votes; | ||
| final List<DocumentRef>? versions; | ||
| final List<ProposalDataCollaborator>? collaborators; | ||
|
|
||
| const ProposalDataV2({ | ||
| required this.id, | ||
| required this.proposalOrDocument, | ||
| required this.submissionAction, | ||
| required this.isFavorite, | ||
| required this.categoryName, | ||
| this.votes, | ||
| this.versions, | ||
| this.collaborators, | ||
| }); | ||
|
|
||
| /// Builds a [ProposalDataV2] from raw data. | ||
| /// | ||
| /// [data] - Raw proposal data from database query. | ||
| /// [proposalOrDocument] - Provides extracted data (categoryName, etc.) from proposal. | ||
| /// Works both with and without template loaded. | ||
| factory ProposalDataV2.build({ | ||
| required RawProposal data, | ||
| required ProposalOrDocument proposalOrDocument, | ||
| Vote? draftVote, | ||
| Vote? castedVote, | ||
| Map<CatalystId, RawCollaboratorAction> collaboratorsActions = const {}, | ||
| List<CatalystId> prevCollaborators = const [], | ||
| List<CatalystId> prevAuthors = const [], | ||
| ProposalSubmissionAction? action, | ||
| }) { | ||
| final id = data.proposal.id; | ||
| final isFinal = data.isFinal; | ||
|
|
||
| final versions = data.versionIds.map((ver) => id.copyWith(ver: Optional(ver))).toList(); | ||
|
|
||
| final collaborators = ProposalDataCollaborator.resolveCollaboratorStatuses( | ||
| isProposalFinal: isFinal, | ||
| currentCollaborators: data.proposal.metadata.collaborators ?? [], | ||
| collaboratorsActions: collaboratorsActions, | ||
| prevCollaborators: prevCollaborators, | ||
| prevAuthors: prevAuthors, | ||
| ); | ||
|
|
||
| return ProposalDataV2( | ||
| id: id, | ||
| proposalOrDocument: proposalOrDocument, | ||
| submissionAction: action, | ||
| isFavorite: data.isFavorite, | ||
| categoryName: proposalOrDocument.categoryName ?? '', | ||
| collaborators: collaborators, | ||
| versions: versions, | ||
| votes: isFinal ? ProposalBriefDataVotes(draft: draftVote, casted: castedVote) : null, | ||
| ); | ||
| } | ||
|
|
||
| ProposalPublish? get proposalPublish { | ||
| if (submissionAction == null && id is DraftRef) { | ||
| return ProposalPublish.localDraft; | ||
| } else if (submissionAction == ProposalSubmissionAction.aFinal) { | ||
| return ProposalPublish.submittedProposal; | ||
| } else if (submissionAction == ProposalSubmissionAction.draft) { | ||
| return ProposalPublish.publishedDraft; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @override | ||
| List<Object?> get props => [ | ||
| id, | ||
| proposalOrDocument, | ||
| submissionAction, | ||
| isFavorite, | ||
| categoryName, | ||
| votes, | ||
| versions, | ||
| collaborators, | ||
| ]; | ||
| } |
37 changes: 37 additions & 0 deletions
37
...t_voices/packages/internal/catalyst_voices_models/lib/src/proposal/data/raw_proposal.dart
This file contains hidden or 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,37 @@ | ||
| import 'package:catalyst_voices_models/catalyst_voices_models.dart'; | ||
| import 'package:equatable/equatable.dart'; | ||
|
|
||
| class RawProposal extends Equatable { | ||
| final DocumentData proposal; | ||
| final DocumentData? template; | ||
| final ProposalSubmissionAction? actionType; | ||
| final List<String> versionIds; | ||
| final int commentsCount; | ||
| final bool isFavorite; | ||
| final List<CatalystId> originalAuthors; | ||
|
|
||
| const RawProposal({ | ||
| required this.proposal, | ||
| required this.template, | ||
| this.actionType, | ||
| required this.versionIds, | ||
| required this.commentsCount, | ||
| required this.isFavorite, | ||
| required this.originalAuthors, | ||
| }); | ||
|
|
||
| bool get isFinal => actionType == ProposalSubmissionAction.aFinal; | ||
|
|
||
| int get iteration => versionIds.indexOf(proposal.id.ver!) + 1; | ||
|
|
||
| @override | ||
| List<Object?> get props => [ | ||
| proposal, | ||
| template, | ||
| actionType, | ||
| versionIds, | ||
| commentsCount, | ||
| isFavorite, | ||
| originalAuthors, | ||
| ]; | ||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.