Move generating of group URLs into group.ts
Release-Notes: skip
Google-Bug-Id: b/244279450
Change-Id: If0948fcae14c80edd8a6b5a380ee5b303e48de88
diff --git a/polygerrit-ui/app/models/views/change.ts b/polygerrit-ui/app/models/views/change.ts
index de701f5..ed23457d 100644
--- a/polygerrit-ui/app/models/views/change.ts
+++ b/polygerrit-ui/app/models/views/change.ts
@@ -11,8 +11,7 @@
} from '../../api/rest-api';
import {GerritView} from '../../services/router/router-model';
import {UrlEncodedCommentId} from '../../types/common';
-import {getPatchRangeExpression} from '../../utils/patch-set-util';
-import {encodeURL} from '../../utils/url-util';
+import {encodeURL, getPatchRangeExpression} from '../../utils/url-util';
import {AttemptChoice} from '../checks/checks-util';
import {Model} from '../model';
import {ViewState} from './base';
diff --git a/polygerrit-ui/app/models/views/diff.ts b/polygerrit-ui/app/models/views/diff.ts
index 3831ab9..68f416f 100644
--- a/polygerrit-ui/app/models/views/diff.ts
+++ b/polygerrit-ui/app/models/views/diff.ts
@@ -11,8 +11,7 @@
} from '../../api/rest-api';
import {GerritView} from '../../services/router/router-model';
import {UrlEncodedCommentId} from '../../types/common';
-import {getPatchRangeExpression} from '../../utils/patch-set-util';
-import {encodeURL} from '../../utils/url-util';
+import {encodeURL, getPatchRangeExpression} from '../../utils/url-util';
import {Model} from '../model';
import {ViewState} from './base';
diff --git a/polygerrit-ui/app/models/views/edit.ts b/polygerrit-ui/app/models/views/edit.ts
index 0a2f07a..102a7e0 100644
--- a/polygerrit-ui/app/models/views/edit.ts
+++ b/polygerrit-ui/app/models/views/edit.ts
@@ -10,8 +10,7 @@
RevisionPatchSetNum,
} from '../../api/rest-api';
import {GerritView} from '../../services/router/router-model';
-import {getPatchRangeExpression} from '../../utils/patch-set-util';
-import {encodeURL} from '../../utils/url-util';
+import {encodeURL, getPatchRangeExpression} from '../../utils/url-util';
import {Model} from '../model';
import {ViewState} from './base';
diff --git a/polygerrit-ui/app/models/views/group.ts b/polygerrit-ui/app/models/views/group.ts
index 50a5229..bac8eb5 100644
--- a/polygerrit-ui/app/models/views/group.ts
+++ b/polygerrit-ui/app/models/views/group.ts
@@ -5,6 +5,7 @@
*/
import {GerritView} from '../../services/router/router-model';
import {GroupId} from '../../types/common';
+import {encodeURL, getBaseUrl} from '../../utils/url-util';
import {Model} from '../model';
import {ViewState} from './base';
@@ -15,16 +16,22 @@
export interface GroupViewState extends ViewState {
view: GerritView.GROUP;
+ groupId: GroupId;
detail?: GroupDetailView;
- groupId?: GroupId;
}
-const DEFAULT_STATE: GroupViewState = {
- view: GerritView.GROUP,
-};
+export function createGroupUrl(state: Omit<GroupViewState, 'view'>) {
+ let url = `/admin/groups/${encodeURL(`${state.groupId}`, true)}`;
+ if (state.detail === GroupDetailView.MEMBERS) {
+ url += ',members';
+ } else if (state.detail === GroupDetailView.LOG) {
+ url += ',audit-log';
+ }
+ return getBaseUrl() + url;
+}
-export class GroupViewModel extends Model<GroupViewState> {
+export class GroupViewModel extends Model<GroupViewState | undefined> {
constructor() {
- super(DEFAULT_STATE);
+ super(undefined);
}
}
diff --git a/polygerrit-ui/app/models/views/group_test.ts b/polygerrit-ui/app/models/views/group_test.ts
new file mode 100644
index 0000000..e1fbe66
--- /dev/null
+++ b/polygerrit-ui/app/models/views/group_test.ts
@@ -0,0 +1,38 @@
+/**
+ * @license
+ * Copyright 2022 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+import {assert} from '@open-wc/testing';
+import {GroupId} from '../../api/rest-api';
+import {GerritView} from '../../services/router/router-model';
+import '../../test/common-test-setup';
+import {createGroupUrl, GroupDetailView, GroupViewState} from './group';
+
+suite('group view state tests', () => {
+ test('createGroupUrl() info', () => {
+ const params: GroupViewState = {
+ view: GerritView.GROUP,
+ groupId: '1234' as GroupId,
+ };
+ assert.equal(createGroupUrl(params), '/admin/groups/1234');
+ });
+
+ test('createGroupUrl() members', () => {
+ const params: GroupViewState = {
+ view: GerritView.GROUP,
+ groupId: '1234' as GroupId,
+ detail: 'members' as GroupDetailView,
+ };
+ assert.equal(createGroupUrl(params), '/admin/groups/1234,members');
+ });
+
+ test('createGroupUrl() audit log', () => {
+ const params: GroupViewState = {
+ view: GerritView.GROUP,
+ groupId: '1234' as GroupId,
+ detail: 'log' as GroupDetailView,
+ };
+ assert.equal(createGroupUrl(params), '/admin/groups/1234,audit-log');
+ });
+});