mainly automated changes from running run npx @grafana/create-plugin@latest update. The .config/ directory changes are all automated
manual changes include updating node to version 20 in .nvmrc, removing TextEncoderjest-setup.js as it's now included in .config/jest-setup.js, and updating dependencies in package.json
renderHooks now comes from @testing-library/react instead of @testing-library/react-hooks
import '@testing-library/jest-dom'; to fix a typescript error where toBeInTheDocument is not found
src/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.test.tsx I believe there were some changes in the Select component from @grafana/ui v10.x.x to v11.x.x so this just updated the test to account for the change in the structure of the Select options
@reduxjs/toolkit updates
After updating @reduxjs/toolkit there were a lot of type errors with the actions/reducers. Before the update, we manually defined the action types and action creators. Something about the manually created action types was clashing with the updated types so I ended up removing the manually defined action types and action creators and used the createAction help from @reduxjs/toolkit which is a helper for creating an action creator that can also be used in place of the action type. This allowed me to delete the manually created action types and action creators.
Here's an example of the changes to the changeBucketAggregationType action to make it a bit more concrete
Previously
/* src/components/QueryEditor/BucketAggregationsEditor/state/types.ts */
// action creator is manually created and we need to specify the payload it returns and make sure to set the type to `CHANGE_BUCKET_AGG_TYPE`
export const changeBucketAggregationType = (
id: BucketAggregation['id'],
newType: BucketAggregation['type']
): BucketAggregationAction => ({
type: CHANGE_BUCKET_AGG_TYPE,
payload: {
id,
newType,
},
});
/* src/components/QueryEditor/BucketAggregationsEditor/state/types.ts */
// action type `ChangeBucketAggregationTypeAction` defined
export interface ChangeBucketAggregationTypeAction extends Action<typeof CHANGE_BUCKET_AGG_TYPE> {
payload: {
id: BucketAggregation['id'];
newType: BucketAggregation['type'];
};
}
// union type for all bucket aggregation action types
export type BucketAggregationAction<T extends BucketAggregation = BucketAggregation> =
| AddBucketAggregationAction
| RemoveBucketAggregationAction
| ChangeBucketAggregationTypeAction // `ChangeBucketAggregationTypeAction` needs to be included here
| ChangeBucketAggregationFieldAction
| ChangeBucketAggregationSettingAction<T>;
/* src/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts */
// reducer creator needs to include the `BucketAggregationAction` union type in its function signature
(
state: OpenSearchQuery['bucketAggs'],
action: BucketAggregationAction | ChangeMetricTypeAction | InitAction
): OpenSearchQuery['bucketAggs'] => {
// the reducer needs to check the `action.type` that the action creator includes in its payload to make sure it matches `CHANGE_BUCKET_AGG_TYPE` that is set in the action creator
switch (action.type) {
// ... other code excluded
case CHANGE_BUCKET_AGG_TYPE:
After updates
/* src/components/QueryEditor/BucketAggregationsEditor/state/actions.ts */
// `createAction just needs `CHANGE_BUCKET_AGG_TYPE` to identify the action and we just pass the type for the expected payload
export const changeBucketAggregationType = createAction<{
id: BucketAggregation['id'];
newType: BucketAggregation['type'];
}>(CHANGE_BUCKET_AGG_TYPE);
/* src/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts */
// the reducer creator can just use the `Action` type from `@reduxjs/toolkit` in its function signature instead of us needing to create a separate union type of all the bucket aggregation action types
// the reducer can just import the action creator we created above and use the `match` function to check if the action is the type we expect. This acts as a type predicate so we also get properly typed payloads in the reducer.
if (changeBucketAggregationType.match(action)) {
This is the bulk of the changes to the actions/reducers. The logic in the reducers is the exact same as before.
The only other thing to note about the action creators is that they now take a single argument for its payload. E.g.
What this PR does / why we need it: Updating dependencies
Which issue(s) this PR fixes:
Fixes https://github.com/grafana/oss-plugin-partnerships/issues/922 Fixes https://github.com/grafana/oss-plugin-partnerships/issues/923
Special notes for your reviewer:
I've organized the changes into different commits to make it easier to review:
run npx @grafana/create-plugin@latest update
. The.config/
directory changes are all automated.nvmrc
, removingTextEncoder
jest-setup.js
as it's now included in.config/jest-setup.js
, and updating dependencies inpackage.json
go mod tidy
which auto updatedgo
andtoolchain
ingo.mod
ArrayVector
is deprecated and causes an error when it's used, the fix is to replace usages of it with plain arraysrenderHooks
now comes from@testing-library/react
instead of@testing-library/react-hooks
import '@testing-library/jest-dom';
to fix a typescript error wheretoBeInTheDocument
is not foundsrc/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.test.tsx
I believe there were some changes in theSelect
component from@grafana/ui
v10.x.x to v11.x.x so this just updated the test to account for the change in the structure of theSelect
optionsAction
type in favour of using the one from@reduxjs/toolkit
@reduxjs/toolkit updates
for a description of the following changes@reduxjs/toolkit updates After updating
@reduxjs/toolkit
there were a lot of type errors with the actions/reducers. Before the update, we manually defined the action types and action creators. Something about the manually created action types was clashing with the updated types so I ended up removing the manually defined action types and action creators and used thecreateAction
help from@reduxjs/toolkit
which is a helper for creating an action creator that can also be used in place of the action type. This allowed me to delete the manually created action types and action creators.Here's an example of the changes to the
changeBucketAggregationType
action to make it a bit more concretePreviously
After updates
This is the bulk of the changes to the actions/reducers. The logic in the reducers is the exact same as before.
The only other thing to note about the action creators is that they now take a single argument for its payload. E.g.
Previously
After updates