Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ table-controls: factor out duplicated code via new usePersistentState hook + misc cleanup + add initial documentation (DOCS.md and JSDoc comments) #1355

Merged
merged 102 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
1ec3a55
TODOs for doc sections
mturley Sep 11, 2023
bc97aa7
WIP
mturley Sep 12, 2023
1228b5c
WIP
mturley Sep 13, 2023
b3b725e
WIP - describe features
mturley Sep 13, 2023
6d2f94f
WIP - flesh out all sections through some of Usage
mturley Sep 13, 2023
3b97a63
Typo
mturley Sep 14, 2023
8807585
Clarify expansion state
mturley Sep 14, 2023
a4d6a25
WIP
mturley Sep 14, 2023
60f717b
Add code examples and rearrange some sections
mturley Sep 22, 2023
6097846
Shorten comments in example code to prevent horizontal scroll in rend…
mturley Sep 22, 2023
cc61b43
Remove usage of translation fn from example code
mturley Sep 22, 2023
d04d316
Remove unnecessary getItemValue from server example
mturley Sep 22, 2023
a4e3fe6
Remove selection code and clean up comments
mturley Sep 22, 2023
23aacc6
Remove copypasted irrelevant comment
mturley Sep 25, 2023
7b99064
Skeleton/TODOs for usePersistedState and next steps
mturley Oct 1, 2023
7540d41
More TODOs
mturley Oct 1, 2023
4db8a66
WIP
mturley Oct 1, 2023
a11bcf0
WIP / TODOs
mturley Oct 2, 2023
aebeb75
Upgrade lib-ui, implement usePersistedState with assertions
mturley Oct 2, 2023
ec2d3e5
TODO
mturley Oct 2, 2023
1af3009
Refactor in progress to combine hooks with `persistIn` option
mturley Oct 3, 2023
3314d46
WIP: Refactored useFilterState but not all usages yet
mturley Oct 3, 2023
f3d0a1d
Combine useLocalTableControls and useLocalTableControlsWithUrlParams,…
mturley Oct 3, 2023
f2a0857
Commit missing file
mturley Oct 3, 2023
3846863
Fix useLegacyFilterState (remove unused storagekey)
mturley Oct 3, 2023
9eea548
Resolving errors with useFilterState
mturley Oct 3, 2023
66027fd
TODOs
mturley Oct 3, 2023
2b274e7
Remove stray characters
mturley Oct 3, 2023
1f51547
WIP refactor of useSortState
mturley Oct 3, 2023
9f8cfbd
Move TODOs to notes app
mturley Oct 3, 2023
c83b78d
Remove remaining references to urlparam hooks from docs file
mturley Oct 5, 2023
7022004
WIP refactor of usePaginationState
mturley Oct 6, 2023
eb12fc3
WIP refactor of useExpansionState, fix mismatched type params
mturley Oct 10, 2023
3769dab
WIP refactor of useActiveRowState
mturley Oct 10, 2023
917d977
Explicitly pass type params in higher level hooks to be safe
mturley Oct 10, 2023
e65ec7f
Fix type errors
mturley Oct 10, 2023
a4649bf
Fix missing type params in useLocalTableControls
mturley Oct 10, 2023
6f4c8a4
Fix fallback behavior in usePersistentState
mturley Oct 10, 2023
b32293f
Simplify usage of usePersistentState with explicit type params and no…
mturley Oct 10, 2023
96b48d4
Fix bug with double prefix on local/sessionStorage
mturley Oct 10, 2023
5ec0c0b
Make persistence configurable by feature
mturley Oct 11, 2023
506e960
Update docs
mturley Oct 11, 2023
8fd16c7
Allow default for persistTo
mturley Oct 11, 2023
c9d965e
Remove unnecessary repeated properties in useLocalTableControlState
mturley Oct 11, 2023
54694d6
Deduplicate logic from useLocalTableControlState
mturley Oct 11, 2023
9757de0
Update type comments
mturley Oct 11, 2023
7a27846
More type cleanup
mturley Oct 11, 2023
35961be
Even more type cleanup
mturley Oct 11, 2023
4a9d925
Yet again more type cleanup
mturley Oct 11, 2023
929c9aa
Update lib-ui
mturley Oct 11, 2023
d7da718
Clean up types in pagination state
mturley Oct 11, 2023
1d66543
Add featuresEnabled arg
mturley Oct 11, 2023
4728cbe
Revert "Add featuresEnabled arg"
mturley Oct 11, 2023
b31155e
Add TODOs
mturley Oct 11, 2023
5aa48b0
Improve persistence arg types
mturley Oct 11, 2023
5dfbd1e
Use discriminated unions for required args per feature
mturley Oct 11, 2023
59357d9
Restore accidentally reverted changes to types
mturley Oct 11, 2023
9d6ab85
Enforce both required and disallowed args with discriminated union
mturley Oct 12, 2023
d436f5f
Attempting to improve disallowing irrelevant args, not working out
mturley Oct 12, 2023
61da6ad
Revert "Attempting to improve disallowing irrelevant args, not workin…
mturley Oct 12, 2023
16d8d30
Pass new feature flags to every usage
mturley Oct 12, 2023
b860c6d
Fix type errors
mturley Oct 12, 2023
ed3bd2b
Comments
mturley Oct 13, 2023
e91e904
Ensure features are fully disabled when not marked enabled
mturley Oct 13, 2023
f9732bf
Use explicit type for table controls object
mturley Oct 13, 2023
648f4bb
Attempt to conditionally return stuff from useTableControlProps by en…
mturley Oct 13, 2023
5778efb
Revert "Attempt to conditionally return stuff from useTableControlPro…
mturley Oct 13, 2023
96f9543
Avoid duplicating types in useTableControlProps
mturley Oct 13, 2023
336a88b
Refactor away getClickableTrProps into getTrProps
mturley Oct 13, 2023
a697a29
Fix type errors
mturley Oct 13, 2023
009d995
Use getTrProps everywhere for future-proofing
mturley Oct 13, 2023
7caaedd
Remove unused vars
mturley Oct 13, 2023
2e6b0ec
Cleanup
mturley Oct 13, 2023
97292d3
Renaming for more flexibility in prop helper files
mturley Oct 13, 2023
c996b35
Closure pattern for extracting expansion prop helpers -- maybe follow…
mturley Oct 13, 2023
8ccd3ca
Fix index
mturley Oct 16, 2023
b14cc4e
Consistent naming for external args in useTableControlProps
mturley Oct 16, 2023
2c5ca70
Move all feature-related prop helpers into use[Feature]PropHelpers
mturley Oct 16, 2023
bc09d56
Use DiscriminatedArgs type util
mturley Oct 16, 2023
4c40642
Simplify arg types for getLocal[Feature]DerivedState by shuffling omits
mturley Oct 16, 2023
4f1e063
Forgot a comment
mturley Oct 16, 2023
8e06e46
Remove comment covered by issue
mturley Oct 16, 2023
1132416
Run prettier in table-controls
mturley Oct 16, 2023
862c37b
Attempting to discriminate args for feature prop helpers
mturley Oct 16, 2023
d030a3d
Revert "Attempting to discriminate args for feature prop helpers"
mturley Oct 16, 2023
677b657
Rename files for active-row to active-item
mturley Oct 16, 2023
e30e469
Rename code for active-row to active-item
mturley Oct 16, 2023
f110084
Remove stale comment about no explicit type
mturley Oct 16, 2023
186b741
Add JSDoc comments for main types file
mturley Oct 16, 2023
c7e06cc
Second pass on jsdocs in main types.ts file, add jsdocs for active-it…
mturley Oct 17, 2023
3094ff9
Add jsdocs for higher-level hooks and utils
mturley Oct 17, 2023
c613b04
Comment
mturley Oct 18, 2023
2670427
Revert "Revert "Attempting to discriminate args for feature prop help…
mturley Oct 19, 2023
8c0cd5d
Attempting to use satisfies and NarrowedArgs
mturley Oct 19, 2023
26e89a5
Revert "Attempting to use satisfies and NarrowedArgs"
mturley Oct 19, 2023
1b9b16b
Revert "Revert "Revert "Attempting to discriminate args for feature p…
mturley Oct 19, 2023
063ce73
Add JSDoc comments for expansion and filtering features, update activ…
mturley Oct 19, 2023
d17bcad
JSDocs for pagination feature
mturley Oct 19, 2023
904acc9
JSDocs for sort feature
mturley Oct 19, 2023
9b471a1
JSDocs for legacy filter/pagination/sort hooks
mturley Oct 20, 2023
ce4a806
Proofread DOCS.md (up through 'Features' section) and add kitchen-sin…
mturley Oct 23, 2023
06546cb
Proofread the rest of DOCS.md
mturley Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "^9.0.3",
"@migtools/lib-ui": "^10.0.1",
"@patternfly/patternfly": "^5.0.2",
"@patternfly/react-charts": "^7.1.0",
"@patternfly/react-code-editor": "^5.1.0",
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ export enum LocalStorageKey {
}

// URL param prefixes: should be short, must be unique for each table that uses one
export enum TableURLParamKeyPrefix {
export enum TablePersistenceKeyPrefix {
issues = "i",
dependencies = "d",
issuesAffectedApps = "ia",
issuesAffectedFiles = "if",
issuesRemainingIncidents = "ii",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React from "react";
import { Td } from "@patternfly/react-table";
import { useTableControlProps } from "@app/hooks/table-controls";
import { ITableControls } from "@app/hooks/table-controls";

export interface ITableRowContentWithControlsProps<
TItem,
TColumnKey extends string,
TSortableColumnKey extends TColumnKey
TSortableColumnKey extends TColumnKey,
TFilterCategoryKey extends string = string,
TPersistenceKeyPrefix extends string = string,
> {
expandableVariant?: "single" | "compound" | null;
isSelectable?: boolean;
propHelpers: ReturnType<
typeof useTableControlProps<TItem, TColumnKey, TSortableColumnKey>
isExpansionEnabled?: boolean;
expandableVariant?: "single" | "compound";
isSelectionEnabled?: boolean;
propHelpers: ITableControls<
TItem,
TColumnKey,
TSortableColumnKey,
TFilterCategoryKey,
TPersistenceKeyPrefix
>["propHelpers"];
item: TItem;
rowIndex: number;
Expand All @@ -20,22 +27,23 @@ export interface ITableRowContentWithControlsProps<
export const TableRowContentWithControls = <
TItem,
TColumnKey extends string,
TSortableColumnKey extends TColumnKey
TSortableColumnKey extends TColumnKey,
>({
expandableVariant = null,
isSelectable = false,
propHelpers: { getSingleExpandTdProps, getSelectCheckboxTdProps },
isExpansionEnabled = false,
expandableVariant,
isSelectionEnabled = false,
propHelpers: { getSingleExpandButtonTdProps, getSelectCheckboxTdProps },
item,
rowIndex,
children,
}: React.PropsWithChildren<
ITableRowContentWithControlsProps<TItem, TColumnKey, TSortableColumnKey>
>) => (
<>
{expandableVariant === "single" ? (
<Td {...getSingleExpandTdProps({ item, rowIndex })} />
{isExpansionEnabled && expandableVariant === "single" ? (
<Td {...getSingleExpandButtonTdProps({ item, rowIndex })} />
) : null}
{isSelectable ? (
{isSelectionEnabled ? (
<Td {...getSelectCheckboxTdProps({ item, rowIndex })} />
) : null}
{children}
Expand Down
6 changes: 2 additions & 4 deletions client/src/app/components/answer-table/answer-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ const AnswerTable: React.FC<IAnswerTableProps> = ({
choice: "Answer choice",
weight: "Weight",
},
hasActionsColumn: false,
hasPagination: false,
variant: "compact",
});
const {
currentPageItems,
numRenderedColumns,
propHelpers: { tableProps, getThProps, getTdProps },
propHelpers: { tableProps, getThProps, getTrProps, getTdProps },
} = tableControls;

const getIconByRisk = (risk: string): React.ReactElement => {
Expand Down Expand Up @@ -118,7 +116,7 @@ const AnswerTable: React.FC<IAnswerTableProps> = ({
{currentPageItems?.map((answer, rowIndex) => {
return (
<>
<Tr key={answer.text}>
<Tr key={answer.text} {...getTrProps({ item: answer })}>
<TableRowContentWithControls
{...tableControls}
item={answer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const QuestionsTable: React.FC<{
formulation: "Name",
section: "Section",
},
isExpansionEnabled: true,
expandableVariant: "single",
forceNumRenderedColumns: isAllQuestionsTab ? 3 : 2, // columns+1 for expand control
});
Expand All @@ -54,6 +55,7 @@ const QuestionsTable: React.FC<{
propHelpers: {
tableProps,
getThProps,
getTrProps,
getTdProps,
getExpandedContentTdProps,
},
Expand All @@ -63,7 +65,7 @@ const QuestionsTable: React.FC<{
const { t } = useTranslation();

return (
<Table {...tableProps} aria-label="Questions table" isExpandable>
<Table {...tableProps} aria-label="Questions table">
<Thead>
<Tr>
<TableHeaderContentWithControls {...tableControls}>
Expand Down Expand Up @@ -98,7 +100,7 @@ const QuestionsTable: React.FC<{
)?.name || "";
return (
<>
<Tr key={question.text}>
<Tr key={question.text} {...getTrProps({ item: question })}>
<TableRowContentWithControls
{...tableControls}
item={question}
Expand Down
Loading
Loading