Skip to content

Commit a70ae15

Browse files
committed
Destruct permissions in dependency array
1 parent 5fc05b1 commit a70ae15

File tree

1 file changed

+26
-9
lines changed
  • x-pack/plugins/cases/public/components/cases_context

1 file changed

+26
-9
lines changed

x-pack/plugins/cases/public/components/cases_context/index.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,23 @@ export const CasesProvider: React.FC<{ value: CasesContextProps; queryClient?: Q
8282
const { appId, appTitle } = useApplication();
8383
const [state, dispatch] = useReducer(casesContextReducer, getInitialCasesContextState());
8484

85-
const value = useMemo(
85+
const value: CasesContextValue = useMemo(
8686
() => ({
8787
appId,
8888
appTitle,
8989
externalReferenceAttachmentTypeRegistry,
9090
persistableStateAttachmentTypeRegistry,
9191
owner,
92-
permissions,
92+
permissions: {
93+
all: permissions.all,
94+
connectors: permissions.connectors,
95+
create: permissions.create,
96+
delete: permissions.delete,
97+
push: permissions.push,
98+
read: permissions.read,
99+
settings: permissions.settings,
100+
update: permissions.update,
101+
},
93102
basePath,
94103
/**
95104
* The empty object at the beginning avoids the mutation
@@ -103,16 +112,24 @@ export const CasesProvider: React.FC<{ value: CasesContextProps; queryClient?: Q
103112
releasePhase,
104113
dispatch,
105114
}),
115+
/**
116+
* We want to trigger a rerender only if the appId, the appTitle, or
117+
* the permissions will change. The registries, the owner, and the rest
118+
* of the values should not change during the lifecycle of the
119+
* cases application.
120+
*/
121+
// eslint-disable-next-line react-hooks/exhaustive-deps
106122
[
107123
appId,
108124
appTitle,
109-
basePath,
110-
externalReferenceAttachmentTypeRegistry,
111-
features,
112-
owner,
113-
permissions,
114-
persistableStateAttachmentTypeRegistry,
115-
releasePhase,
125+
permissions.all,
126+
permissions.connectors,
127+
permissions.create,
128+
permissions.delete,
129+
permissions.push,
130+
permissions.read,
131+
permissions.settings,
132+
permissions.update,
116133
]
117134
);
118135

0 commit comments

Comments
 (0)