Skip to content

Commit cced154

Browse files
authoredJun 21, 2023
Fixed Prop Issue (buerokratt#245)
1 parent 66165ad commit cced154

File tree

5 files changed

+325
-3
lines changed

5 files changed

+325
-3
lines changed
 

‎GUI/package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎GUI/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"rxjs": "^7.8.1",
5353
"timeago.js": "^4.0.2",
5454
"usehooks-ts": "^2.9.1",
55+
"uuid": "^9.0.0",
5556
"zustand": "^4.3.2"
5657
},
5758
"devDependencies": {
@@ -61,6 +62,7 @@
6162
"@types/react": "^18.0.26",
6263
"@types/react-datepicker": "^4.8.0",
6364
"@types/react-dom": "^18.0.9",
65+
"@types/uuid": "^9.0.2",
6466
"@vitejs/plugin-react": "^3.0.0",
6567
"eslint": "^8.30.0",
6668
"eslint-config-react-app": "^7.0.1",

‎GUI/public/mockServiceWorker.js

+303
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
/* eslint-disable */
2+
/* tslint:disable */
3+
4+
/**
5+
* Mock Service Worker (0.49.3).
6+
* @see https://github.com/mswjs/msw
7+
* - Please do NOT modify this file.
8+
* - Please do NOT serve this file on production.
9+
*/
10+
11+
const INTEGRITY_CHECKSUM = '3d6b9f06410d179a7f7404d4bf4c3c70'
12+
const activeClientIds = new Set()
13+
14+
self.addEventListener('install', function () {
15+
self.skipWaiting()
16+
})
17+
18+
self.addEventListener('activate', function (event) {
19+
event.waitUntil(self.clients.claim())
20+
})
21+
22+
self.addEventListener('message', async function (event) {
23+
const clientId = event.source.id
24+
25+
if (!clientId || !self.clients) {
26+
return
27+
}
28+
29+
const client = await self.clients.get(clientId)
30+
31+
if (!client) {
32+
return
33+
}
34+
35+
const allClients = await self.clients.matchAll({
36+
type: 'window',
37+
})
38+
39+
switch (event.data) {
40+
case 'KEEPALIVE_REQUEST': {
41+
sendToClient(client, {
42+
type: 'KEEPALIVE_RESPONSE',
43+
})
44+
break
45+
}
46+
47+
case 'INTEGRITY_CHECK_REQUEST': {
48+
sendToClient(client, {
49+
type: 'INTEGRITY_CHECK_RESPONSE',
50+
payload: INTEGRITY_CHECKSUM,
51+
})
52+
break
53+
}
54+
55+
case 'MOCK_ACTIVATE': {
56+
activeClientIds.add(clientId)
57+
58+
sendToClient(client, {
59+
type: 'MOCKING_ENABLED',
60+
payload: true,
61+
})
62+
break
63+
}
64+
65+
case 'MOCK_DEACTIVATE': {
66+
activeClientIds.delete(clientId)
67+
break
68+
}
69+
70+
case 'CLIENT_CLOSED': {
71+
activeClientIds.delete(clientId)
72+
73+
const remainingClients = allClients.filter((client) => {
74+
return client.id !== clientId
75+
})
76+
77+
// Unregister itself when there are no more clients
78+
if (remainingClients.length === 0) {
79+
self.registration.unregister()
80+
}
81+
82+
break
83+
}
84+
}
85+
})
86+
87+
self.addEventListener('fetch', function (event) {
88+
const { request } = event
89+
const accept = request.headers.get('accept') || ''
90+
91+
// Bypass server-sent events.
92+
if (accept.includes('text/event-stream')) {
93+
return
94+
}
95+
96+
// Bypass navigation requests.
97+
if (request.mode === 'navigate') {
98+
return
99+
}
100+
101+
// Opening the DevTools triggers the "only-if-cached" request
102+
// that cannot be handled by the worker. Bypass such requests.
103+
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
104+
return
105+
}
106+
107+
// Bypass all requests when there are no active clients.
108+
// Prevents the self-unregistered worked from handling requests
109+
// after it's been deleted (still remains active until the next reload).
110+
if (activeClientIds.size === 0) {
111+
return
112+
}
113+
114+
// Generate unique request ID.
115+
const requestId = Math.random().toString(16).slice(2)
116+
117+
event.respondWith(
118+
handleRequest(event, requestId).catch((error) => {
119+
if (error.name === 'NetworkError') {
120+
console.warn(
121+
'[MSW] Successfully emulated a network error for the "%s %s" request.',
122+
request.method,
123+
request.url,
124+
)
125+
return
126+
}
127+
128+
// At this point, any exception indicates an issue with the original request/response.
129+
console.error(
130+
`\
131+
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
132+
request.method,
133+
request.url,
134+
`${error.name}: ${error.message}`,
135+
)
136+
}),
137+
)
138+
})
139+
140+
async function handleRequest(event, requestId) {
141+
const client = await resolveMainClient(event)
142+
const response = await getResponse(event, client, requestId)
143+
144+
// Send back the response clone for the "response:*" life-cycle events.
145+
// Ensure MSW is active and ready to handle the message, otherwise
146+
// this message will pend indefinitely.
147+
if (client && activeClientIds.has(client.id)) {
148+
;(async function () {
149+
const clonedResponse = response.clone()
150+
sendToClient(client, {
151+
type: 'RESPONSE',
152+
payload: {
153+
requestId,
154+
type: clonedResponse.type,
155+
ok: clonedResponse.ok,
156+
status: clonedResponse.status,
157+
statusText: clonedResponse.statusText,
158+
body:
159+
clonedResponse.body === null ? null : await clonedResponse.text(),
160+
headers: Object.fromEntries(clonedResponse.headers.entries()),
161+
redirected: clonedResponse.redirected,
162+
},
163+
})
164+
})()
165+
}
166+
167+
return response
168+
}
169+
170+
// Resolve the main client for the given event.
171+
// Client that issues a request doesn't necessarily equal the client
172+
// that registered the worker. It's with the latter the worker should
173+
// communicate with during the response resolving phase.
174+
async function resolveMainClient(event) {
175+
const client = await self.clients.get(event.clientId)
176+
177+
if (client?.frameType === 'top-level') {
178+
return client
179+
}
180+
181+
const allClients = await self.clients.matchAll({
182+
type: 'window',
183+
})
184+
185+
return allClients
186+
.filter((client) => {
187+
// Get only those clients that are currently visible.
188+
return client.visibilityState === 'visible'
189+
})
190+
.find((client) => {
191+
// Find the client ID that's recorded in the
192+
// set of clients that have registered the worker.
193+
return activeClientIds.has(client.id)
194+
})
195+
}
196+
197+
async function getResponse(event, client, requestId) {
198+
const { request } = event
199+
const clonedRequest = request.clone()
200+
201+
function passthrough() {
202+
// Clone the request because it might've been already used
203+
// (i.e. its body has been read and sent to the client).
204+
const headers = Object.fromEntries(clonedRequest.headers.entries())
205+
206+
// Remove MSW-specific request headers so the bypassed requests
207+
// comply with the server's CORS preflight check.
208+
// Operate with the headers as an object because request "Headers"
209+
// are immutable.
210+
delete headers['x-msw-bypass']
211+
212+
return fetch(clonedRequest, { headers })
213+
}
214+
215+
// Bypass mocking when the client is not active.
216+
if (!client) {
217+
return passthrough()
218+
}
219+
220+
// Bypass initial page load requests (i.e. static assets).
221+
// The absence of the immediate/parent client in the map of the active clients
222+
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
223+
// and is not ready to handle requests.
224+
if (!activeClientIds.has(client.id)) {
225+
return passthrough()
226+
}
227+
228+
// Bypass requests with the explicit bypass header.
229+
// Such requests can be issued by "ctx.fetch()".
230+
if (request.headers.get('x-msw-bypass') === 'true') {
231+
return passthrough()
232+
}
233+
234+
// Notify the client that a request has been intercepted.
235+
const clientMessage = await sendToClient(client, {
236+
type: 'REQUEST',
237+
payload: {
238+
id: requestId,
239+
url: request.url,
240+
method: request.method,
241+
headers: Object.fromEntries(request.headers.entries()),
242+
cache: request.cache,
243+
mode: request.mode,
244+
credentials: request.credentials,
245+
destination: request.destination,
246+
integrity: request.integrity,
247+
redirect: request.redirect,
248+
referrer: request.referrer,
249+
referrerPolicy: request.referrerPolicy,
250+
body: await request.text(),
251+
bodyUsed: request.bodyUsed,
252+
keepalive: request.keepalive,
253+
},
254+
})
255+
256+
switch (clientMessage.type) {
257+
case 'MOCK_RESPONSE': {
258+
return respondWithMock(clientMessage.data)
259+
}
260+
261+
case 'MOCK_NOT_FOUND': {
262+
return passthrough()
263+
}
264+
265+
case 'NETWORK_ERROR': {
266+
const { name, message } = clientMessage.data
267+
const networkError = new Error(message)
268+
networkError.name = name
269+
270+
// Rejecting a "respondWith" promise emulates a network error.
271+
throw networkError
272+
}
273+
}
274+
275+
return passthrough()
276+
}
277+
278+
function sendToClient(client, message) {
279+
return new Promise((resolve, reject) => {
280+
const channel = new MessageChannel()
281+
282+
channel.port1.onmessage = (event) => {
283+
if (event.data && event.data.error) {
284+
return reject(event.data.error)
285+
}
286+
287+
resolve(event.data)
288+
}
289+
290+
client.postMessage(message, [channel.port2])
291+
})
292+
}
293+
294+
function sleep(timeMs) {
295+
return new Promise((resolve) => {
296+
setTimeout(resolve, timeMs)
297+
})
298+
}
299+
300+
async function respondWithMock(response) {
301+
await sleep(response.delay)
302+
return new Response(response.body, response)
303+
}

‎GUI/src/pages/Chat/ChatActive/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import StartAServiceModal from '../StartAServiceModal';
2121
import ChatTrigger from './ChatTrigger';
2222
import './ChatActive.scss';
2323
import apiDevV2 from 'services/api-dev-v2';
24+
import { v4 as uuidv4 } from 'uuid';
2425

2526
const CSAchatStatuses = [
2627
CHAT_EVENTS.ACCEPTED,
@@ -227,7 +228,7 @@ const ChatActive: FC = () => {
227228
<p>{t('chat.active.newChats')}</p>
228229
</div>
229230
{activeChats?.otherChats?.map(({ name, chats }) => (
230-
<>
231+
<div key={uuidv4()}>
231232
{name && (
232233
<div className="vertical-tabs__sub-group-header">
233234
<p>{name}</p>
@@ -247,7 +248,7 @@ const ChatActive: FC = () => {
247248
<ChatTrigger chat={chat} />
248249
</Tabs.Trigger>
249250
))}
250-
</>
251+
</div>
251252
))}
252253
</Tabs.List>
253254

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This repo will primarily contain:
1717
- Clone [Resql](https://github.com/buerokratt/Resql)
1818
- Navigate to Resql and build the image `docker build -t resql .`
1919
- Clone [Data Mapper](https://github.com/buerokratt/DataMapper)
20-
- Navigate to Data Mapper and build the image docker build -t datamapper-node .
20+
- Navigate to Data Mapper and build the image `docker build -t datamapper-node .`
2121
- Clone [TIM](https://github.com/buerokratt/TIM)
2222
- Go to src -> main -> resources -> application.properties & modify `security.allowlist.jwt` value to `security.allowlist.jwt=ruuter-v1-public,ruuter-v1-private,ruuter-v2-private,ruuter-v2-public,dmapper,resql,tim,tim-postgresql,chat-widget,customer-service,127.0.0.1,::1`
2323
- Go to src -> main -> resources -> application.properties & add `auth.success.redirect.whitelist=http://localhost:8085,http://localhost:8085/auth/callback`

0 commit comments

Comments
 (0)
Please sign in to comment.