Skip to content

Commit

Permalink
onboard to automated consumer testing
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Sullivan <[email protected]>
  • Loading branch information
wise-king-sullyman committed Feb 2, 2024
1 parent 3cf032f commit 30c21cb
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 17 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: CI

on:
push:
branches:
- main
- "release-*"
pull_request:
branches:
- main
Expand All @@ -30,7 +26,7 @@ jobs:
run: ./scripts/verify_lock.mjs

- name: Install
run: npm clean-install --ignore-scripts
run: npm install --ignore-scripts

- name: Lint sources
run: npm run lint
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@dnd-kit/sortable": "^7.0.2",
"@hookform/resolvers": "^2.9.11",
"@hot-loader/react-dom": "^17.0.2",
"@migtools/lib-ui": "^10.0.1",
"@pf-consumer-testing/lib-ui": "1.0.1",
"@patternfly/patternfly": "^5.0.2",
"@patternfly/react-charts": "^7.1.0",
"@patternfly/react-code-editor": "^5.1.0",
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/hooks/table-controls/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TableProps, TdProps, ThProps, TrProps } from "@patternfly/react-table";
import { ISelectionStateArgs, useSelectionState } from "@migtools/lib-ui";
import { ISelectionStateArgs, useSelectionState } from "@pf-consumer-testing/lib-ui";
import { DisallowCharacters, DiscriminatedArgs } from "@app/utils/type-utils";
import {
IFilterStateArgs,
Expand Down
161 changes: 161 additions & 0 deletions client/src/app/hooks/table-controls/useLocalTableControlState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { useSelectionState } from "@pf-consumer-testing/lib-ui";
import {
getLocalFilterDerivedState,
useFilterState,
useFilterUrlParams,
} from "./filtering";
import {
useSortState,
getLocalSortDerivedState,
useSortUrlParams,
} from "./sorting";
import {
getLocalPaginationDerivedState,
usePaginationState,
usePaginationUrlParams,
} from "./pagination";
import { useExpansionState, useExpansionUrlParams } from "./expansion";
import { useActiveRowState, useActiveRowUrlParams } from "./active-row";
import {
IExtraArgsForURLParamHooks,
IUseLocalTableControlStateArgs,
IUseTableControlPropsArgs,
} from "./types";

export const useLocalTableControlState = <
TItem,
TColumnKey extends string,
TSortableColumnKey extends TColumnKey,
>(
args: IUseLocalTableControlStateArgs<TItem, TColumnKey, TSortableColumnKey>
): IUseTableControlPropsArgs<TItem, TColumnKey, TSortableColumnKey> => {
const {
items,
filterCategories = [],
sortableColumns = [],
getSortValues,
initialSort = null,
hasPagination = true,
initialItemsPerPage = 10,
idProperty,
initialSelected,
isItemSelectable,
} = args;

const filterState = useFilterState(args);
const { filteredItems } = getLocalFilterDerivedState({
items,
filterCategories,
filterState,
});

const selectionState = useSelectionState({
items: filteredItems,
isEqual: (a, b) => a[idProperty] === b[idProperty],
initialSelected,
isItemSelectable,
});

const sortState = useSortState({ sortableColumns, initialSort });
const { sortedItems } = getLocalSortDerivedState({
sortState,
items: filteredItems,
getSortValues,
});

const paginationState = usePaginationState({
initialItemsPerPage,
});
const { currentPageItems } = getLocalPaginationDerivedState({
paginationState,
items: sortedItems,
});

const expansionState = useExpansionState<TColumnKey>();

const activeRowState = useActiveRowState();

return {
...args,
filterState,
expansionState,
selectionState,
sortState,
paginationState,
activeRowState,
totalItemCount: items.length,
currentPageItems: hasPagination ? currentPageItems : sortedItems,
};
};

// TODO refactor useUrlParams so it can be used conditionally (e.g. useStateOrUrlParams) so we don't have to duplicate all this.
// this would mean all use[Feature]UrlParams hooks could be consolidated into use[Feature]State with a boolean option for whether to use URL params.

export const useLocalTableControlUrlParams = <
TItem,
TColumnKey extends string,
TSortableColumnKey extends TColumnKey,
TURLParamKeyPrefix extends string = string,
>(
args: IUseLocalTableControlStateArgs<TItem, TColumnKey, TSortableColumnKey> &
IExtraArgsForURLParamHooks<TURLParamKeyPrefix>
): IUseTableControlPropsArgs<TItem, TColumnKey, TSortableColumnKey> => {
const {
items,
filterCategories = [],
sortableColumns = [],
getSortValues,
initialSort = null,
hasPagination = true,
initialItemsPerPage = 10,
idProperty,
initialSelected,
isItemSelectable,
} = args;

const filterState = useFilterUrlParams(args);
const { filteredItems } = getLocalFilterDerivedState({
items,
filterCategories,
filterState,
});

const selectionState = useSelectionState({
items: filteredItems,
isEqual: (a, b) => a[idProperty] === b[idProperty],
initialSelected,
isItemSelectable,
});

const sortState = useSortUrlParams({ ...args, sortableColumns, initialSort });
const { sortedItems } = getLocalSortDerivedState({
sortState,
items: filteredItems,
getSortValues,
});

const paginationState = usePaginationUrlParams({
...args,
initialItemsPerPage,
});
const { currentPageItems } = getLocalPaginationDerivedState({
paginationState,
items: sortedItems,
});

const expansionState = useExpansionUrlParams<TColumnKey>(args);

const activeRowState = useActiveRowUrlParams(args);

return {
...args,
filterState,
expansionState,
selectionState,
sortState,
paginationState,
activeRowState,
totalItemCount: items.length,
currentPageItems: hasPagination ? currentPageItems : sortedItems,
};
};
2 changes: 1 addition & 1 deletion client/src/app/layout/SidebarApp/SidebarApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { LayoutTheme } from "../LayoutUtils";
import { checkAccess } from "@app/utils/rbac-utils";
import keycloak from "@app/keycloak";

import { useLocalStorage } from "@migtools/lib-ui";
import { useLocalStorage } from "@pf-consumer-testing/lib-ui";
import { LocalStorageKey } from "@app/Constants";
import { FEATURES_ENABLED } from "@app/FeatureFlags";
import { SimpleSelectBasic } from "@app/components/SimpleSelectBasic";
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/controls/tags/tags.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { AxiosError } from "axios";
import { useTranslation } from "react-i18next";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";
import {
Button,
ButtonVariant,
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/dependencies/dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
TableRowContentWithControls,
} from "@app/components/TableControls";
import { useFetchDependencies } from "@app/queries/dependencies";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";
import { DependencyAppsDetailDrawer } from "./dependency-apps-detail-drawer";
import { useSharedAffectedApplicationFilterCategories } from "../issues/helpers";
import { getParsedLabel } from "@app/utils/rules-utils";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@patternfly/react-core";
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";
import { AnalysisAppDependency, AnalysisDependency } from "@app/api/models";
import {
useTableControlState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";

import { ConditionalRender } from "@app/components/ConditionalRender";
import { AppPlaceholder } from "@app/components/AppPlaceholder";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Table, Thead, Tr, Th, Tbody, Td } from "@patternfly/react-table";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";
import { TablePersistenceKeyPrefix } from "@app/Constants";
import { AnalysisFileReport } from "@app/api/models";
import { useFetchIncidents } from "@app/queries/issues";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@patternfly/react-core";
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";
import { AnalysisFileReport, AnalysisIssue } from "@app/api/models";
import {
useTableControlState,
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/issues/issues-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import textStyles from "@patternfly/react-styles/css/utilities/Text/text";
import CubesIcon from "@patternfly/react-icons/dist/esm/icons/cubes-icon";
import { useSelectionState } from "@migtools/lib-ui";
import { useSelectionState } from "@pf-consumer-testing/lib-ui";

import { AppPlaceholder } from "@app/components/AppPlaceholder";
import { OptionWithValue, SimpleSelect } from "@app/components/SimpleSelect";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, { useEffect, useState } from "react";
import { useSelectionState, ISelectionState } from "@migtools/lib-ui";
import {
useSelectionState,
ISelectionState,
} from "@pf-consumer-testing/lib-ui";
import { Application } from "@app/api/models";

interface IApplicationSelectionContext extends ISelectionState<Application> {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"enabledManagers": ["npm"],
"rangeStrategy": "bump",
"includeForks": true,
"packageRules": [
{
"packagePatterns": ["*"],
"excludePackagePatterns": ["@patternfly/*"],
"enabled": false
},
{
"datasources": ["npm"],
"packagePatterns": ["@patternfly/*"],
"excludePackageNames": ["@patternfly/documentation-framework", "@patternfly/patternfly-a11y"],
"groupName": "patternfly",
"followTag": "prerelease"
},
{
"datasources": ["npm"],
"matchPackageNames": ["@patternfly/documentation-framework", "@patternfly/patternfly-a11y"],
"groupName": "patternfly",
"followTag": "latest"
}
]
}

0 comments on commit 30c21cb

Please sign in to comment.