-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove listGroups while building categories (#11988)
This PR adds new field called `groups` on the User object to avoid fetching the usergroups list to get the names of the groups. Also this PR removes the `<ManagePermisssionsModal />`
- Loading branch information
1 parent
6dc3e33
commit b1cc4f1
Showing
25 changed files
with
429 additions
and
718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* @file Activity component | ||
* | ||
* This component is used to suspend the rendering of a subtree until a promise is resolved. | ||
*/ | ||
import { unsafeWriteValue } from '#/utilities/write' | ||
import { Suspense, useEffect, useLayoutEffect, useRef, useState } from 'react' | ||
import { useAwait } from './Await' | ||
|
||
/** | ||
* Props for {@link Activity} | ||
*/ | ||
export interface ActivityProps { | ||
/** | ||
* The mode of the activity. | ||
* - `active`: The subtree is active (default). | ||
* - `inactive`: The activity of the subtree is paused. | ||
* - `inactive-hidden`: The activity of the subtree is paused, and the subtree is hidden. | ||
* @default 'active' | ||
*/ | ||
readonly mode: 'active' | 'inactive-hidden' | 'inactive' | ||
readonly children: React.ReactNode | ||
} | ||
|
||
/** | ||
* A component that pauses all activity inside it's subtree. | ||
* | ||
* --- | ||
* ## The component is EXPERIMENTAL, please use with caution. | ||
* --- | ||
*/ | ||
export function Activity(props: ActivityProps) { | ||
const { mode, children } = props | ||
|
||
const contentRef = useRef<HTMLDivElement>(null) | ||
|
||
const [promise, setPromise] = useState<Promise<void> | null>(null) | ||
|
||
const isActive = mode === 'active' | ||
const fallback = | ||
mode === 'inactive-hidden' ? null : <UnhideSuspendedTree contentRef={contentRef} /> | ||
|
||
useEffect(() => { | ||
if (isActive) { | ||
return | ||
} | ||
|
||
let resolve = () => {} | ||
|
||
setPromise( | ||
new Promise((res) => { | ||
resolve = res | ||
}), | ||
) | ||
|
||
return () => { | ||
resolve() | ||
setPromise(null) | ||
} | ||
}, [isActive]) | ||
|
||
return ( | ||
<div ref={contentRef} className="contents"> | ||
<Suspense fallback={fallback}> | ||
<ActivityInner promise={promise}>{children}</ActivityInner> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
/** | ||
* Props for {@link ActivityInner} | ||
*/ | ||
interface ActivityInnerProps { | ||
readonly children: React.ReactNode | ||
readonly promise?: Promise<unknown> | null | undefined | ||
} | ||
|
||
/** | ||
* A component that suspends the tree using promises. | ||
* @param props - The props of the component. | ||
* @returns The children of the component. | ||
*/ | ||
function ActivityInner(props: ActivityInnerProps) { | ||
const { promise, children } = props | ||
|
||
// Suspend the subtree | ||
useAwait(promise) | ||
|
||
return children | ||
} | ||
|
||
/** | ||
* Props for {@link UnhideSuspendedTree} | ||
*/ | ||
interface UnhideSuspendedTreeProps { | ||
readonly contentRef: React.RefObject<HTMLDivElement> | ||
} | ||
|
||
/** | ||
* Hack, that unhides the suspended tree. | ||
*/ | ||
function UnhideSuspendedTree(props: UnhideSuspendedTreeProps) { | ||
const { contentRef } = props | ||
|
||
useLayoutEffect(() => { | ||
const element: HTMLDivElement | null = contentRef.current | ||
|
||
if (element == null) { | ||
return | ||
} | ||
|
||
const chidlren = element.childNodes | ||
|
||
for (let i = 0; i < chidlren.length; i++) { | ||
const child = chidlren[i] | ||
|
||
if (child instanceof HTMLElement) { | ||
unsafeWriteValue(child.style, 'display', '') | ||
} | ||
} | ||
}, [contentRef]) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
app/gui/src/dashboard/components/__tests__/Activity.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import { useEffect, useState } from 'react' | ||
import { describe } from 'vitest' | ||
import { Activity } from '../Activity' | ||
|
||
describe('Activity', (it) => { | ||
it('should render the children', ({ expect }) => { | ||
render( | ||
<Activity mode="active"> | ||
<div>Hello</div> | ||
</Activity>, | ||
) | ||
|
||
expect(screen.getByText('Hello')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render children when inactive', ({ expect }) => { | ||
render( | ||
<Activity mode="inactive"> | ||
<div>Hello</div> | ||
</Activity>, | ||
) | ||
|
||
expect(screen.getByText('Hello')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render children when inactive-hidden', ({ expect }) => { | ||
render( | ||
<Activity mode="inactive-hidden"> | ||
<div>Hello</div> | ||
</Activity>, | ||
) | ||
|
||
expect(screen.getByText('Hello')).toBeInTheDocument() | ||
}) | ||
|
||
it('should display children when inactive', ({ expect }) => { | ||
render( | ||
<Activity mode="inactive"> | ||
<div>Hello</div> | ||
</Activity>, | ||
) | ||
|
||
expect(screen.getByText('Hello')).toBeVisible() | ||
}) | ||
|
||
it('should not unmount children when inactive', async ({ expect }) => { | ||
let count = 0 | ||
|
||
const Component = () => { | ||
useEffect( | ||
() => () => { | ||
count++ | ||
}, | ||
[], | ||
) | ||
|
||
return <div>{count}</div> | ||
} | ||
|
||
function Container() { | ||
const [mode, setMode] = useState<'active' | 'inactive'>('active') | ||
|
||
return ( | ||
<div> | ||
<button | ||
onClick={() => { | ||
setMode('inactive') | ||
}} | ||
> | ||
Inactive | ||
</button> | ||
<button | ||
onClick={() => { | ||
setMode('active') | ||
}} | ||
> | ||
Active | ||
</button> | ||
<Activity mode={mode}> | ||
<Component /> | ||
</Activity> | ||
</div> | ||
) | ||
} | ||
|
||
render(<Container />) | ||
|
||
await userEvent.click(screen.getByText('Inactive')) | ||
await userEvent.click(screen.getByText('Active')) | ||
|
||
expect(count).toBe(0) | ||
}) | ||
}) |
Oops, something went wrong.