Skip to content

Commit

Permalink
fix: Account for group deletes when indexing groupType (#18118)
Browse files Browse the repository at this point in the history
* fix: Account for group deletes when indexing groupType

* refactor: Use a groupTypes selector to find existing group types
  • Loading branch information
tomasfarias authored Oct 24, 2023
1 parent fc0ec2c commit 3b34e1f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion frontend/src/models/groupsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const groupsModel = kea<groupsModelType>([
values: [teamLogic, ['currentTeamId'], groupsAccessLogic, ['groupsEnabled', 'groupsAccessStatus']],
}),
loaders(({ values }) => ({
groupTypes: [
groupTypesRaw: [
[] as Array<GroupType>,
{
loadAllGroupTypes: async () => {
Expand All @@ -38,6 +38,20 @@ export const groupsModel = kea<groupsModelType>([
],
})),
selectors({
groupTypes: [
(s) => [s.groupTypesRaw],
(groupTypesRaw) => {
const groupTypes: GroupType[] = new Array(groupTypesRaw.length)

for (const groupType of groupTypesRaw) {
groupTypes[groupType.group_type_index] = groupType
}

return groupTypes
},
],
groupTypesLoading: [(s) => [s.groupTypesRawLoading], (groupTypesRawLoading) => groupTypesRawLoading],

showGroupsOptions: [
(s) => [s.groupsAccessStatus, s.groupsEnabled, s.groupTypes],
(status, enabled, groupTypes) => status !== GroupsAccessStatus.Hidden || (enabled && groupTypes.length > 0),
Expand Down Expand Up @@ -66,6 +80,7 @@ export const groupsModel = kea<groupsModelType>([
(groupTypeIndex: number | null | undefined, deferToUserWording: boolean = false): Noun => {
if (groupTypeIndex != undefined && groupTypes.length > 0 && groupTypes[groupTypeIndex]) {
const groupType = groupTypes[groupTypeIndex]

return {
singular: groupType.name_plural || groupType.group_type,
plural: groupType.name_plural || `${groupType.group_type}(s)`,
Expand Down

0 comments on commit 3b34e1f

Please sign in to comment.