refactor: Moved around filter types.

Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
Marley Powell
2021-12-02 13:34:14 +00:00
parent 50b3d1737d
commit 2a02690b11
10 changed files with 127 additions and 22 deletions
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { BaseFilter, FilterType } from './types';
import { BaseFilter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { PullRequestFilter } from '../types';
import { stringArrayHas } from '../utils';
export type AssignedToTeamFilter = BaseFilter & {
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { BaseFilter, FilterType } from './types';
import { BaseFilter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { PullRequestFilter } from '../types';
import { createAssignedToTeamFilter } from './assignedToTeamFilter';
export type AssignedToTeamsFilter = BaseFilter &
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { BaseFilter, FilterType } from './types';
import { BaseFilter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { PullRequestFilter } from '../types';
import { stringArrayHas } from '../utils';
export type AssignedToUserFilter = BaseFilter &
@@ -0,0 +1,71 @@
/*
* 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 { Filter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { createAllFilter } from './allFilter';
import { createAssignedToTeamFilter } from './assignedToTeamFilter';
import { createAssignedToTeamsFilter } from './assignedToTeamsFilter';
import { createAssignedToUserFilter } from './assignedToUserFilter';
import { createCreatedByTeamFilter } from './createdByTeamFilter';
import { createCreatedByTeamsFilter } from './createdByTeamsFilter';
import { createCreatedByUserFilter } from './createdByUserFilter';
export function createFilter(filters: Filter | Filter[]): PullRequestFilter {
const mapFilter = (filter: Filter): PullRequestFilter => {
switch (filter.type) {
case FilterType.AssignedToUser:
case FilterType.AssignedToCurrentUser:
return createAssignedToUserFilter(filter);
case FilterType.CreatedByUser:
case FilterType.CreatedByCurrentUser:
return createCreatedByUserFilter(filter);
case FilterType.AssignedToTeam:
return createAssignedToTeamFilter(filter);
case FilterType.CreatedByTeam:
return createCreatedByTeamFilter(filter);
case FilterType.AssignedToTeams:
case FilterType.AssignedToCurrentUsersTeams:
return createAssignedToTeamsFilter(filter);
case FilterType.CreatedByTeams:
case FilterType.CreatedByCurrentUsersTeams:
return createCreatedByTeamsFilter(filter);
case FilterType.All:
return createAllFilter();
default:
return _ => false;
}
};
if (Array.isArray(filters)) {
if (filters.length === 1) {
return mapFilter(filters[0]);
}
return (pullRequest: DashboardPullRequest): boolean =>
filters.every(filter => mapFilter(filter)(pullRequest));
}
return mapFilter(filters);
}
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { BaseFilter, FilterType } from './types';
import { BaseFilter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { PullRequestFilter } from '../types';
import { stringArrayHas } from '../utils';
export type CreatedByTeamFilter = BaseFilter &
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { BaseFilter, FilterType } from './types';
import { BaseFilter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { PullRequestFilter } from '../types';
import { createCreatedByTeamFilter } from './createdByTeamFilter';
export type CreatedByTeamsFilter = BaseFilter &
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { BaseFilter, FilterType } from './types';
import { BaseFilter, FilterType, PullRequestFilter } from './types';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
import { PullRequestFilter } from '../types';
import { equalsIgnoreCase } from '../utils';
export type CreatedByUserFilter = BaseFilter &
@@ -0,0 +1,19 @@
/*
* 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.
*/
export { createFilter } from './createFilter';
export { FilterTypes } from './types';
export type { Filter, PullRequestFilter, FilterType } from './types';
@@ -14,6 +14,15 @@
* limitations under the License.
*/
import { AllFilter } from './allFilter';
import { AssignedToTeamFilter } from './assignedToTeamFilter';
import { AssignedToTeamsFilter } from './assignedToTeamsFilter';
import { AssignedToUserFilter } from './assignedToUserFilter';
import { CreatedByTeamFilter } from './createdByTeamFilter';
import { CreatedByTeamsFilter } from './createdByTeamsFilter';
import { CreatedByUserFilter } from './createdByUserFilter';
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
export enum FilterType {
All = 'All',
@@ -51,3 +60,14 @@ export const FilterTypes = [
export type BaseFilter = {
type: FilterType;
};
export type Filter =
| AssignedToUserFilter
| CreatedByUserFilter
| AssignedToTeamFilter
| CreatedByTeamFilter
| AssignedToTeamsFilter
| CreatedByTeamsFilter
| AllFilter;
export type PullRequestFilter = (pullRequest: DashboardPullRequest) => boolean;
@@ -14,23 +14,24 @@
* limitations under the License.
*/
import {
DashboardPullRequest,
Team,
} from '@backstage/plugin-azure-devops-common';
import { Filter, PullRequestFilter } from './filters';
export interface PullRequestGroup {
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
export interface PullRequestColumnConfig {
title: string;
pullRequests: DashboardPullRequest[];
filters: Filter[];
simplified?: boolean;
}
export type PullRequestFilter = (pullRequest: DashboardPullRequest) => boolean;
export type TeamFilter = (team: Team) => boolean;
export interface PullRequestGroupConfig {
title: string;
filter: PullRequestFilter;
simplified?: boolean;
}
export interface PullRequestGroup {
title: string;
pullRequests: DashboardPullRequest[];
simplified?: boolean;
}