@tuturuuu/ui 0.19.0 → 0.20.1
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/CHANGELOG.md +46 -0
- package/biome.json +1 -1
- package/package.json +62 -50
- package/src/components/ui/badge.tsx +2 -0
- package/src/components/ui/button.tsx +2 -0
- package/src/components/ui/custom/__tests__/settings-dialog-shell.test.tsx +48 -4
- package/src/components/ui/custom/__tests__/workspace-select-helpers.test.ts +22 -0
- package/src/components/ui/custom/animated-slot-text.tsx +20 -0
- package/src/components/ui/custom/common-footer.tsx +262 -237
- package/src/components/ui/custom/language-dropdown-item.tsx +3 -10
- package/src/components/ui/custom/language-toggle.test.tsx +30 -0
- package/src/components/ui/custom/language-toggle.tsx +11 -10
- package/src/components/ui/custom/locale-preference.ts +32 -0
- package/src/components/ui/custom/settings/appearance-settings.tsx +5 -13
- package/src/components/ui/custom/settings-dialog-shell.tsx +40 -9
- package/src/components/ui/custom/structure.tsx +12 -0
- package/src/components/ui/custom/system-language-dropdown-item.tsx +3 -6
- package/src/components/ui/custom/workspace-access/adapters.test.ts +10 -1
- package/src/components/ui/custom/workspace-access/adapters.ts +36 -4
- package/src/components/ui/custom/workspace-access/member-filter-utils.test.ts +14 -0
- package/src/components/ui/custom/workspace-access/member-filter-utils.ts +8 -0
- package/src/components/ui/custom/workspace-access/types.ts +20 -0
- package/src/components/ui/custom/workspace-access/workspace-access-context.test.tsx +111 -0
- package/src/components/ui/custom/workspace-access/workspace-access-default-role-card.tsx +15 -5
- package/src/components/ui/custom/workspace-access/workspace-access-invite-dialog.tsx +155 -48
- package/src/components/ui/custom/workspace-access/workspace-access-member-profile-dialog.tsx +92 -0
- package/src/components/ui/custom/workspace-access/workspace-access-member-row.tsx +171 -76
- package/src/components/ui/custom/workspace-access/workspace-access-members.tsx +11 -2
- package/src/components/ui/custom/workspace-access/workspace-access-page-header.tsx +11 -11
- package/src/components/ui/custom/workspace-access/workspace-access-page.tsx +180 -22
- package/src/components/ui/custom/workspace-access/workspace-access-people-filters.tsx +29 -15
- package/src/components/ui/custom/workspace-access/workspace-access-permission-checklist.tsx +56 -10
- package/src/components/ui/custom/workspace-access/workspace-access-permission-preview.test.ts +33 -0
- package/src/components/ui/custom/workspace-access/workspace-access-permission-preview.tsx +24 -1
- package/src/components/ui/custom/workspace-access/workspace-access-responsive.test.ts +64 -0
- package/src/components/ui/custom/workspace-access/workspace-access-role-editor-dialog.tsx +28 -16
- package/src/components/ui/custom/workspace-access/workspace-access-roles.tsx +35 -11
- package/src/components/ui/custom/workspace-access/workspace-access-tabs-toolbar.tsx +23 -11
- package/src/components/ui/custom/workspace-select-helpers.ts +5 -3
- package/src/components/ui/custom/workspace-select.tsx +8 -2
- package/src/components/ui/finance/shared/charts/monthly-total-chart-client.tsx +1 -1
- package/src/components/ui/finance/shared/charts/monthly-total-chart.tsx +1 -1
- package/src/components/ui/storefront/cart-summary.tsx +12 -2
- package/src/components/ui/storefront/storefront-surface.test.tsx +21 -0
- package/src/components/ui/storefront/storefront-surface.tsx +6 -0
- package/src/components/ui/text-editor/__tests__/collaboration-binding.test.tsx +161 -0
- package/src/components/ui/text-editor/editor.tsx +267 -235
- package/src/globals.css +166 -0
- package/src/hooks/__tests__/use-workspace-identity-mutation.test.tsx +181 -0
- package/src/hooks/use-workspace-identity-mutation.ts +136 -0
- package/vendor/xlsx/LICENSE +201 -0
- package/vendor/xlsx/types/index.d.ts +1065 -0
- package/vendor/xlsx/xlsx.js +28103 -0
- package/vendor/xlsx/xlsx.mjs +28228 -0
- package/vendor/xlsx-0.20.3.tgz +0 -0
package/src/globals.css
CHANGED
|
@@ -442,6 +442,172 @@
|
|
|
442
442
|
--animate-accordion-up: accordion-up 0.2s ease-out;
|
|
443
443
|
--animate-aurora: aurora 80s linear infinite;
|
|
444
444
|
--animate-shake: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
|
|
445
|
+
--animate-bloom-drift: bloom-drift 24s ease-in-out infinite;
|
|
446
|
+
--animate-bloom-drift-slow: bloom-drift-slow 32s ease-in-out infinite;
|
|
447
|
+
--animate-sheen: sheen 6s ease-in-out infinite;
|
|
448
|
+
--animate-rise-in: rise-in 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
449
|
+
--animate-text-sheen: text-sheen 8s ease-in-out infinite;
|
|
450
|
+
--animate-marquee: marquee 40s linear infinite;
|
|
451
|
+
--animate-float-y: float-y 6s ease-in-out infinite;
|
|
452
|
+
--animate-scroll-cue: scroll-cue 2.2s ease-in-out infinite;
|
|
453
|
+
--animate-ring-pulse: ring-pulse 3s ease-out infinite;
|
|
454
|
+
--animate-day-scan: day-scan 9s ease-in-out infinite;
|
|
455
|
+
|
|
456
|
+
/* Marketing type scale. The variables resolve only where the marketing
|
|
457
|
+
layout loads the fonts; everywhere else these fall back to the app font. */
|
|
458
|
+
/* The inner fallbacks matter: apps that do not load the marketing faces
|
|
459
|
+
(nova, meet) would otherwise hit an undefined var and drop the whole
|
|
460
|
+
font-family declaration. */
|
|
461
|
+
--font-display:
|
|
462
|
+
var(--font-be-vietnam-pro, ui-sans-serif), ui-sans-serif, system-ui,
|
|
463
|
+
sans-serif;
|
|
464
|
+
--font-mono-ui:
|
|
465
|
+
var(--font-jetbrains-mono, ui-monospace), ui-monospace, SFMono-Regular,
|
|
466
|
+
Menlo, monospace;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/* Marketing atmosphere: slow, low-amplitude drift for hero light blooms. */
|
|
470
|
+
@keyframes bloom-drift {
|
|
471
|
+
0%,
|
|
472
|
+
100% {
|
|
473
|
+
transform: translate3d(0, 0, 0) scale(1);
|
|
474
|
+
}
|
|
475
|
+
50% {
|
|
476
|
+
transform: translate3d(4%, -3%, 0) scale(1.08);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
@keyframes bloom-drift-slow {
|
|
481
|
+
0%,
|
|
482
|
+
100% {
|
|
483
|
+
transform: translate3d(0, 0, 0) scale(1.05);
|
|
484
|
+
}
|
|
485
|
+
50% {
|
|
486
|
+
transform: translate3d(-5%, 4%, 0) scale(1);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
@keyframes sheen {
|
|
491
|
+
0%,
|
|
492
|
+
100% {
|
|
493
|
+
opacity: 0.35;
|
|
494
|
+
}
|
|
495
|
+
50% {
|
|
496
|
+
opacity: 0.75;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/* Hero entrance. Paired with an inline animation-delay for stagger, so the
|
|
501
|
+
choreography needs no JavaScript and runs before hydration. */
|
|
502
|
+
@keyframes rise-in {
|
|
503
|
+
from {
|
|
504
|
+
opacity: 0;
|
|
505
|
+
transform: translate3d(0, 24px, 0);
|
|
506
|
+
filter: blur(12px);
|
|
507
|
+
}
|
|
508
|
+
to {
|
|
509
|
+
opacity: 1;
|
|
510
|
+
transform: translate3d(0, 0, 0);
|
|
511
|
+
filter: blur(0);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/* Slow light travelling through gradient headline text. */
|
|
516
|
+
@keyframes text-sheen {
|
|
517
|
+
0%,
|
|
518
|
+
100% {
|
|
519
|
+
background-position: 0% 50%;
|
|
520
|
+
}
|
|
521
|
+
50% {
|
|
522
|
+
background-position: 100% 50%;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/* Product marquee: the track holds two identical halves, so -50% loops
|
|
527
|
+
seamlessly. */
|
|
528
|
+
@keyframes marquee {
|
|
529
|
+
from {
|
|
530
|
+
transform: translate3d(0, 0, 0);
|
|
531
|
+
}
|
|
532
|
+
to {
|
|
533
|
+
transform: translate3d(-50%, 0, 0);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
@keyframes float-y {
|
|
538
|
+
0%,
|
|
539
|
+
100% {
|
|
540
|
+
transform: translate3d(0, 0, 0);
|
|
541
|
+
}
|
|
542
|
+
50% {
|
|
543
|
+
transform: translate3d(0, -10px, 0);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
@keyframes scroll-cue {
|
|
548
|
+
0% {
|
|
549
|
+
opacity: 0;
|
|
550
|
+
transform: translate3d(0, -6px, 0);
|
|
551
|
+
}
|
|
552
|
+
40% {
|
|
553
|
+
opacity: 1;
|
|
554
|
+
}
|
|
555
|
+
100% {
|
|
556
|
+
opacity: 0;
|
|
557
|
+
transform: translate3d(0, 10px, 0);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/* Restless light crossing the fragmented day on the landing page. Driving
|
|
562
|
+
background-position (rather than a transform) keeps the highlight clipped to
|
|
563
|
+
the strip, so it never has to be masked. Symmetric endpoints let it sweep
|
|
564
|
+
out and back on one eased loop with no seam. */
|
|
565
|
+
@keyframes day-scan {
|
|
566
|
+
0%,
|
|
567
|
+
100% {
|
|
568
|
+
background-position: 130% 0;
|
|
569
|
+
}
|
|
570
|
+
50% {
|
|
571
|
+
background-position: -30% 0;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
@keyframes ring-pulse {
|
|
576
|
+
0% {
|
|
577
|
+
opacity: 0.6;
|
|
578
|
+
transform: scale(0.85);
|
|
579
|
+
}
|
|
580
|
+
100% {
|
|
581
|
+
opacity: 0;
|
|
582
|
+
transform: scale(1.6);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/* Global guard: the marketing atmosphere and entrance choreography are
|
|
587
|
+
decorative, so drop them entirely when the user asks for less motion. */
|
|
588
|
+
@media (prefers-reduced-motion: reduce) {
|
|
589
|
+
.animate-rise-in,
|
|
590
|
+
.animate-text-sheen,
|
|
591
|
+
.animate-marquee,
|
|
592
|
+
.animate-float-y,
|
|
593
|
+
.animate-scroll-cue,
|
|
594
|
+
.animate-ring-pulse,
|
|
595
|
+
.animate-day-scan,
|
|
596
|
+
.animate-bloom-drift,
|
|
597
|
+
.animate-bloom-drift-slow,
|
|
598
|
+
.animate-sheen,
|
|
599
|
+
.animate-aurora {
|
|
600
|
+
/*
|
|
601
|
+
* Cancelling the animation is enough, and is all we should do. These
|
|
602
|
+
* elements carry layout transforms (`-translate-x-1/2` centres the hero
|
|
603
|
+
* blooms) and deliberate opacities (blooms sit at 40-60%), so forcing
|
|
604
|
+
* `transform: none` / `opacity: 1` here would shift them off-centre and
|
|
605
|
+
* blow out their brightness. Entrance keyframes use `both`, so removing
|
|
606
|
+
* the animation simply leaves the element in its natural, final state.
|
|
607
|
+
*/
|
|
608
|
+
/* biome-ignore lint/complexity/noImportantStyles: must beat utility-class animations for accessibility */
|
|
609
|
+
animation: none !important;
|
|
610
|
+
}
|
|
445
611
|
}
|
|
446
612
|
|
|
447
613
|
/* Aurora animation - must be outside @theme block */
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
|
+
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import {
|
|
6
|
+
patchWorkspaceCacheValue,
|
|
7
|
+
useUpdateWorkspaceIdentity,
|
|
8
|
+
} from '../use-workspace-identity-mutation';
|
|
9
|
+
|
|
10
|
+
const WS_ID = 'ws-1';
|
|
11
|
+
|
|
12
|
+
const mocks = vi.hoisted(() => ({
|
|
13
|
+
refresh: vi.fn(),
|
|
14
|
+
updateWorkspace: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock('next/navigation', () => ({
|
|
18
|
+
useRouter: () => ({ refresh: mocks.refresh }),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
vi.mock('@tuturuuu/internal-api/workspaces', () => ({
|
|
22
|
+
updateWorkspace: (...args: unknown[]) => mocks.updateWorkspace(...args),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
function createHarness() {
|
|
26
|
+
const queryClient = new QueryClient({
|
|
27
|
+
defaultOptions: { queries: { retry: false } },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// The surfaces that show a workspace name, as each one caches it.
|
|
31
|
+
queryClient.setQueryData(
|
|
32
|
+
['workspaces'],
|
|
33
|
+
[
|
|
34
|
+
{ id: WS_ID, name: 'Old name' },
|
|
35
|
+
{ id: 'ws-2', name: 'Other workspace' },
|
|
36
|
+
]
|
|
37
|
+
);
|
|
38
|
+
queryClient.setQueryData(['workspace', WS_ID], {
|
|
39
|
+
workspace: { handle: 'old-handle', id: WS_ID, name: 'Old name' },
|
|
40
|
+
});
|
|
41
|
+
queryClient.setQueryData(['workspace-select-current-workspace', WS_ID], {
|
|
42
|
+
id: WS_ID,
|
|
43
|
+
name: 'Old name',
|
|
44
|
+
});
|
|
45
|
+
queryClient.setQueryData(['unrelated'], { id: WS_ID, name: 'Old name' });
|
|
46
|
+
|
|
47
|
+
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
48
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return { queryClient, wrapper };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('patchWorkspaceCacheValue', () => {
|
|
55
|
+
it('patches the record, arrays of records, and wrapped shapes', () => {
|
|
56
|
+
const patch = { name: 'New name' };
|
|
57
|
+
|
|
58
|
+
expect(
|
|
59
|
+
patchWorkspaceCacheValue({ id: WS_ID, name: 'Old' }, WS_ID, patch)
|
|
60
|
+
).toEqual({ id: WS_ID, name: 'New name' });
|
|
61
|
+
|
|
62
|
+
expect(
|
|
63
|
+
patchWorkspaceCacheValue([{ id: WS_ID, name: 'Old' }], WS_ID, patch)
|
|
64
|
+
).toEqual([{ id: WS_ID, name: 'New name' }]);
|
|
65
|
+
|
|
66
|
+
expect(
|
|
67
|
+
patchWorkspaceCacheValue(
|
|
68
|
+
{ workspace: { id: WS_ID, name: 'Old' } },
|
|
69
|
+
WS_ID,
|
|
70
|
+
patch
|
|
71
|
+
)
|
|
72
|
+
).toEqual({ workspace: { id: WS_ID, name: 'New name' } });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('leaves other workspaces and unknown shapes alone', () => {
|
|
76
|
+
const other = { id: 'ws-2', name: 'Other' };
|
|
77
|
+
expect(patchWorkspaceCacheValue(other, WS_ID, { name: 'New' })).toBe(other);
|
|
78
|
+
expect(patchWorkspaceCacheValue(null, WS_ID, { name: 'New' })).toBeNull();
|
|
79
|
+
expect(patchWorkspaceCacheValue('text', WS_ID, { name: 'New' })).toBe(
|
|
80
|
+
'text'
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('useUpdateWorkspaceIdentity', () => {
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
vi.clearAllMocks();
|
|
88
|
+
mocks.updateWorkspace.mockResolvedValue({ id: WS_ID });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Regression: renaming a workspace used to only call `router.refresh()`, which
|
|
92
|
+
// re-renders server markup but leaves client caches untouched — so the
|
|
93
|
+
// workspace selector kept the old name until the user reloaded the page.
|
|
94
|
+
it('renames the workspace everywhere it is cached', async () => {
|
|
95
|
+
const { queryClient, wrapper } = createHarness();
|
|
96
|
+
const { result } = renderHook(
|
|
97
|
+
() => useUpdateWorkspaceIdentity({ workspaceId: WS_ID }),
|
|
98
|
+
{ wrapper }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await act(async () => {
|
|
102
|
+
await result.current.mutateAsync({ name: 'New name' });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(queryClient.getQueryData(['workspaces'])).toEqual([
|
|
106
|
+
{ id: WS_ID, name: 'New name' },
|
|
107
|
+
{ id: 'ws-2', name: 'Other workspace' },
|
|
108
|
+
]);
|
|
109
|
+
expect(queryClient.getQueryData(['workspace', WS_ID])).toEqual({
|
|
110
|
+
workspace: { handle: 'old-handle', id: WS_ID, name: 'New name' },
|
|
111
|
+
});
|
|
112
|
+
expect(
|
|
113
|
+
queryClient.getQueryData(['workspace-select-current-workspace', WS_ID])
|
|
114
|
+
).toEqual({ id: WS_ID, name: 'New name' });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('refreshes server-rendered surfaces too', async () => {
|
|
118
|
+
const { wrapper } = createHarness();
|
|
119
|
+
const { result } = renderHook(
|
|
120
|
+
() => useUpdateWorkspaceIdentity({ workspaceId: WS_ID }),
|
|
121
|
+
{ wrapper }
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
await act(async () => {
|
|
125
|
+
await result.current.mutateAsync({ name: 'New name' });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await waitFor(() => expect(mocks.refresh).toHaveBeenCalledTimes(1));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('updates the cache before the request resolves', async () => {
|
|
132
|
+
const { queryClient, wrapper } = createHarness();
|
|
133
|
+
let resolveUpdate: (value: unknown) => void = () => {};
|
|
134
|
+
mocks.updateWorkspace.mockReturnValue(
|
|
135
|
+
new Promise((resolve) => {
|
|
136
|
+
resolveUpdate = resolve;
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const { result } = renderHook(
|
|
141
|
+
() => useUpdateWorkspaceIdentity({ workspaceId: WS_ID }),
|
|
142
|
+
{ wrapper }
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
await act(async () => {
|
|
146
|
+
void result.current.mutateAsync({ name: 'Optimistic name' });
|
|
147
|
+
await Promise.resolve();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
expect(queryClient.getQueryData(['workspaces'])).toEqual([
|
|
151
|
+
{ id: WS_ID, name: 'Optimistic name' },
|
|
152
|
+
{ id: 'ws-2', name: 'Other workspace' },
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
await act(async () => {
|
|
156
|
+
resolveUpdate({ id: WS_ID });
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('rolls the caches back when the rename fails', async () => {
|
|
161
|
+
const { queryClient, wrapper } = createHarness();
|
|
162
|
+
const onError = vi.fn();
|
|
163
|
+
mocks.updateWorkspace.mockRejectedValue(new Error('nope'));
|
|
164
|
+
|
|
165
|
+
const { result } = renderHook(
|
|
166
|
+
() => useUpdateWorkspaceIdentity({ onError, workspaceId: WS_ID }),
|
|
167
|
+
{ wrapper }
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
await act(async () => {
|
|
171
|
+
await result.current.mutateAsync({ name: 'New name' }).catch(() => {});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
expect(queryClient.getQueryData(['workspaces'])).toEqual([
|
|
175
|
+
{ id: WS_ID, name: 'Old name' },
|
|
176
|
+
{ id: 'ws-2', name: 'Other workspace' },
|
|
177
|
+
]);
|
|
178
|
+
expect(onError).toHaveBeenCalledTimes(1);
|
|
179
|
+
expect(mocks.refresh).not.toHaveBeenCalled();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { updateWorkspace } from '@tuturuuu/internal-api/workspaces';
|
|
5
|
+
import { useRouter } from 'next/navigation';
|
|
6
|
+
|
|
7
|
+
export interface WorkspaceIdentityPatch {
|
|
8
|
+
handle?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface QueryKeyFilter {
|
|
13
|
+
queryKey: readonly unknown[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Matches every cached query that can carry this workspace's name or handle.
|
|
18
|
+
*
|
|
19
|
+
* The workspace selector reads `['workspaces']`, satellite panels read
|
|
20
|
+
* `['workspace', wsId]`, and the selector's fallback reads
|
|
21
|
+
* `['workspace-select-current-workspace', wsId]` — so match by the well-known
|
|
22
|
+
* roots plus any key mentioning the workspace id.
|
|
23
|
+
*/
|
|
24
|
+
export function createWorkspaceQueryFilter(workspaceId: string) {
|
|
25
|
+
return {
|
|
26
|
+
predicate: ({ queryKey }: QueryKeyFilter) =>
|
|
27
|
+
queryKey[0] === 'workspaces' ||
|
|
28
|
+
queryKey[0] === 'user-workspaces' ||
|
|
29
|
+
queryKey.includes(workspaceId),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Apply a patch to any shape a workspace can take inside a cached value: the
|
|
35
|
+
* record itself, an array of records, or a wrapper such as `{ data }`,
|
|
36
|
+
* `{ workspace }` or `{ workspaces }`.
|
|
37
|
+
*/
|
|
38
|
+
export function patchWorkspaceCacheValue(
|
|
39
|
+
value: unknown,
|
|
40
|
+
workspaceId: string,
|
|
41
|
+
patch: WorkspaceIdentityPatch
|
|
42
|
+
): unknown {
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
let changed = false;
|
|
45
|
+
const nextArray = value.map((entry) => {
|
|
46
|
+
const nextEntry = patchWorkspaceCacheValue(entry, workspaceId, patch);
|
|
47
|
+
if (nextEntry !== entry) changed = true;
|
|
48
|
+
return nextEntry;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return changed ? nextArray : value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!value || typeof value !== 'object') {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const record = value as Record<string, unknown>;
|
|
59
|
+
if (record.id === workspaceId) {
|
|
60
|
+
return { ...record, ...patch };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let changed = false;
|
|
64
|
+
const nextRecord = { ...record };
|
|
65
|
+
for (const key of ['data', 'workspace', 'workspaces'] as const) {
|
|
66
|
+
if (!(key in record)) continue;
|
|
67
|
+
const nextValue = patchWorkspaceCacheValue(record[key], workspaceId, patch);
|
|
68
|
+
if (nextValue !== record[key]) {
|
|
69
|
+
nextRecord[key] = nextValue;
|
|
70
|
+
changed = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return changed ? nextRecord : value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Rename a workspace and make every surface agree, without a page reload.
|
|
79
|
+
*
|
|
80
|
+
* A workspace name is read from two independent places: client caches (the
|
|
81
|
+
* workspace selector, settings panels) and server-rendered markup (sidebars,
|
|
82
|
+
* headers). `router.refresh()` only refreshes the second, so a form that just
|
|
83
|
+
* calls it leaves the selector showing the old name until the user reloads —
|
|
84
|
+
* which is exactly what shipped in `apps/web`. This does all three steps:
|
|
85
|
+
* patch the caches optimistically, revalidate them, and refresh the server tree.
|
|
86
|
+
*
|
|
87
|
+
* Every app's settings dialog should mutate the workspace through this hook, so
|
|
88
|
+
* the propagation rules live in one place rather than being re-derived per app.
|
|
89
|
+
*/
|
|
90
|
+
export function useUpdateWorkspaceIdentity({
|
|
91
|
+
onError,
|
|
92
|
+
onSuccess,
|
|
93
|
+
workspaceId,
|
|
94
|
+
}: {
|
|
95
|
+
onError?: (error: unknown) => void;
|
|
96
|
+
onSuccess?: (patch: WorkspaceIdentityPatch) => void;
|
|
97
|
+
workspaceId: string;
|
|
98
|
+
}) {
|
|
99
|
+
const queryClient = useQueryClient();
|
|
100
|
+
const router = useRouter();
|
|
101
|
+
const workspaceQueryFilter = createWorkspaceQueryFilter(workspaceId);
|
|
102
|
+
|
|
103
|
+
return useMutation({
|
|
104
|
+
mutationFn: (values: WorkspaceIdentityPatch) =>
|
|
105
|
+
updateWorkspace(workspaceId, values as { handle?: string; name: string }),
|
|
106
|
+
onError: (error, _values, context) => {
|
|
107
|
+
for (const [queryKey, previous] of context?.previousQueries ?? []) {
|
|
108
|
+
queryClient.setQueryData(queryKey, previous);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
onError?.(error);
|
|
112
|
+
},
|
|
113
|
+
onMutate: async (values: WorkspaceIdentityPatch) => {
|
|
114
|
+
await queryClient.cancelQueries(workspaceQueryFilter);
|
|
115
|
+
const previousQueries = queryClient.getQueriesData(workspaceQueryFilter);
|
|
116
|
+
|
|
117
|
+
queryClient.setQueriesData(workspaceQueryFilter, (previous) =>
|
|
118
|
+
patchWorkspaceCacheValue(previous, workspaceId, values)
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return { previousQueries };
|
|
122
|
+
},
|
|
123
|
+
onSuccess: async (_response, values: WorkspaceIdentityPatch) => {
|
|
124
|
+
queryClient.setQueriesData(workspaceQueryFilter, (previous) =>
|
|
125
|
+
patchWorkspaceCacheValue(previous, workspaceId, values)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
await queryClient.invalidateQueries(workspaceQueryFilter);
|
|
129
|
+
// Server-rendered surfaces (sidebar header, page titles) need this; the
|
|
130
|
+
// cache work above is what keeps the client-side selector honest.
|
|
131
|
+
router.refresh();
|
|
132
|
+
|
|
133
|
+
onSuccess?.(values);
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (C) 2012-present SheetJS LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|