@ssa-ui-kit/templates 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,12 +27,7 @@ export declare const DashboardEventsMock: {
27
27
  avatarUrl: string;
28
28
  }[];
29
29
  newComers: never[];
30
- assessments: {
31
- personId: number;
32
- personName: string;
33
- eventDate: string;
34
- avatarUrl: string;
35
- }[];
30
+ assessments: never[];
36
31
  terminations: never[];
37
32
  };
38
33
  nextWeek: {
@@ -50,12 +45,7 @@ export declare const DashboardEventsMock: {
50
45
  };
51
46
  thisMonth: {
52
47
  trials: never[];
53
- birthdays: {
54
- personId: number;
55
- personName: string;
56
- eventDate: string;
57
- avatarUrl: string;
58
- }[];
48
+ birthdays: never[];
59
49
  anniversaries: {
60
50
  personId: number;
61
51
  personName: string;
@@ -63,12 +53,7 @@ export declare const DashboardEventsMock: {
63
53
  avatarUrl: string;
64
54
  }[];
65
55
  newComers: never[];
66
- assessments: {
67
- personId: number;
68
- personName: string;
69
- eventDate: string;
70
- avatarUrl: string;
71
- }[];
56
+ assessments: never[];
72
57
  terminations: never[];
73
58
  };
74
59
  nextMonth: {
@@ -86,7 +71,12 @@ export declare const DashboardEventsMock: {
86
71
  avatarUrl: string;
87
72
  }[];
88
73
  newComers: never[];
89
- assessments: never[];
74
+ assessments: {
75
+ personId: number;
76
+ personName: string;
77
+ eventDate: string;
78
+ avatarUrl: string;
79
+ }[];
90
80
  terminations: never[];
91
81
  };
92
82
  };
@@ -95,12 +95,8 @@ export type EventItemInfo = {
95
95
  personName: string;
96
96
  avatarUrl: string;
97
97
  };
98
- export type EventInfo = {
99
- anniversaries: Array<EventItemInfo>;
100
- birthdays: Array<EventItemInfo>;
101
- trials: Array<EventItemInfo>;
102
- terminations: Array<EventItemInfo>;
103
- };
98
+ export type EventInfoType = 'anniversaries' | 'birthdays' | 'trials' | 'newComers' | 'terminations' | 'assessments';
99
+ export type EventInfo = Record<EventInfoType, Array<EventItemInfo>>;
104
100
  export type DashboardCharts = {
105
101
  [K in DashboardChartsTypes]: Array<{
106
102
  caption: string;
@@ -1,4 +1,5 @@
1
1
  import * as API from '../types';
2
+ import { Period } from '../components/Events/types';
2
3
  export declare const getTodayBounds: () => {
3
4
  start: Date;
4
5
  end: Date;
@@ -19,120 +20,4 @@ export declare const getNextMonthBounds: () => {
19
20
  start: Date;
20
21
  end: Date;
21
22
  };
22
- export declare const getFilledTemplate: () => {
23
- today: {
24
- birthdays: {
25
- eventDate: string;
26
- personId: number;
27
- personName: string;
28
- avatarUrl: string;
29
- }[];
30
- anniversaries: {
31
- eventDate: string;
32
- personId: number;
33
- personName: string;
34
- avatarUrl: string;
35
- }[];
36
- assessments: {
37
- eventDate: string;
38
- personId: number;
39
- personName: string;
40
- avatarUrl: string;
41
- }[];
42
- newComers: API.EventItemInfo[];
43
- terminations: API.EventItemInfo[];
44
- trials: API.EventItemInfo[];
45
- };
46
- thisWeek: {
47
- birthdays: {
48
- eventDate: string;
49
- personId: number;
50
- personName: string;
51
- avatarUrl: string;
52
- }[];
53
- anniversaries: {
54
- eventDate: string;
55
- personId: number;
56
- personName: string;
57
- avatarUrl: string;
58
- }[];
59
- assessments: {
60
- eventDate: string;
61
- personId: number;
62
- personName: string;
63
- avatarUrl: string;
64
- }[];
65
- newComers: API.EventItemInfo[];
66
- terminations: API.EventItemInfo[];
67
- trials: API.EventItemInfo[];
68
- };
69
- nextWeek: {
70
- birthdays: {
71
- eventDate: string;
72
- personId: number;
73
- personName: string;
74
- avatarUrl: string;
75
- }[];
76
- anniversaries: {
77
- eventDate: string;
78
- personId: number;
79
- personName: string;
80
- avatarUrl: string;
81
- }[];
82
- assessments: {
83
- eventDate: string;
84
- personId: number;
85
- personName: string;
86
- avatarUrl: string;
87
- }[];
88
- newComers: API.EventItemInfo[];
89
- terminations: API.EventItemInfo[];
90
- trials: API.EventItemInfo[];
91
- };
92
- thisMonth: {
93
- birthdays: {
94
- eventDate: string;
95
- personId: number;
96
- personName: string;
97
- avatarUrl: string;
98
- }[];
99
- anniversaries: {
100
- eventDate: string;
101
- personId: number;
102
- personName: string;
103
- avatarUrl: string;
104
- }[];
105
- assessments: {
106
- eventDate: string;
107
- personId: number;
108
- personName: string;
109
- avatarUrl: string;
110
- }[];
111
- newComers: API.EventItemInfo[];
112
- terminations: API.EventItemInfo[];
113
- trials: API.EventItemInfo[];
114
- };
115
- nextMonth: {
116
- birthdays: {
117
- eventDate: string;
118
- personId: number;
119
- personName: string;
120
- avatarUrl: string;
121
- }[];
122
- anniversaries: {
123
- eventDate: string;
124
- personId: number;
125
- personName: string;
126
- avatarUrl: string;
127
- }[];
128
- assessments: {
129
- eventDate: string;
130
- personId: number;
131
- personName: string;
132
- avatarUrl: string;
133
- }[];
134
- newComers: API.EventItemInfo[];
135
- terminations: API.EventItemInfo[];
136
- trials: API.EventItemInfo[];
137
- };
138
- };
23
+ export declare const getFilledTemplate: () => Record<Period, API.EventInfo>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/templates",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -4,6 +4,7 @@ export type Period =
4
4
  | 'nextWeek'
5
5
  | 'thisMonth'
6
6
  | 'nextMonth';
7
+
7
8
  export type EventInfoRowProps = {
8
9
  itemLabel: string;
9
10
  rowCircleColor: string;
@@ -57,29 +57,7 @@ export const DashboardEventsMock = {
57
57
  },
58
58
  ],
59
59
  newComers: [],
60
- assessments: [
61
- {
62
- personId: 1,
63
- personName: 'John Smith',
64
- eventDate: '01-01-2025',
65
- avatarUrl:
66
- 'https://eu.ui-avatars.com/api/?name=John+Smith&size=24&font-size=0.5',
67
- },
68
- {
69
- personId: 2,
70
- personName: 'Jack Brown',
71
- eventDate: '01-01-2025',
72
- avatarUrl:
73
- 'https://eu.ui-avatars.com/api/?name=Jack+Brown&size=24&font-size=0.5',
74
- },
75
- {
76
- personId: 3,
77
- personName: 'Adam Turner',
78
- eventDate: '01-01-2025',
79
- avatarUrl:
80
- 'https://eu.ui-avatars.com/api/?name=Adam+Turner&size=24&font-size=0.5',
81
- },
82
- ],
60
+ assessments: [],
83
61
  terminations: [],
84
62
  },
85
63
  nextWeek: {
@@ -114,30 +92,8 @@ export const DashboardEventsMock = {
114
92
  },
115
93
  thisMonth: {
116
94
  trials: [],
117
- birthdays: [
118
- {
119
- personId: 4,
120
- personName: 'Colin York',
121
- eventDate: '10-01-1978',
122
- avatarUrl:
123
- 'https://eu.ui-avatars.com/api/?name=Colin+York&size=24&font-size=0.5',
124
- },
125
- {
126
- personId: 5,
127
- personName: 'Stephen McCarthy',
128
- eventDate: '11-01-1978',
129
- avatarUrl:
130
- 'https://eu.ui-avatars.com/api/?name=Stephen+McCarthy&size=24&font-size=0.5',
131
- },
132
- ],
95
+ birthdays: [],
133
96
  anniversaries: [
134
- {
135
- personId: 6,
136
- personName: 'Sarah Webb',
137
- eventDate: '09-01-2018',
138
- avatarUrl:
139
- 'https://eu.ui-avatars.com/api/?name=Sarah+Webb&size=24&font-size=0.5',
140
- },
141
97
  {
142
98
  personId: 7,
143
99
  personName: 'Jane Stone',
@@ -147,29 +103,7 @@ export const DashboardEventsMock = {
147
103
  },
148
104
  ],
149
105
  newComers: [],
150
- assessments: [
151
- {
152
- personId: 1,
153
- personName: 'John Smith',
154
- eventDate: '01-01-2025',
155
- avatarUrl:
156
- 'https://eu.ui-avatars.com/api/?name=John+Smith&size=24&font-size=0.5',
157
- },
158
- {
159
- personId: 2,
160
- personName: 'Jack Brown',
161
- eventDate: '01-01-2025',
162
- avatarUrl:
163
- 'https://eu.ui-avatars.com/api/?name=Jack+Brown&size=24&font-size=0.5',
164
- },
165
- {
166
- personId: 3,
167
- personName: 'Adam Turner',
168
- eventDate: '01-01-2025',
169
- avatarUrl:
170
- 'https://eu.ui-avatars.com/api/?name=Adam+Turner&size=24&font-size=0.5',
171
- },
172
- ],
106
+ assessments: [],
173
107
  terminations: [],
174
108
  },
175
109
  nextMonth: {
@@ -226,6 +160,9 @@ export const DashboardEventsMock = {
226
160
  avatarUrl:
227
161
  'https://eu.ui-avatars.com/api/?name=Colin+York&size=24&font-size=0.5',
228
162
  },
163
+ ],
164
+ newComers: [],
165
+ assessments: [
229
166
  {
230
167
  personId: 13,
231
168
  personName: 'David Foster',
@@ -241,8 +178,6 @@ export const DashboardEventsMock = {
241
178
  'https://eu.ui-avatars.com/api/?name=Emily+Clark&size=24&font-size=0.5',
242
179
  },
243
180
  ],
244
- newComers: [],
245
- assessments: [],
246
181
  terminations: [],
247
182
  },
248
183
  };
@@ -9,7 +9,7 @@ export const translationConfig: JSONObject = {
9
9
  dashboard: {
10
10
  indicators: {
11
11
  employees: 'Employees',
12
- fte: 'FTE',
12
+ fte: 'Full Time Employees',
13
13
  utilization: 'Utilization',
14
14
  onBench: 'On Bench',
15
15
  seniorityLevel: 'Seniority Level',
@@ -74,7 +74,7 @@ export const translationConfig: JSONObject = {
74
74
  nextTrialTerminationDates: 'next termination dates',
75
75
  },
76
76
  fte: {
77
- title: 'FTE',
77
+ title: 'Full Time Employees',
78
78
  },
79
79
  headCountByFullCompany: {
80
80
  title: 'Headcount',
@@ -132,12 +132,15 @@ export type EventItemInfo = {
132
132
  avatarUrl: string;
133
133
  };
134
134
 
135
- export type EventInfo = {
136
- anniversaries: Array<EventItemInfo>;
137
- birthdays: Array<EventItemInfo>;
138
- trials: Array<EventItemInfo>;
139
- terminations: Array<EventItemInfo>;
140
- };
135
+ export type EventInfoType =
136
+ | 'anniversaries'
137
+ | 'birthdays'
138
+ | 'trials'
139
+ | 'newComers'
140
+ | 'terminations'
141
+ | 'assessments';
142
+
143
+ export type EventInfo = Record<EventInfoType, Array<EventItemInfo>>;
141
144
 
142
145
  export type DashboardCharts = {
143
146
  [K in DashboardChartsTypes]: Array<{
@@ -1,9 +1,12 @@
1
- import { DateTime } from 'luxon';
1
+ import { DateTime, Interval } from 'luxon';
2
2
  import * as API from '@/peopleops/types';
3
3
  import { DashboardEventsMock as template } from '@peopleops/hooks/dashboard/__mocks__/dashboardEvents';
4
+ import { Period } from '../components/Events/types';
5
+
6
+ const DATE_FORMAT = 'dd-MM-yyyy';
4
7
 
5
8
  const formatDate = (date: Date) =>
6
- DateTime.fromJSDate(date).toFormat('dd-MM-yyyy');
9
+ DateTime.fromJSDate(date).toFormat(DATE_FORMAT);
7
10
 
8
11
  const getRandomDateInRange = (start: Date, end: Date) => {
9
12
  const randomTime =
@@ -12,13 +15,13 @@ const getRandomDateInRange = (start: Date, end: Date) => {
12
15
  };
13
16
 
14
17
  export const getTodayBounds = () => {
15
- const startOfDay = new Date();
16
- startOfDay.setHours(0, 0, 0, 0);
18
+ const startOfToday = new Date();
19
+ startOfToday.setHours(0, 0, 0, 0);
17
20
 
18
21
  const endOfDay = new Date();
19
22
  endOfDay.setHours(23, 59, 59, 999);
20
23
 
21
- return { start: startOfDay, end: endOfDay };
24
+ return { start: startOfToday, end: endOfDay };
22
25
  };
23
26
 
24
27
  export const getCurrentWeekBounds = () => {
@@ -76,11 +79,7 @@ const updateEventDates = (
76
79
  dateRange: { start: Date; end: Date },
77
80
  ) => {
78
81
  const { start, end } = dateRange;
79
-
80
- const dates = events
81
- .map(() => getRandomDateInRange(start, end))
82
- .sort((date1, date2) => date1.getTime() - date2.getTime());
83
-
82
+ const dates = events.map(() => getRandomDateInRange(start, end));
84
83
  const updatedEvents = events.map((event, index) => {
85
84
  return {
86
85
  ...event,
@@ -91,14 +90,28 @@ const updateEventDates = (
91
90
  return updatedEvents;
92
91
  };
93
92
 
94
- // type EventPeriods = keyof typeof template;
95
- // type EventTypes = keyof (typeof template)['today'];
93
+ const sortEvent = (item1: API.EventItemInfo, item2: API.EventItemInfo) => {
94
+ const date1splitted = item1.eventDate.split('-');
95
+ const date2splitted = item2.eventDate.split('-');
96
+ const ms1 = new Date(
97
+ Number(date1splitted[2]),
98
+ Number(date1splitted[1]) - 1,
99
+ Number(date1splitted[0]),
100
+ ).getTime();
101
+ const ms2 = new Date(
102
+ Number(date2splitted[2]),
103
+ Number(date2splitted[1]) - 1,
104
+ Number(date2splitted[0]),
105
+ ).getTime();
106
+ return ms1 - ms2 > 0 ? 1 : ms2 === ms1 ? 0 : -1;
107
+ };
96
108
 
97
109
  export const getFilledTemplate = () => {
98
- // const cache: Record<
99
- // EventPeriods,
100
- // Record<EventTypes, API.EventItemInfo[]>
101
- // > = {} as Record<EventPeriods, Record<EventTypes, API.EventItemInfo[]>>;
110
+ const cache: Array<
111
+ API.EventItemInfo & {
112
+ eventInfoType: API.EventInfoType;
113
+ }
114
+ > = [];
102
115
  const dateRanges: API.DateRanges = {
103
116
  today: getTodayBounds(),
104
117
  thisWeek: getCurrentWeekBounds(),
@@ -107,26 +120,85 @@ export const getFilledTemplate = () => {
107
120
  nextMonth: getNextMonthBounds(),
108
121
  };
109
122
 
123
+ const processCache = (
124
+ items: API.EventItemInfo[],
125
+ eventInfoType: API.EventInfoType,
126
+ ) =>
127
+ items.map((item) => {
128
+ const foundItem = cache.find(
129
+ (cacheItem) =>
130
+ cacheItem.eventInfoType === eventInfoType &&
131
+ cacheItem.personId === item.personId,
132
+ );
133
+ if (foundItem) {
134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
135
+ const { eventInfoType, ...rest } = foundItem;
136
+ return rest;
137
+ } else {
138
+ cache.push({
139
+ eventInfoType,
140
+ ...item,
141
+ });
142
+ return item;
143
+ }
144
+ });
145
+
110
146
  const updateSection = (
111
147
  section: API.DashboardEvent,
112
148
  dateRangeKey: API.DateRangesKeys,
113
149
  ) => {
114
150
  const dateRange = dateRanges[dateRangeKey];
115
- return {
151
+ const newData = {
116
152
  ...section,
117
153
  birthdays: updateEventDates(section.birthdays, dateRange),
118
154
  anniversaries: updateEventDates(section.anniversaries, dateRange),
119
155
  assessments: updateEventDates(section.assessments, dateRange),
120
156
  };
157
+ (Object.keys(newData) as Array<API.EventInfoType>).forEach(
158
+ (eventInfoType) => {
159
+ newData[eventInfoType] = processCache(
160
+ newData[eventInfoType],
161
+ eventInfoType,
162
+ );
163
+ },
164
+ );
165
+ return newData;
121
166
  };
122
167
 
123
- const result = {
124
- today: updateSection(template.today, 'today'),
125
- thisWeek: updateSection(template.thisWeek, 'thisWeek'),
126
- nextWeek: updateSection(template.nextWeek, 'nextWeek'),
127
- thisMonth: updateSection(template.thisMonth, 'thisMonth'),
128
- nextMonth: updateSection(template.nextMonth, 'nextMonth'),
129
- };
168
+ const result: Record<Period, API.EventInfo> = {} as Record<
169
+ Period,
170
+ API.EventInfo
171
+ >;
172
+
173
+ (Object.keys(template) as Array<Period>).forEach((periodType) => {
174
+ result[periodType] = updateSection(template[periodType], periodType);
175
+
176
+ const currentDateRange = dateRanges[periodType];
177
+ const currentInterval = Interval.fromDateTimes(
178
+ DateTime.fromJSDate(currentDateRange.start),
179
+ DateTime.fromJSDate(currentDateRange.end),
180
+ );
181
+ cache
182
+ .filter((item) =>
183
+ currentInterval.contains(
184
+ DateTime.fromFormat(item.eventDate, DATE_FORMAT),
185
+ ),
186
+ )
187
+ .forEach(({ eventInfoType, ...rest }) => {
188
+ if (
189
+ !result[periodType][eventInfoType].find(
190
+ (item) => item.personId === rest.personId,
191
+ )
192
+ ) {
193
+ result[periodType][eventInfoType].push(rest);
194
+ }
195
+ });
196
+ (Object.keys(template[periodType]) as API.EventInfoType[]).map(
197
+ (eventInfoType) => {
198
+ result[periodType][eventInfoType].sort(sortEvent);
199
+ },
200
+ );
201
+ });
130
202
 
131
203
  return result;
132
204
  };