Skip to content

Commit

Permalink
rerender problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jgespinosa10 committed Sep 26, 2024
1 parent 80dde94 commit 8835970
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/ui",
"version": "0.5.23-beta.18",
"version": "0.5.23-beta.19",
"main": "./src/index.js",
"type": "module",
"exports": {
Expand Down
76 changes: 41 additions & 35 deletions packages/ui/src/DataTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const DataTable = ({
isTableParamsConnected,
noForm,
orderByFirstColumn,
schema: __schema,
schema: _schema,
showEmptyColumnsByDefault,
tableParams: _tableParams,
anyTouched,
Expand Down Expand Up @@ -199,27 +199,6 @@ const DataTable = ({
};
}

props.defaults = useDeepEqualMemo({
pageSize: controlled_pageSize || 25,
order: [], // ["-name", "statusCode"] //an array of camelCase display names with - sign to denote reverse
searchTerm: "",
page: 1,
filters: [
// filters look like this:
// {
// selectedFilter: 'textContains', //camel case
// filterOn: ccDisplayName, //camel case display name
// filterValue: 'thomas',
// }
],
...(props.defaults || {})
});

const _schema = useMemo(() => {
if (isFunction(__schema)) return __schema(props);
else return __schema;
}, [__schema, props]);

const convertedSchema = useMemo(() => convertSchema(_schema), [_schema]);

if (isLocalCall) {
Expand All @@ -229,10 +208,6 @@ const DataTable = ({
_schema
);
}
if (orderByFirstColumn && !props.defaults?.order?.length) {
const r = [getCCDisplayName(convertedSchema.fields[0])];
props.defaults.order = r;
}
} else {
//in user instantiated withTableParams() call
if (!formName || formName === "tgDataTable") {
Expand All @@ -252,10 +227,41 @@ const DataTable = ({
withSelectedEntities
} = props;

if (!syncDisplayOptionsToDb && userSetPageSize) {
props.defaults = props.defaults || {};
props.defaults.pageSize = userSetPageSize;
}
const defaults = useMemo(() => {
const _defaults = {
pageSize: controlled_pageSize || 25,
order: [], // ["-name", "statusCode"] //an array of camelCase display names with - sign to denote reverse
searchTerm: "",
page: 1,
filters: [
// filters look like this:
// {
// selectedFilter: 'textContains', //camel case
// filterOn: ccDisplayName, //camel case display name
// filterValue: 'thomas',
// }
],
...(props.defaults || {})
};
if (isLocalCall && orderByFirstColumn && !_defaults?.order?.length) {
const r = [getCCDisplayName(convertedSchema.fields[0])];
_defaults.order = r;
}

if (!syncDisplayOptionsToDb && userSetPageSize) {
_defaults.pageSize = userSetPageSize;
}

return _defaults;
}, [
controlled_pageSize,
convertedSchema.fields,
isLocalCall,
orderByFirstColumn,
props.defaults,
syncDisplayOptionsToDb,
userSetPageSize
]);

const selectedEntities = withSelectedEntities
? getRecordsFromIdMap(reduxFormSelectedEntityIdMap)
Expand Down Expand Up @@ -295,7 +301,7 @@ const DataTable = ({
const bindThese = makeDataTableHandlers({
setNewParams,
updateSearch,
defaults: props.defaults,
defaults,
onlyOneFilter: props.onlyOneFilter
});

Expand Down Expand Up @@ -323,9 +329,9 @@ const DataTable = ({
_tableParams,
change,
currentParams,
history?.replace,
defaults,
history.replace,
isTableParamsConnected,
props.defaults,
props.onlyOneFilter,
selectedEntities,
urlConnected
Expand Down Expand Up @@ -353,7 +359,7 @@ const DataTable = ({
currentParams,
entities: props.entities, // for local table
urlConnected,
defaults: props.defaults,
defaults,
schema: convertedSchema,
isInfinite,
isLocalCall,
Expand Down Expand Up @@ -550,7 +556,7 @@ const DataTable = ({
]);

const schema = useMemo(() => {
const schema = convertedSchema;
const schema = { ...convertedSchema };
if (isViewable) {
schema.fields = [viewColumn, ...schema.fields];
}
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/DataTable/utils/withTableParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const useTableParams = props => {
entities,
formName = "tgDataTable",
history,
initialValues,
isCodeModel,
isInfinite,
isLocalCall = false,
Expand Down Expand Up @@ -252,6 +253,7 @@ export const useTableParams = props => {
selectedEntities,
..._tableParams,
formName,
initialValues,
isLocalCall,
schema,
currentParams,
Expand All @@ -268,6 +270,7 @@ export const useTableParams = props => {
dispatch,
formName,
history?.replace,
initialValues,
isLocalCall,
onlyOneFilter,
queryParams,
Expand Down

0 comments on commit 8835970

Please sign in to comment.