-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from MytsV/feature-473-functional_rule_list
Feature 473. Functional rule list
- Loading branch information
Showing
71 changed files
with
2,082 additions
and
712 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
'use client'; | ||
|
||
import { ListRule } from '@/component-library/pages/legacy/Rule/ListRule'; | ||
import { RuleViewModel } from '@/lib/infrastructure/data/view-model/rule'; | ||
import useComDOM from '@/lib/infrastructure/hooks/useComDOM'; | ||
import { HTTPRequest } from '@/lib/sdk/http'; | ||
import { useEffect, useState } from 'react'; | ||
import { ListRule } from '@/component-library/pages/Rule/list/ListRule'; | ||
|
||
export default function Page() { | ||
const comDOM = useComDOM<RuleViewModel>('list-rule-query', [], false, Infinity, 200, true); | ||
return <ListRule comdom={comDOM} webui_host={process.env.NEXT_PUBLIC_WEBUI_HOST ?? 'http://localhost:3000'} />; | ||
return <ListRule />; | ||
} |
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/component-library/features/badges/Rule/RuleStateBadge.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,29 @@ | ||
import { RuleState } from '@/lib/core/entity/rucio'; | ||
import React from 'react'; | ||
import { Badge } from '@/component-library/atoms/misc/Badge'; | ||
import { cn } from '@/component-library/utils'; | ||
|
||
const stateString: Record<RuleState, string> = { | ||
[RuleState.REPLICATING]: 'Replicating', | ||
[RuleState.OK]: 'OK', | ||
[RuleState.STUCK]: 'Stuck', | ||
[RuleState.SUSPENDED]: 'Suspended', | ||
[RuleState.WAITING_APPROVAL]: 'Waiting', | ||
[RuleState.INJECT]: 'Inject', | ||
[RuleState.UNKNOWN]: 'Unknown', | ||
}; | ||
|
||
const stateColorClasses: Record<RuleState, string> = { | ||
[RuleState.REPLICATING]: 'bg-base-warning-400', | ||
[RuleState.OK]: 'bg-base-success-500', | ||
[RuleState.STUCK]: 'bg-base-error-500', | ||
[RuleState.SUSPENDED]: 'bg-neutral-500', | ||
[RuleState.WAITING_APPROVAL]: 'bg-extra-indigo-500', | ||
[RuleState.INJECT]: 'bg-base-info-500', | ||
[RuleState.UNKNOWN]: 'bg-neutral-0 dark:bg-neutral-800', | ||
}; | ||
|
||
export const RuleStateBadge = (props: { value: RuleState; className?: string }) => { | ||
const classes = cn(stateColorClasses[props.value], props.className); | ||
return <Badge value={stateString[props.value]} className={classes} />; | ||
}; |
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
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ges/DID/List/Meta/ListDIDMeta.stories.tsx → ...ges/DID/list/meta/ListDIDMeta.stories.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
File renamed without changes.
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
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
src/component-library/pages/Rule/list/ListRule.stories.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,32 @@ | ||
import { StoryFn, Meta } from '@storybook/react'; | ||
import { fixtureRuleViewModel } from '@/test/fixtures/table-fixtures'; | ||
import { ListRule } from '@/component-library/pages/Rule/list/ListRule'; | ||
import { ToastedTemplate } from '@/component-library/templates/ToastedTemplate/ToastedTemplate'; | ||
import { getDecoratorWithWorker } from '@/test/mocks/handlers/story-decorators'; | ||
import { getMockStreamEndpoint } from '@/test/mocks/handlers/streaming-handlers'; | ||
|
||
export default { | ||
title: 'Components/Pages/Rule/List', | ||
component: ListRule, | ||
} as Meta<typeof ListRule>; | ||
|
||
const Template: StoryFn<typeof ListRule> = args => ( | ||
<ToastedTemplate> | ||
<ListRule {...args} /> | ||
</ToastedTemplate> | ||
); | ||
|
||
export const InitialDataNoEndpoint = Template.bind({}); | ||
InitialDataNoEndpoint.args = { | ||
initialData: Array.from({ length: 50 }, () => fixtureRuleViewModel()), | ||
}; | ||
|
||
export const RegularStreaming = Template.bind({}); | ||
RegularStreaming.decorators = [ | ||
getDecoratorWithWorker([ | ||
getMockStreamEndpoint('/api/feature/list-rules', { | ||
data: Array.from({ length: 500 }, fixtureRuleViewModel), | ||
delay: 1, | ||
}), | ||
]), | ||
]; |
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,92 @@ | ||
import { ChangeEvent, useEffect, useState } from 'react'; | ||
import { RuleViewModel } from '@/lib/infrastructure/data/view-model/rule'; | ||
import useChunkedStream, { StreamingStatus } from '@/lib/infrastructure/hooks/useChunkedStream'; | ||
import { GridApi, GridReadyEvent } from 'ag-grid-community'; | ||
import { useToast } from '@/lib/infrastructure/hooks/useToast'; | ||
import { BaseViewModelValidator } from '@/component-library/features/utils/BaseViewModelValidator'; | ||
import { alreadyStreamingToast, noApiToast } from '@/component-library/features/utils/list-toasts'; | ||
import { Heading } from '@/component-library/atoms/misc/Heading'; | ||
import { Input } from '@/component-library/atoms/form/input'; | ||
import { SearchButton } from '@/component-library/features/search/SearchButton'; | ||
import { ListRuleTable } from '@/component-library/pages/Rule/list/ListRuleTable'; | ||
|
||
type ListRuleProps = { | ||
initialData?: RuleViewModel[]; | ||
}; | ||
|
||
const DEFAULT_SCOPE = '*'; | ||
|
||
export const ListRule = (props: ListRuleProps) => { | ||
const streamingHook = useChunkedStream<RuleViewModel>(); | ||
const [scope, setScope] = useState<string>(DEFAULT_SCOPE); | ||
const [gridApi, setGridApi] = useState<GridApi<RuleViewModel> | null>(null); | ||
|
||
const { toast, dismiss } = useToast(); | ||
const validator = new BaseViewModelValidator(toast); | ||
|
||
const onGridReady = (event: GridReadyEvent) => { | ||
setGridApi(event.api); | ||
}; | ||
|
||
useEffect(() => { | ||
if (props.initialData) { | ||
onData(props.initialData); | ||
} | ||
}, [gridApi]); | ||
|
||
const onData = (data: RuleViewModel[]) => { | ||
const validData = data.filter(element => validator.isValid(element)); | ||
gridApi?.applyTransactionAsync({ add: validData }); | ||
}; | ||
|
||
const startStreaming = () => { | ||
if (gridApi) { | ||
dismiss(); | ||
gridApi.flushAsyncTransactions(); | ||
gridApi.setGridOption('rowData', []); | ||
validator.reset(); | ||
|
||
const url = `/api/feature/list-rules?scope=${scope}`; | ||
streamingHook.start({ url, onData }); | ||
} else { | ||
toast(noApiToast); | ||
} | ||
}; | ||
|
||
const isRunning = streamingHook.status === StreamingStatus.RUNNING; | ||
|
||
const onInputChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
const value = event.target.value; | ||
setScope(value !== '' ? value : DEFAULT_SCOPE); | ||
}; | ||
|
||
const onSearch = (event: any) => { | ||
event.preventDefault(); | ||
if (!isRunning) { | ||
startStreaming(); | ||
} else { | ||
toast(alreadyStreamingToast); | ||
} | ||
}; | ||
|
||
const onStop = (event: any) => { | ||
event.preventDefault(); | ||
if (isRunning) { | ||
streamingHook.stop(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col space-y-3 w-full grow"> | ||
<Heading text="Rules" /> | ||
<div className="space-y-2"> | ||
<div className="text-neutral-900 dark:text-neutral-100">Scope</div> | ||
<div className="flex flex-col space-y-2 sm:flex-row sm:space-y-0 sm:space-x-2 items-center sm:items-start"> | ||
<Input className="w-full sm:flex-grow" onChange={onInputChange} onEnterKey={onSearch} placeholder={DEFAULT_SCOPE} /> | ||
<SearchButton isRunning={isRunning} onStop={onStop} onSearch={onSearch} /> | ||
</div> | ||
</div> | ||
<ListRuleTable streamingHook={streamingHook} onGridReady={onGridReady} /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.