Skip to content

Commit

Permalink
Merge "Remove type AccountInput and GroupObjectInput"
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvsrivastava authored and Gerrit Code Review committed Apr 7, 2022
2 parents 5295f1e + 2235ecb commit 7ec6979
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
AccountInfoInput,
GrAccountList,
GroupInfoInput,
GroupObjectInput,
RawAccountInput,
} from '../../shared/gr-account-list/gr-account-list';
import {
Expand All @@ -78,6 +77,7 @@ import {
ReviewInput,
ReviewResult,
ServerInfo,
SuggestedReviewerGroupInfo,
Suggestion,
} from '../../../types/common';
import {GrButton} from '../../shared/gr-button/gr-button';
Expand Down Expand Up @@ -275,7 +275,7 @@ export class GrReplyDialog extends DIPolymerElement {
_attentionCcsCount = 0;

@property({type: Object, observer: '_reviewerPendingConfirmationUpdated'})
_ccPendingConfirmation: GroupObjectInput | null = null;
_ccPendingConfirmation: SuggestedReviewerGroupInfo | null = null;

@property({
type: String,
Expand All @@ -290,7 +290,7 @@ export class GrReplyDialog extends DIPolymerElement {
_uploader?: AccountInfo;

@property({type: Object})
_pendingConfirmationDetails: GroupObjectInput | null = null;
_pendingConfirmationDetails: SuggestedReviewerGroupInfo | null = null;

@property({type: Boolean})
_includeComments = true;
Expand All @@ -299,7 +299,7 @@ export class GrReplyDialog extends DIPolymerElement {
_reviewers: (AccountInfo | GroupInfo)[] = [];

@property({type: Object, observer: '_reviewerPendingConfirmationUpdated'})
_reviewerPendingConfirmation: GroupObjectInput | null = null;
_reviewerPendingConfirmation: SuggestedReviewerGroupInfo | null = null;

@property({type: Boolean, observer: '_handleHeightChanged'})
_previewFormatting = false;
Expand Down Expand Up @@ -409,6 +409,7 @@ export class GrReplyDialog extends DIPolymerElement {
// elements/shared/gr-account-list/gr-account-list.js#addAccountItem
this.$.reviewers.addAccountItem({
account: (e as CustomEvent).detail.reviewer,
count: 1,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,11 +1138,13 @@ suite('gr-reply-dialog tests', () => {
element._ccPendingConfirmation = {
group,
confirm: false,
count: 1,
};
} else {
element._reviewerPendingConfirmation = {
group,
confirm: false,
count: 1,
};
}
flush();
Expand Down Expand Up @@ -1203,11 +1205,13 @@ suite('gr-reply-dialog tests', () => {
element._ccPendingConfirmation = {
group,
confirm: false,
count: 1,
};
} else {
element._reviewerPendingConfirmation = {
group,
confirm: false,
count: 1,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
AccountInfo,
GroupInfo,
EmailAddress,
SuggestedReviewerGroupInfo,
SuggestedReviewerAccountInfo,
} from '../../../types/common';
import {
ReviewerSuggestionsProvider,
Expand All @@ -53,31 +55,23 @@ export interface GrAccountList {
};
}

/**
* For item added with account info
*/
export interface AccountObjectInput {
account: AccountInfo;
}

/**
* For item added with group info
*/
export interface GroupObjectInput {
group: GroupInfo;
confirm: boolean;
}

/** Supported input to be added */
export type RawAccountInput = string | AccountObjectInput | GroupObjectInput;

// type guards for AccountObjectInput and GroupObjectInput
function isAccountObject(x: RawAccountInput): x is AccountObjectInput {
return !!(x as AccountObjectInput).account;
export type RawAccountInput =
| string
| SuggestedReviewerAccountInfo
| SuggestedReviewerGroupInfo;

// type guards for SuggestedReviewerAccountInfo and SuggestedReviewerGroupInfo
function isAccountObject(
x: RawAccountInput
): x is SuggestedReviewerAccountInfo {
return !!(x as SuggestedReviewerAccountInfo).account;
}

function isGroupObjectInput(x: RawAccountInput): x is GroupObjectInput {
return !!(x as GroupObjectInput).group;
function isSuggestedReviewerGroupInfo(
x: RawAccountInput
): x is SuggestedReviewerGroupInfo {
return !!(x as SuggestedReviewerGroupInfo).group;
}

// Internal input type with account info
Expand Down Expand Up @@ -150,7 +144,7 @@ export class GrAccountList extends PolymerElement {
* Needed for template checking since value is initially set to null.
*/
@property({type: Object, notify: true})
pendingConfirmation: GroupObjectInput | null = null;
pendingConfirmation: SuggestedReviewerGroupInfo | null = null;

@property({type: Boolean})
readonly = false;
Expand Down Expand Up @@ -225,7 +219,7 @@ export class GrAccountList extends PolymerElement {
this.removeFromPendingRemoval(account);
this.push('accounts', account);
itemTypeAdded = 'account';
} else if (isGroupObjectInput(item)) {
} else if (isSuggestedReviewerGroupInfo(item)) {
if (item.confirm) {
this.pendingConfirmation = item;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import {
AccountId,
AccountInfo,
EmailAddress,
GroupBaseInfo,
GroupId,
GroupInfo,
GroupName,
SuggestedReviewerAccountInfo,
Suggestion,
} from '../../../types/common';
Expand Down Expand Up @@ -64,11 +65,12 @@ suite('gr-account-list tests', () => {
_account_id: accountId as AccountId,
};
};
const makeGroup: () => GroupInfo = function () {
const makeGroup: () => GroupBaseInfo = function () {
const groupId = `group${++_nextAccountId}`;
return {
id: groupId as GroupId,
_group: true,
name: 'abcd' as GroupName,
};
};

Expand Down Expand Up @@ -116,7 +118,7 @@ suite('gr-account-list tests', () => {

// New accounts are added to end with pendingAdd class.
const newAccount = makeAccount();
handleAdd({account: newAccount});
handleAdd({account: newAccount, count: 1});
flush();
chips = getChips();
assert.equal(chips.length, 3);
Expand Down Expand Up @@ -160,7 +162,7 @@ suite('gr-account-list tests', () => {

// New groups are added to end with pendingAdd and group classes.
const newGroup = makeGroup();
handleAdd({group: newGroup, confirm: false});
handleAdd({group: newGroup, confirm: false, count: 1});
flush();
chips = getChips();
assert.equal(chips.length, 2);
Expand Down Expand Up @@ -301,9 +303,9 @@ suite('gr-account-list tests', () => {
assert.equal(element.additions().length, 0);

const newAccount = makeAccount();
handleAdd({account: newAccount});
handleAdd({account: newAccount, count: 1});
const newGroup = makeGroup();
handleAdd({group: newGroup, confirm: false});
handleAdd({group: newGroup, confirm: false, count: 1});

assert.deepEqual(element.additions(), [
{
Expand All @@ -317,6 +319,7 @@ suite('gr-account-list tests', () => {
id: newGroup.id,
_group: true,
_pendingAdd: true,
name: 'abcd' as GroupName,
},
},
]);
Expand Down Expand Up @@ -346,6 +349,7 @@ suite('gr-account-list tests', () => {
_group: true,
_pendingAdd: true,
confirmed: true,
name: 'abcd' as GroupName,
},
},
]);
Expand All @@ -362,7 +366,7 @@ suite('gr-account-list tests', () => {
test('max-count', () => {
element.maxCount = 1;
const acct = makeAccount();
handleAdd({account: acct});
handleAdd({account: acct, count: 1});
flush();
assert.isTrue(element.$.entry.hasAttribute('hidden'));
});
Expand Down

0 comments on commit 7ec6979

Please sign in to comment.