-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
overview_logic.ts
141 lines (134 loc) · 3.32 KB
/
overview_logic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { kea, MakeLogicType } from 'kea';
import { HttpLogic } from '../../../shared/http';
import { handleAPIError } from '../../../shared/flash_messages';
import { IAccount, IOrganization } from '../../types';
import { IFeedActivity } from './recent_activity';
export interface IOverviewServerData {
hasUsers: boolean;
hasOrgSources: boolean;
canCreateContentSources: boolean;
canCreateInvitations: boolean;
isOldAccount: boolean;
sourcesCount: number;
pendingInvitationsCount: number;
accountsCount: number;
personalSourcesCount: number;
activityFeed: IFeedActivity[];
organization: IOrganization;
isFederatedAuth: boolean;
fpAccount: IAccount;
}
export interface IOverviewActions {
setServerData(serverData: IOverviewServerData): IOverviewServerData;
initializeOverview(): void;
}
export interface IOverviewValues extends IOverviewServerData {
dataLoading: boolean;
}
export const OverviewLogic = kea<MakeLogicType<IOverviewValues, IOverviewActions>>({
actions: {
setServerData: (serverData) => serverData,
initializeOverview: () => null,
},
reducers: {
organization: [
{} as IOrganization,
{
setServerData: (_, { organization }) => organization,
},
],
isFederatedAuth: [
true,
{
setServerData: (_, { isFederatedAuth }) => isFederatedAuth,
},
],
fpAccount: [
{} as IAccount,
{
setServerData: (_, { fpAccount }) => fpAccount,
},
],
canCreateInvitations: [
false,
{
setServerData: (_, { canCreateInvitations }) => canCreateInvitations,
},
],
hasUsers: [
false,
{
setServerData: (_, { hasUsers }) => hasUsers,
},
],
hasOrgSources: [
false,
{
setServerData: (_, { hasOrgSources }) => hasOrgSources,
},
],
canCreateContentSources: [
false,
{
setServerData: (_, { canCreateContentSources }) => canCreateContentSources,
},
],
isOldAccount: [
false,
{
setServerData: (_, { isOldAccount }) => isOldAccount,
},
],
sourcesCount: [
0,
{
setServerData: (_, { sourcesCount }) => sourcesCount,
},
],
pendingInvitationsCount: [
0,
{
setServerData: (_, { pendingInvitationsCount }) => pendingInvitationsCount,
},
],
accountsCount: [
0,
{
setServerData: (_, { accountsCount }) => accountsCount,
},
],
personalSourcesCount: [
0,
{
setServerData: (_, { personalSourcesCount }) => personalSourcesCount,
},
],
activityFeed: [
[],
{
setServerData: (_, { activityFeed }) => activityFeed,
},
],
dataLoading: [
true,
{
setServerData: () => false,
},
],
},
listeners: ({ actions }) => ({
initializeOverview: async () => {
try {
const response = await HttpLogic.values.http.get('/api/workplace_search/overview');
actions.setServerData(response);
} catch (e) {
handleAPIError(e);
}
},
}),
});