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

Move record page perisistence to wdk-client package #1270

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 43 additions & 3 deletions packages/libs/wdk-client/src/Actions/RecordActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Action =
| RecordLoadingAction
| RecordErrorAction
| SectionVisibilityAction
| UpdateTableStateAction
| SetCollapsedSectionsAction
| AllFieldVisibilityAction
| NavigationVisibilityAction
Expand All @@ -43,6 +44,7 @@ export type RecordReceivedAction = {
record: RecordInstance;
recordClass: RecordClass;
categoryTree: CategoryTreeNode;
defaultExpandedSections?: string[];
};
};

Expand Down Expand Up @@ -209,6 +211,30 @@ export function setCollapsedSections(

//==============================================================================

export const TABLE_STATE_UPDATED = 'record-view/table-state-updated';

export type UpdateTableStateAction = {
type: typeof TABLE_STATE_UPDATED;
payload: {
tableName: string;
tableState: {
searchTerm: string;
selectedRow?: number;
expandedRows: number[];
};
};
};

export const updateTableState = (
tableName: string,
tableState: UpdateTableStateAction['payload']['tableState']
): UpdateTableStateAction => ({
type: TABLE_STATE_UPDATED,
payload: { tableName, tableState },
});

//==============================================================================

export const ALL_FIELD_VISIBILITY = 'record-view/all-field-visibility-changed';

export type AllFieldVisibilityAction = {
Expand Down Expand Up @@ -325,6 +351,12 @@ interface RequestRequestOptionsGetter {
): RecordRequestOptions[];
}

interface DefaultExpandedSectionsGetter {
(recordClass: RecordClass, categoryTree: CategoryTreeNode):
| string[]
| undefined;
}

interface CategoryTreePruner {
(recordClass: RecordClass, categoryTree: CategoryTreeNode): CategoryTreeNode;
}
Expand All @@ -334,14 +366,16 @@ export function loadRecordData(
recordClass: string,
primaryKeyValues: string[],
getRecordRequestOptions: RequestRequestOptionsGetter,
pruneCategoryTree: CategoryTreePruner
pruneCategoryTree: CategoryTreePruner,
getDefaultExpandedSections: DefaultExpandedSectionsGetter
): ActionThunk<LoadRecordAction | UserAction | EmptyAction> {
return function run({ wdkService }) {
return setActiveRecord(
recordClass,
primaryKeyValues,
getRecordRequestOptions,
pruneCategoryTree
pruneCategoryTree,
getDefaultExpandedSections
);
};
}
Expand All @@ -357,7 +391,8 @@ function setActiveRecord(
recordClassUrlSegment: string,
primaryKeyValues: string[],
getRecordRequestOptions: RequestRequestOptionsGetter,
pruneCategoryTree: CategoryTreePruner
pruneCategoryTree: CategoryTreePruner,
getDefaultExpandedSections: DefaultExpandedSectionsGetter
): ActionThunk<LoadRecordAction | UserAction | EmptyAction> {
return ({ wdkService }) => {
const id = uniqueId('recordViewId');
Expand All @@ -381,13 +416,18 @@ function setActiveRecord(
{ name: '__', tree: prunedCategoryTree },
isNotInternalNode
);
const defaultExpandedSections = getDefaultExpandedSections(
recordClass,
categoryTree
);
const initialAction$ = wdkService
.getRecord(recordClass.urlSegment, primaryKey, initialOptions)
.then((record) =>
recordReceived(id, {
record,
recordClass,
categoryTree,
defaultExpandedSections,
})
);
const additionalActions = additionalOptions.map((options) =>
Expand Down
12 changes: 11 additions & 1 deletion packages/libs/wdk-client/src/Controllers/RecordController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
updateNavigationVisibility,
updateSectionVisibility,
requestPartialRecord,
updateTableState,
} from '../Actions/RecordActions';

import {
Expand All @@ -42,6 +43,7 @@ const ActionCreators = {
loadRecordData,
updateSectionVisibility,
updateNavigationQuery,
updateTableState,
updateAllFieldVisibility,
updateNavigationCategoryExpansion,
updateNavigationVisibility,
Expand Down Expand Up @@ -96,6 +98,13 @@ class RecordController extends PageController<Props> {
];
}

getDefaultExpandedSections(
recordClass: RecordClass,
categoryTree: CategoryTreeNode
): string[] | undefined {
return undefined;
}

pruneCategoryTree(
recordClass: RecordClass,
categoryTree: CategoryTreeNode
Expand Down Expand Up @@ -176,7 +185,8 @@ class RecordController extends PageController<Props> {
recordClass,
pkValues,
this.getRecordRequestOptions.bind(this),
this.pruneCategoryTree.bind(this)
this.pruneCategoryTree.bind(this),
this.getDefaultExpandedSections.bind(this)
);
}
}
Expand Down
Loading
Loading