@shellui/core 0.3.0 → 0.4.0
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.
- package/package.json +2 -2
- package/src/app.tsx +31 -3
- package/src/components/ui/dialog.tsx +26 -6
- package/src/components/ui/sonner.tsx +9 -5
- package/src/features/admin/AdminView.tsx +5 -49
- package/src/features/admin/config.ts +15 -0
- package/src/features/admin/index.ts +4 -0
- package/src/features/admin/routes.tsx +14 -0
- package/src/features/admin/utils.ts +79 -0
- package/src/features/auth/AuthProvider.tsx +68 -13
- package/src/features/auth/backends/shellui.ts +8 -1
- package/src/features/auth/components/AccessPendingView.tsx +112 -0
- package/src/features/auth/components/LoginButton.tsx +5 -10
- package/src/features/auth/components/LoginView.tsx +20 -2
- package/src/features/auth/components/OAuthCallbackView.tsx +211 -50
- package/src/features/auth/hooks/useAuth.tsx +8 -1
- package/src/features/auth/utils/authRequestError.spec.ts +52 -0
- package/src/features/auth/utils/authRequestError.ts +45 -0
- package/src/features/auth/utils/buildAuthUrlWithNext.spec.ts +18 -0
- package/src/features/auth/utils/buildAuthUrlWithNext.ts +12 -0
- package/src/features/auth/utils/index.ts +8 -0
- package/src/features/auth/utils/isTokenAutoRefreshDisabled.spec.ts +71 -0
- package/src/features/auth/utils/isTokenAutoRefreshDisabled.ts +18 -0
- package/src/features/config/ConfigProvider.ts +1 -1
- package/src/features/config/types.ts +46 -5
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +17 -28
- package/src/features/layouts/resolveSdkNavigatePath.spec.ts +55 -0
- package/src/features/layouts/resolveSdkNavigatePath.ts +68 -0
- package/src/features/settings/SettingsIcons.tsx +35 -0
- package/src/features/settings/SettingsProvider.tsx +79 -10
- package/src/features/settings/SettingsRoutes.tsx +14 -6
- package/src/features/settings/SettingsView.tsx +11 -5
- package/src/features/settings/components/Advanced.tsx +117 -44
- package/src/features/settings/components/Develop.tsx +38 -0
- package/src/features/settings/components/ServiceWorker.tsx +52 -25
- package/src/features/settings/components/Storage.tsx +138 -0
- package/src/features/settings/components/UpdateApp.tsx +1 -1
- package/src/features/settings/components/develop/StoragePickerTestButtons.tsx +148 -0
- package/src/features/settings/components/develop/UploadToastTestButton.tsx +29 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +55 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +34 -0
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +1 -1
- package/src/features/settings/utils/toSettingsUser.spec.ts +4 -0
- package/src/features/settings/utils/toSettingsUser.ts +2 -0
- package/src/features/sonner/SonnerContext.tsx +44 -60
- package/src/features/storage/StorageBridge.tsx +50 -0
- package/src/features/storage/StoragePickerContext.tsx +214 -0
- package/src/features/storage/api.spec.ts +303 -0
- package/src/features/storage/api.ts +414 -0
- package/src/features/storage/handleRequest.spec.ts +88 -0
- package/src/features/storage/handleRequest.ts +53 -0
- package/src/features/storage/quota.spec.ts +151 -0
- package/src/features/storage/quota.ts +104 -0
- package/src/features/storage/uploads/UploadToastCard.tsx +442 -0
- package/src/features/storage/uploads/UploadToaster.tsx +41 -0
- package/src/features/storage/uploads/handleTrackedUpload.spec.ts +170 -0
- package/src/features/storage/uploads/handleTrackedUpload.ts +97 -0
- package/src/features/storage/uploads/types.ts +24 -0
- package/src/features/storage/uploads/uploadQueue.spec.ts +118 -0
- package/src/features/storage/uploads/uploadQueue.ts +349 -0
- package/src/features/storage/uploads/useUploadQueue.ts +30 -0
- package/src/i18n/translations/en/common.json +33 -0
- package/src/i18n/translations/en/settings.json +56 -4
- package/src/i18n/translations/fr/common.json +33 -0
- package/src/i18n/translations/fr/settings.json +56 -4
- package/src/index.css +2 -1
- package/src/index.ts +2 -0
- package/src/lib/z-index.ts +9 -3
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
- package/src/routes/routes.tsx +2 -13
- package/src/service-worker/register.ts +217 -101
- package/src/service-worker/sw-dev.ts +5 -1
- package/src/service-worker/sw.ts +5 -1
- package/src/shellui-target.d.ts +2 -0
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
getServiceWorkerStatus,
|
|
9
9
|
addStatusListener,
|
|
10
10
|
serviceWorkerFileExists,
|
|
11
|
+
showUpdateAvailableToastForTesting,
|
|
12
|
+
clearAppCaches,
|
|
13
|
+
reloadApp,
|
|
11
14
|
} from '../../../service-worker/register';
|
|
12
15
|
import { shellui } from '@shellui/sdk';
|
|
13
16
|
import { useState, useEffect } from 'react';
|
|
@@ -20,7 +23,7 @@ export const ServiceWorker = () => {
|
|
|
20
23
|
const [isLoading, setIsLoading] = useState(true);
|
|
21
24
|
const [swFileExists, setSwFileExists] = useState(true); // Track if service worker file exists
|
|
22
25
|
|
|
23
|
-
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ??
|
|
26
|
+
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
24
27
|
|
|
25
28
|
useEffect(() => {
|
|
26
29
|
// Don't check service worker status if disabled
|
|
@@ -36,7 +39,7 @@ export const ServiceWorker = () => {
|
|
|
36
39
|
// Initial check with loading state
|
|
37
40
|
const initialCheck = async () => {
|
|
38
41
|
// Double-check service worker is still enabled before proceeding
|
|
39
|
-
const stillEnabled = settings?.serviceWorker?.enabled ??
|
|
42
|
+
const stillEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
40
43
|
if (!stillEnabled) {
|
|
41
44
|
setIsLoading(false);
|
|
42
45
|
return;
|
|
@@ -48,7 +51,7 @@ export const ServiceWorker = () => {
|
|
|
48
51
|
const exists = await serviceWorkerFileExists();
|
|
49
52
|
|
|
50
53
|
// Check again if service worker was disabled during the async operation
|
|
51
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
54
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
52
55
|
if (!currentEnabled) {
|
|
53
56
|
setIsLoading(false);
|
|
54
57
|
return;
|
|
@@ -61,7 +64,7 @@ export const ServiceWorker = () => {
|
|
|
61
64
|
const status = await getServiceWorkerStatus();
|
|
62
65
|
|
|
63
66
|
// Final check before updating state
|
|
64
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
67
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
65
68
|
if (finalCheck) {
|
|
66
69
|
setIsRegistered(status.registered);
|
|
67
70
|
setUpdateAvailable(status.updateAvailable);
|
|
@@ -69,7 +72,7 @@ export const ServiceWorker = () => {
|
|
|
69
72
|
} else {
|
|
70
73
|
// File doesn't exist, so service worker can't be registered
|
|
71
74
|
// Only update if service worker is still enabled
|
|
72
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
75
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
73
76
|
if (finalCheck) {
|
|
74
77
|
setIsRegistered(false);
|
|
75
78
|
setUpdateAvailable(false);
|
|
@@ -82,7 +85,7 @@ export const ServiceWorker = () => {
|
|
|
82
85
|
// Background refresh without affecting loading state
|
|
83
86
|
const refreshStatus = async () => {
|
|
84
87
|
// Skip if service worker was disabled (check current setting value)
|
|
85
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
88
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
86
89
|
if (!currentEnabled) {
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
@@ -91,7 +94,7 @@ export const ServiceWorker = () => {
|
|
|
91
94
|
const exists = await serviceWorkerFileExists();
|
|
92
95
|
|
|
93
96
|
// Check again if service worker was disabled during the async operation
|
|
94
|
-
const currentEnabledAfter = settings?.serviceWorker?.enabled ??
|
|
97
|
+
const currentEnabledAfter = settings?.serviceWorker?.enabled ?? false;
|
|
95
98
|
if (!currentEnabledAfter) {
|
|
96
99
|
return;
|
|
97
100
|
}
|
|
@@ -103,7 +106,7 @@ export const ServiceWorker = () => {
|
|
|
103
106
|
const status = await getServiceWorkerStatus();
|
|
104
107
|
|
|
105
108
|
// Final check before updating state
|
|
106
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
109
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
107
110
|
if (finalCheck) {
|
|
108
111
|
setIsRegistered(status.registered);
|
|
109
112
|
setUpdateAvailable(status.updateAvailable);
|
|
@@ -111,7 +114,7 @@ export const ServiceWorker = () => {
|
|
|
111
114
|
} else {
|
|
112
115
|
// File doesn't exist, so service worker can't be registered
|
|
113
116
|
// Only update if service worker is still enabled
|
|
114
|
-
const finalCheck = settings?.serviceWorker?.enabled ??
|
|
117
|
+
const finalCheck = settings?.serviceWorker?.enabled ?? false;
|
|
115
118
|
if (finalCheck) {
|
|
116
119
|
setIsRegistered(false);
|
|
117
120
|
setUpdateAvailable(false);
|
|
@@ -125,7 +128,7 @@ export const ServiceWorker = () => {
|
|
|
125
128
|
// Listen for status changes
|
|
126
129
|
const unsubscribe = addStatusListener((status) => {
|
|
127
130
|
// Only update if service worker is still enabled (check current setting value)
|
|
128
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
131
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
129
132
|
if (currentEnabled) {
|
|
130
133
|
setIsRegistered(status.registered);
|
|
131
134
|
setUpdateAvailable(status.updateAvailable);
|
|
@@ -161,7 +164,7 @@ export const ServiceWorker = () => {
|
|
|
161
164
|
// Give it a moment to register/unregister
|
|
162
165
|
setTimeout(async () => {
|
|
163
166
|
// Double-check service worker is still enabled before updating state
|
|
164
|
-
const currentEnabled = settings?.serviceWorker?.enabled ??
|
|
167
|
+
const currentEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
165
168
|
if (enabled && currentEnabled) {
|
|
166
169
|
const registered = await isServiceWorkerRegistered();
|
|
167
170
|
setIsRegistered(registered);
|
|
@@ -183,13 +186,21 @@ export const ServiceWorker = () => {
|
|
|
183
186
|
}
|
|
184
187
|
};
|
|
185
188
|
|
|
189
|
+
const handleShowUpdateModal = async () => {
|
|
190
|
+
try {
|
|
191
|
+
await showUpdateAvailableToastForTesting();
|
|
192
|
+
} catch (_error) {
|
|
193
|
+
shellui.toast({
|
|
194
|
+
title: t('caching.testing.error.title'),
|
|
195
|
+
description: t('caching.testing.error.description'),
|
|
196
|
+
type: 'error',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
186
201
|
const handleResetToLatest = async () => {
|
|
187
202
|
try {
|
|
188
|
-
|
|
189
|
-
if ('caches' in window) {
|
|
190
|
-
const cacheNames = await caches.keys();
|
|
191
|
-
await Promise.all(cacheNames.map((name) => caches.delete(name)));
|
|
192
|
-
}
|
|
203
|
+
await clearAppCaches();
|
|
193
204
|
|
|
194
205
|
shellui.toast({
|
|
195
206
|
title: t('caching.resetSuccess.title'),
|
|
@@ -197,16 +208,8 @@ export const ServiceWorker = () => {
|
|
|
197
208
|
type: 'success',
|
|
198
209
|
});
|
|
199
210
|
|
|
200
|
-
// Reload the app using shellUI refresh message (refreshes entire app, not just iframe)
|
|
201
211
|
setTimeout(() => {
|
|
202
|
-
|
|
203
|
-
type: 'SHELLUI_REFRESH_PAGE',
|
|
204
|
-
payload: {},
|
|
205
|
-
});
|
|
206
|
-
if (!sent) {
|
|
207
|
-
// Fallback to window.location.reload if message can't be sent
|
|
208
|
-
window.location.reload();
|
|
209
|
-
}
|
|
212
|
+
reloadApp();
|
|
210
213
|
}, 1000);
|
|
211
214
|
} catch (_error) {
|
|
212
215
|
shellui.toast({
|
|
@@ -354,6 +357,30 @@ export const ServiceWorker = () => {
|
|
|
354
357
|
</Button>
|
|
355
358
|
</div>
|
|
356
359
|
</div>
|
|
360
|
+
|
|
361
|
+
{/* Developer testing */}
|
|
362
|
+
<div className="space-y-2">
|
|
363
|
+
<div className="space-y-0.5">
|
|
364
|
+
<label
|
|
365
|
+
className="text-sm font-medium leading-none"
|
|
366
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
367
|
+
>
|
|
368
|
+
{t('caching.testing.title')}
|
|
369
|
+
</label>
|
|
370
|
+
<p className="text-sm text-muted-foreground">
|
|
371
|
+
{t('caching.testing.description')}
|
|
372
|
+
</p>
|
|
373
|
+
</div>
|
|
374
|
+
<div className="mt-2">
|
|
375
|
+
<Button
|
|
376
|
+
variant="outline"
|
|
377
|
+
onClick={handleShowUpdateModal}
|
|
378
|
+
className="w-full sm:w-auto"
|
|
379
|
+
>
|
|
380
|
+
{t('caching.testing.button')}
|
|
381
|
+
</Button>
|
|
382
|
+
</div>
|
|
383
|
+
</div>
|
|
357
384
|
</>
|
|
358
385
|
)}
|
|
359
386
|
</div>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { Button } from '../../../components/ui/button';
|
|
4
|
+
import { useAuth } from '../../auth/hooks/useAuth';
|
|
5
|
+
import { useConfig } from '../../config/useConfig';
|
|
6
|
+
import {
|
|
7
|
+
fetchStorageQuota,
|
|
8
|
+
formatBytes,
|
|
9
|
+
getStorageBaseUrl,
|
|
10
|
+
getUsagePercent,
|
|
11
|
+
type StorageQuotaBucket,
|
|
12
|
+
type StorageQuotaSnapshot,
|
|
13
|
+
} from '../../storage/quota';
|
|
14
|
+
|
|
15
|
+
const QuotaMeter = ({
|
|
16
|
+
label,
|
|
17
|
+
description,
|
|
18
|
+
bucket,
|
|
19
|
+
}: {
|
|
20
|
+
label: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
bucket: StorageQuotaBucket;
|
|
23
|
+
}) => {
|
|
24
|
+
const { t, i18n } = useTranslation('settings');
|
|
25
|
+
const locale = i18n.language || 'en';
|
|
26
|
+
const percent = getUsagePercent(bucket.usedBytes, bucket.maxBytes);
|
|
27
|
+
const used = formatBytes(bucket.usedBytes, locale);
|
|
28
|
+
const max = bucket.maxBytes !== null ? formatBytes(bucket.maxBytes, locale) : null;
|
|
29
|
+
const barTone = percent !== null && percent >= 100 ? 'bg-destructive' : 'bg-primary';
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="space-y-2">
|
|
33
|
+
<div className="space-y-0.5">
|
|
34
|
+
<h3
|
|
35
|
+
className="text-sm font-medium leading-none"
|
|
36
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
37
|
+
>
|
|
38
|
+
{label}
|
|
39
|
+
</h3>
|
|
40
|
+
{description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
|
|
41
|
+
</div>
|
|
42
|
+
<p className="text-sm tabular-nums">
|
|
43
|
+
{max ? t('storage.usedOfMax', { used, max }) : t('storage.usedOnly', { used })}
|
|
44
|
+
</p>
|
|
45
|
+
{percent !== null ? (
|
|
46
|
+
<div
|
|
47
|
+
className="h-2 w-full overflow-hidden rounded-full bg-muted"
|
|
48
|
+
role="progressbar"
|
|
49
|
+
aria-valuemin={0}
|
|
50
|
+
aria-valuemax={100}
|
|
51
|
+
aria-valuenow={Math.round(percent)}
|
|
52
|
+
aria-label={label}
|
|
53
|
+
>
|
|
54
|
+
<div
|
|
55
|
+
className={`h-full rounded-full transition-[width] ${barTone}`}
|
|
56
|
+
style={{ width: `${percent}%` }}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
) : null}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const Storage = () => {
|
|
65
|
+
const { t } = useTranslation('settings');
|
|
66
|
+
const { config } = useConfig();
|
|
67
|
+
const { session, isAuthenticated } = useAuth();
|
|
68
|
+
const storageBaseUrl = getStorageBaseUrl(config);
|
|
69
|
+
const accessToken = session?.accessToken ?? null;
|
|
70
|
+
|
|
71
|
+
const [snapshot, setSnapshot] = useState<StorageQuotaSnapshot | null>(null);
|
|
72
|
+
const [loading, setLoading] = useState(false);
|
|
73
|
+
const [error, setError] = useState(false);
|
|
74
|
+
|
|
75
|
+
const load = useCallback(async () => {
|
|
76
|
+
if (!storageBaseUrl || !accessToken) {
|
|
77
|
+
setSnapshot(null);
|
|
78
|
+
setLoading(false);
|
|
79
|
+
setError(false);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setLoading(true);
|
|
83
|
+
setError(false);
|
|
84
|
+
try {
|
|
85
|
+
setSnapshot(await fetchStorageQuota(storageBaseUrl, accessToken));
|
|
86
|
+
} catch {
|
|
87
|
+
setSnapshot(null);
|
|
88
|
+
setError(true);
|
|
89
|
+
} finally {
|
|
90
|
+
setLoading(false);
|
|
91
|
+
}
|
|
92
|
+
}, [accessToken, storageBaseUrl]);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
void load();
|
|
96
|
+
}, [load]);
|
|
97
|
+
|
|
98
|
+
if (!isAuthenticated || !accessToken) {
|
|
99
|
+
return <p className="text-sm text-muted-foreground">{t('storage.signInRequired')}</p>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div className="space-y-6">
|
|
104
|
+
<p className="text-sm text-muted-foreground">{t('storage.description')}</p>
|
|
105
|
+
|
|
106
|
+
{loading && !snapshot ? (
|
|
107
|
+
<p className="text-sm text-muted-foreground">{t('storage.loading')}</p>
|
|
108
|
+
) : null}
|
|
109
|
+
|
|
110
|
+
{error ? (
|
|
111
|
+
<div className="space-y-3">
|
|
112
|
+
<p className="text-sm text-destructive">{t('storage.error')}</p>
|
|
113
|
+
<Button
|
|
114
|
+
variant="outline"
|
|
115
|
+
size="sm"
|
|
116
|
+
onClick={() => void load()}
|
|
117
|
+
>
|
|
118
|
+
{t('storage.retry')}
|
|
119
|
+
</Button>
|
|
120
|
+
</div>
|
|
121
|
+
) : null}
|
|
122
|
+
|
|
123
|
+
{snapshot ? (
|
|
124
|
+
<div className="space-y-6">
|
|
125
|
+
<QuotaMeter
|
|
126
|
+
label={t('storage.yourUsage')}
|
|
127
|
+
description={snapshot.user.maxBytes === null ? t('storage.noPersonalLimit') : undefined}
|
|
128
|
+
bucket={snapshot.user}
|
|
129
|
+
/>
|
|
130
|
+
<QuotaMeter
|
|
131
|
+
label={t('storage.organization')}
|
|
132
|
+
bucket={snapshot.company}
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
) : null}
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
@@ -24,7 +24,7 @@ export const UpdateApp = () => {
|
|
|
24
24
|
const [showUpToDateInButton, setShowUpToDateInButton] = useState(false);
|
|
25
25
|
const [checkError, setCheckError] = useState(false);
|
|
26
26
|
|
|
27
|
-
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ??
|
|
27
|
+
const serviceWorkerEnabled = settings?.serviceWorker?.enabled ?? false;
|
|
28
28
|
|
|
29
29
|
useEffect(() => {
|
|
30
30
|
if (isTauri()) return;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { shellui, type StorageSelectedItem } from '@shellui/sdk';
|
|
4
|
+
import { Button } from '../../../../components/ui/button';
|
|
5
|
+
|
|
6
|
+
const FolderIcon = () => (
|
|
7
|
+
<svg
|
|
8
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
9
|
+
width="16"
|
|
10
|
+
height="16"
|
|
11
|
+
viewBox="0 0 24 24"
|
|
12
|
+
fill="none"
|
|
13
|
+
stroke="currentColor"
|
|
14
|
+
strokeWidth="2"
|
|
15
|
+
strokeLinecap="round"
|
|
16
|
+
strokeLinejoin="round"
|
|
17
|
+
aria-hidden
|
|
18
|
+
>
|
|
19
|
+
<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z" />
|
|
20
|
+
</svg>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const FileIcon = () => (
|
|
24
|
+
<svg
|
|
25
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
+
width="16"
|
|
27
|
+
height="16"
|
|
28
|
+
viewBox="0 0 24 24"
|
|
29
|
+
fill="none"
|
|
30
|
+
stroke="currentColor"
|
|
31
|
+
strokeWidth="2"
|
|
32
|
+
strokeLinecap="round"
|
|
33
|
+
strokeLinejoin="round"
|
|
34
|
+
aria-hidden
|
|
35
|
+
>
|
|
36
|
+
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z" />
|
|
37
|
+
<path d="M14 2v6h6" />
|
|
38
|
+
</svg>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const CloseIcon = () => (
|
|
42
|
+
<svg
|
|
43
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
44
|
+
width="16"
|
|
45
|
+
height="16"
|
|
46
|
+
viewBox="0 0 24 24"
|
|
47
|
+
fill="none"
|
|
48
|
+
stroke="currentColor"
|
|
49
|
+
strokeWidth="2"
|
|
50
|
+
strokeLinecap="round"
|
|
51
|
+
strokeLinejoin="round"
|
|
52
|
+
aria-hidden
|
|
53
|
+
>
|
|
54
|
+
<path d="M18 6 6 18" />
|
|
55
|
+
<path d="m6 6 12 12" />
|
|
56
|
+
</svg>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export const StoragePickerTestButtons = () => {
|
|
60
|
+
const { t } = useTranslation('settings');
|
|
61
|
+
const [items, setItems] = useState<StorageSelectedItem[]>([]);
|
|
62
|
+
|
|
63
|
+
const runPicker = async (fn: () => Promise<{ items: StorageSelectedItem[] } | null>) => {
|
|
64
|
+
try {
|
|
65
|
+
const result = await fn();
|
|
66
|
+
if (result) setItems(result.items);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
shellui.toast({
|
|
69
|
+
title: t('develop.testing.storagePicker.errorTitle'),
|
|
70
|
+
description: err instanceof Error ? err.message : t('develop.testing.storagePicker.error'),
|
|
71
|
+
type: 'error',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div>
|
|
78
|
+
<h4
|
|
79
|
+
className="text-sm font-medium mb-2"
|
|
80
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
81
|
+
>
|
|
82
|
+
{t('develop.testing.storagePicker.title')}
|
|
83
|
+
</h4>
|
|
84
|
+
<div className="flex flex-wrap gap-2">
|
|
85
|
+
<Button
|
|
86
|
+
variant="outline"
|
|
87
|
+
onClick={() => void runPicker(() => shellui.selectFolders())}
|
|
88
|
+
>
|
|
89
|
+
{t('develop.testing.storagePicker.buttons.folders')}
|
|
90
|
+
</Button>
|
|
91
|
+
<Button
|
|
92
|
+
variant="outline"
|
|
93
|
+
onClick={() => void runPicker(() => shellui.selectFolders({ multiple: true }))}
|
|
94
|
+
>
|
|
95
|
+
{t('develop.testing.storagePicker.buttons.foldersMultiple')}
|
|
96
|
+
</Button>
|
|
97
|
+
<Button
|
|
98
|
+
variant="outline"
|
|
99
|
+
onClick={() => void runPicker(() => shellui.selectFiles({ multiple: true }))}
|
|
100
|
+
>
|
|
101
|
+
{t('develop.testing.storagePicker.buttons.files')}
|
|
102
|
+
</Button>
|
|
103
|
+
<Button
|
|
104
|
+
variant="outline"
|
|
105
|
+
onClick={() =>
|
|
106
|
+
void runPicker(() => shellui.selectFiles({ multiple: true, folders: true }))
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
{t('develop.testing.storagePicker.buttons.filesAndFolders')}
|
|
110
|
+
</Button>
|
|
111
|
+
</div>
|
|
112
|
+
{items.length > 0 ? (
|
|
113
|
+
<ul className="mt-3 divide-y divide-border rounded-md border border-border">
|
|
114
|
+
{items.map((item) => (
|
|
115
|
+
<li
|
|
116
|
+
key={`${item.bucket}:${item.type}:${item.id}`}
|
|
117
|
+
className="flex items-center gap-2 px-3 py-2 text-sm"
|
|
118
|
+
>
|
|
119
|
+
<span className="shrink-0 text-muted-foreground">
|
|
120
|
+
{item.type === 'folder' ? <FolderIcon /> : <FileIcon />}
|
|
121
|
+
</span>
|
|
122
|
+
<span className="min-w-0 flex-1 truncate">{item.name}</span>
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"
|
|
126
|
+
onClick={() =>
|
|
127
|
+
setItems((current) =>
|
|
128
|
+
current.filter(
|
|
129
|
+
(entry) =>
|
|
130
|
+
!(
|
|
131
|
+
entry.id === item.id &&
|
|
132
|
+
entry.bucket === item.bucket &&
|
|
133
|
+
entry.type === item.type
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
aria-label={t('develop.testing.storagePicker.remove', { name: item.name })}
|
|
139
|
+
>
|
|
140
|
+
<CloseIcon />
|
|
141
|
+
</button>
|
|
142
|
+
</li>
|
|
143
|
+
))}
|
|
144
|
+
</ul>
|
|
145
|
+
) : null}
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { Button } from '../../../../components/ui/button';
|
|
3
|
+
import { requestUploadToastDemo } from '../../../storage/uploads/uploadQueue';
|
|
4
|
+
|
|
5
|
+
export const UploadToastTestButton = () => {
|
|
6
|
+
const { t } = useTranslation('settings');
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<div>
|
|
10
|
+
<h4
|
|
11
|
+
className="text-sm font-medium mb-2"
|
|
12
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
13
|
+
>
|
|
14
|
+
{t('develop.testing.uploadProgress.title')}
|
|
15
|
+
</h4>
|
|
16
|
+
<div className="flex flex-wrap gap-2">
|
|
17
|
+
<Button
|
|
18
|
+
onClick={() => requestUploadToastDemo()}
|
|
19
|
+
variant="outline"
|
|
20
|
+
>
|
|
21
|
+
{t('develop.testing.uploadProgress.buttons.simulate')}
|
|
22
|
+
</Button>
|
|
23
|
+
</div>
|
|
24
|
+
<p className="text-xs text-muted-foreground mt-2">
|
|
25
|
+
{t('develop.testing.uploadProgress.description')}
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -78,7 +78,7 @@ const baseSettings: Settings = {
|
|
|
78
78
|
language: { code: 'en' },
|
|
79
79
|
region: { timezone: 'UTC' },
|
|
80
80
|
cookieConsent: { acceptedHosts: [], consentedCookieHosts: [] },
|
|
81
|
-
serviceWorker: { enabled:
|
|
81
|
+
serviceWorker: { enabled: false },
|
|
82
82
|
user: null,
|
|
83
83
|
};
|
|
84
84
|
|
|
@@ -164,4 +164,58 @@ describe('buildSettingsForPropagation', () => {
|
|
|
164
164
|
const result = buildSettingsForPropagation(baseSettings, config, 'en');
|
|
165
165
|
expect(result.authBackendBaseUrl).toBeNull();
|
|
166
166
|
});
|
|
167
|
+
|
|
168
|
+
it('injects localized administration navigation from config', () => {
|
|
169
|
+
const config = {
|
|
170
|
+
storage: { url: 'http://localhost:8001/', filesUrl: 'http://localhost:5175/' },
|
|
171
|
+
administration: {
|
|
172
|
+
title: { en: 'Applications', fr: 'Applications FR' },
|
|
173
|
+
navigation: [
|
|
174
|
+
{
|
|
175
|
+
label: { en: 'Billing', fr: 'Facturation' },
|
|
176
|
+
path: 'billing',
|
|
177
|
+
url: 'https://app.example.com/billing',
|
|
178
|
+
icon: '/icons/billing.svg',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
label: { en: 'Django admin', fr: 'Admin Django' },
|
|
182
|
+
path: 'django-admin',
|
|
183
|
+
url: '/admin/',
|
|
184
|
+
requiresStaff: true,
|
|
185
|
+
openIn: 'external',
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
} as ShellUIConfig;
|
|
190
|
+
|
|
191
|
+
const result = buildSettingsForPropagation(baseSettings, config, 'fr');
|
|
192
|
+
expect(result.administration).toEqual({
|
|
193
|
+
title: 'Applications FR',
|
|
194
|
+
navigation: [
|
|
195
|
+
{
|
|
196
|
+
path: 'billing',
|
|
197
|
+
url: 'https://app.example.com/billing',
|
|
198
|
+
label: 'Facturation',
|
|
199
|
+
icon: '/icons/billing.svg',
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
path: 'django-admin',
|
|
203
|
+
url: '/admin/',
|
|
204
|
+
label: 'Admin Django',
|
|
205
|
+
requiresStaff: true,
|
|
206
|
+
openIn: 'external',
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
expect(result.storage).toEqual({
|
|
211
|
+
url: 'http://localhost:8001',
|
|
212
|
+
filesUrl: 'http://localhost:5175/',
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('sets administration and storage to null when not configured', () => {
|
|
217
|
+
const result = buildSettingsForPropagation(baseSettings, undefined, 'en');
|
|
218
|
+
expect(result.administration).toBeNull();
|
|
219
|
+
expect(result.storage).toBeNull();
|
|
220
|
+
});
|
|
167
221
|
});
|
|
@@ -41,11 +41,45 @@ export const buildSettingsForPropagation = (
|
|
|
41
41
|
path: item.path,
|
|
42
42
|
url: item.url,
|
|
43
43
|
label: resolveLabel(item.label, lang),
|
|
44
|
+
...(item.icon ? { icon: item.icon } : {}),
|
|
44
45
|
}),
|
|
45
46
|
);
|
|
46
47
|
result = { ...result, navigation: { items } };
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
if (config?.administration) {
|
|
51
|
+
result = {
|
|
52
|
+
...result,
|
|
53
|
+
administration: {
|
|
54
|
+
title: resolveLabel(config.administration.title, lang),
|
|
55
|
+
navigation: (config.administration.navigation ?? []).map((item) => ({
|
|
56
|
+
path: item.path,
|
|
57
|
+
url: item.url,
|
|
58
|
+
label: resolveLabel(item.label, lang),
|
|
59
|
+
...(item.icon ? { icon: item.icon } : {}),
|
|
60
|
+
...(item.requiresStaff ? { requiresStaff: true } : {}),
|
|
61
|
+
...(item.openIn === 'external' ? { openIn: 'external' as const } : {}),
|
|
62
|
+
})),
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
result = { ...result, administration: null };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const storageUrl = config?.storage?.url?.trim().replace(/\/+$/, '') || null;
|
|
70
|
+
if (storageUrl) {
|
|
71
|
+
const filesUrl = config.storage?.filesUrl?.trim() || null;
|
|
72
|
+
result = {
|
|
73
|
+
...result,
|
|
74
|
+
storage: {
|
|
75
|
+
url: storageUrl,
|
|
76
|
+
...(filesUrl ? { filesUrl } : {}),
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
result = { ...result, storage: null };
|
|
81
|
+
}
|
|
82
|
+
|
|
49
83
|
const authBackendBaseUrl =
|
|
50
84
|
config?.backend?.type === 'shellui' && config.backend.url?.trim()
|
|
51
85
|
? config.backend.url.trim().replace(/\/+$/, '')
|
|
@@ -25,6 +25,8 @@ describe('toSettingsUser', () => {
|
|
|
25
25
|
profilePicture: 'https://example.com/avatar.png',
|
|
26
26
|
authProvider: 'github',
|
|
27
27
|
groups: null,
|
|
28
|
+
isStaff: false,
|
|
29
|
+
isCompanyOwner: false,
|
|
28
30
|
});
|
|
29
31
|
|
|
30
32
|
const withGroups = toSettingsUser({
|
|
@@ -44,6 +46,8 @@ describe('toSettingsUser', () => {
|
|
|
44
46
|
profilePicture: null,
|
|
45
47
|
authProvider: 'github',
|
|
46
48
|
groups: ['beta', 'alpha'],
|
|
49
|
+
isStaff: true,
|
|
50
|
+
isCompanyOwner: false,
|
|
47
51
|
});
|
|
48
52
|
});
|
|
49
53
|
});
|
|
@@ -11,5 +11,7 @@ export const toSettingsUser = (user: AuthUser | null): Settings['user'] => {
|
|
|
11
11
|
profilePicture: user.profilePicture,
|
|
12
12
|
authProvider: user.authProvider,
|
|
13
13
|
groups: user.groups.length ? [...user.groups] : null,
|
|
14
|
+
isStaff: user.isStaff,
|
|
15
|
+
isCompanyOwner: user.isCompanyOwner,
|
|
14
16
|
};
|
|
15
17
|
};
|