feat: Created assignedToTeamFilter, assignedToTeamsFilter and assignedToUserFilter.
Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BaseFilter, FilterType } from './types';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestFilter } from '../types';
|
||||
import { stringArrayHas } from '../utils';
|
||||
|
||||
export type AssignedToTeamFilter = BaseFilter & {
|
||||
type: FilterType.AssignedToTeam;
|
||||
teamId: string;
|
||||
};
|
||||
|
||||
export function createAssignedToTeamFilter(
|
||||
filter: AssignedToTeamFilter,
|
||||
): PullRequestFilter {
|
||||
return (pullRequest: DashboardPullRequest): boolean => {
|
||||
const reviewerIds = pullRequest.reviewers?.map(reviewer => reviewer.id);
|
||||
|
||||
if (!reviewerIds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stringArrayHas(reviewerIds, filter.teamId, true);
|
||||
};
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BaseFilter, FilterType } from './types';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestFilter } from '../types';
|
||||
import { createAssignedToTeamFilter } from './assignedToTeamFilter';
|
||||
|
||||
export type AssignedToTeamsFilter = BaseFilter &
|
||||
(
|
||||
| {
|
||||
type: FilterType.AssignedToTeams;
|
||||
teamIds: string[];
|
||||
}
|
||||
| {
|
||||
type: FilterType.AssignedToCurrentUsersTeams;
|
||||
teamIds?: string[];
|
||||
}
|
||||
);
|
||||
|
||||
export function createAssignedToTeamsFilter(
|
||||
filter: AssignedToTeamsFilter,
|
||||
): PullRequestFilter {
|
||||
const teamIds = filter.teamIds;
|
||||
|
||||
return (pullRequest: DashboardPullRequest): boolean => {
|
||||
if (!teamIds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return teamIds.some(teamId => {
|
||||
return createAssignedToTeamFilter({
|
||||
type: FilterType.AssignedToTeam,
|
||||
teamId,
|
||||
})(pullRequest);
|
||||
});
|
||||
};
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BaseFilter, FilterType } from './types';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestFilter } from '../types';
|
||||
import { stringArrayHas } from '../utils';
|
||||
|
||||
export type AssignedToUserFilter = BaseFilter &
|
||||
(
|
||||
| {
|
||||
type: FilterType.AssignedToUser;
|
||||
email: string;
|
||||
}
|
||||
| {
|
||||
type: FilterType.AssignedToCurrentUser;
|
||||
email?: string;
|
||||
}
|
||||
);
|
||||
|
||||
export function createAssignedToUserFilter(
|
||||
filter: AssignedToUserFilter,
|
||||
): PullRequestFilter {
|
||||
const email = filter.email;
|
||||
|
||||
return (pullRequest: DashboardPullRequest): boolean => {
|
||||
const uniqueNames = pullRequest.reviewers?.map(
|
||||
reviewer => reviewer.uniqueName,
|
||||
);
|
||||
|
||||
if (!email || !uniqueNames) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stringArrayHas(uniqueNames, email, true);
|
||||
};
|
||||
}
|
||||
@@ -16,27 +16,34 @@
|
||||
|
||||
export enum FilterType {
|
||||
All = 'All',
|
||||
|
||||
// Assigned To
|
||||
AssignedToUser = 'AssignedToUser',
|
||||
CreatedByUser = 'CreatedByUser',
|
||||
AssignedToCurrentUser = 'AssignedToCurrentUser',
|
||||
CreatedByCurrentUser = 'CreatedByCurrentUser',
|
||||
AssignedToTeam = 'AssignedToTeam',
|
||||
CreatedByTeam = 'CreatedByTeam',
|
||||
AssignedToTeams = 'AssignedToTeams',
|
||||
CreatedByTeams = 'CreatedByTeams',
|
||||
AssignedToCurrentUsersTeams = 'AssignedToCurrentUsersTeams',
|
||||
|
||||
// Created By
|
||||
CreatedByUser = 'CreatedByUser',
|
||||
CreatedByCurrentUser = 'CreatedByCurrentUser',
|
||||
CreatedByTeam = 'CreatedByTeam',
|
||||
CreatedByTeams = 'CreatedByTeams',
|
||||
CreatedByCurrentUsersTeams = 'CreatedByCurrentUsersTeams',
|
||||
}
|
||||
|
||||
export const FilterTypes = [
|
||||
FilterType.All,
|
||||
|
||||
FilterType.AssignedToUser,
|
||||
FilterType.CreatedByUser,
|
||||
FilterType.AssignedToCurrentUser,
|
||||
FilterType.CreatedByCurrentUser,
|
||||
FilterType.AssignedToTeam,
|
||||
FilterType.CreatedByTeam,
|
||||
FilterType.AssignedToTeams,
|
||||
FilterType.AssignedToCurrentUsersTeams,
|
||||
|
||||
FilterType.CreatedByUser,
|
||||
FilterType.CreatedByCurrentUser,
|
||||
FilterType.CreatedByTeam,
|
||||
FilterType.CreatedByTeams,
|
||||
FilterType.CreatedByCurrentUsersTeams,
|
||||
] as const;
|
||||
|
||||
Reference in New Issue
Block a user