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

[Aggregate queries for table views - #1] Introduce aggregateOperationForViewFieldState #9010

Merged
merged 5 commits into from
Dec 10, 2024

Conversation

ijreilly
Copy link
Collaborator

Introducing aggregateOperationForViewFieldState to add a state storing the aggregate operation for each view field

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Introduces a new Recoil state management system for aggregate operations (SUM, COUNT, etc.) in table views, enabling per-field aggregation functionality.

  • Added aggregateOperationForViewFieldState family state in /record-table-footer/states/aggregateOperationForViewFieldState.ts to store field-specific aggregation settings
  • Implemented state synchronization in RecordIndexTableContainerEffect.tsx using useRecoilCallback to efficiently update aggregate operations
  • Modified RecordIndexContainer.tsx to handle aggregate operation changes during view field updates
  • Removed usePortal prop from Dropdown component, suggesting architectural changes in dropdown rendering

5 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings | Greptile

import { createFamilyState } from '@/ui/utilities/state/utils/createFamilyState';

export const aggregateOperationForViewFieldState = createFamilyState<
AGGREGATE_OPERATIONS | null | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider whether undefined is needed in the type union since defaultValue is null

Comment on lines 101 to 103
currentViewWithSavedFiltersAndSorts?.viewFields.forEach((viewField) => {
setViewFieldsAggregateOperations(viewField);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing null check on viewFields before forEach could cause runtime error

Comment on lines +80 to +86
const aggregateOperationForViewField = snapshot
.getLoadable(
aggregateOperationForViewFieldState({
viewFieldId: viewField.id,
}),
)
.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: getLoadable could throw if state is not initialized - wrap in try/catch

Comment on lines +132 to +139
if (aggregateOperationForViewField !== viewField.aggregateOperation) {
set(
aggregateOperationForViewFieldState({
viewFieldId: viewField.id,
}),
viewField.aggregateOperation,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing null check for viewField.aggregateOperation. If undefined, this could set null state unnecessarily.

viewField.aggregateOperation,
);
}
});
},
[columnDefinitions, setTableColumns],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Dependencies array is missing aggregateOperationForViewFieldState, which this callback uses internally.

Comment on lines +124 to +130
const aggregateOperationForViewField = snapshot
.getLoadable(
aggregateOperationForViewFieldState({
viewFieldId: viewField.id,
}),
)
.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: getLoadable() call could throw if state is not initialized. Consider using loadable.state === 'hasValue' check.

Copy link
Contributor

@lucasbordeau lucasbordeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge main for the fixes on dropdown

@@ -68,5 +74,37 @@ export const RecordIndexTableContainerEffect = () => {
);
}, [setRecordCountInCurrentView, setOnEntityCountChange]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setAggregateOperationForViewField ? Why using plural ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it is setting the aggregate operation for every view fields we have

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only sets one view field operation for the view field passed in parameters, that naming would be adequate if the function would indeed contain a loop.

currentViewWithSavedFiltersAndSorts?.viewFields,
setViewFieldsAggregateOperations,
]);

Copy link
Contributor

@lucasbordeau lucasbordeau Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

currentViewWithSavedFiltersAndSorts?.viewFields.forEach(
      setViewFieldAggregateOperation,
    );

Works in that case, why not ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can see why having the naming in singular fits with the fact that we apply a single operation on each item, it's coherent if we read it : For each view field, set aggregate operation

@ijreilly ijreilly enabled auto-merge (squash) December 10, 2024 17:14
@ijreilly ijreilly merged commit 8ecf07f into main Dec 10, 2024
19 checks passed
@ijreilly ijreilly deleted the add-agregate-queries-table-view branch December 10, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants