Skip to content

Commit

Permalink
Format the code and fix failing build
Browse files Browse the repository at this point in the history
  • Loading branch information
MytsV committed Sep 15, 2024
1 parent 22c5538 commit 1f1208b
Show file tree
Hide file tree
Showing 55 changed files with 1,305 additions and 1,215 deletions.
16 changes: 0 additions & 16 deletions src/component-library/demos/03_2_List_Rules.stories.tsx

This file was deleted.

42 changes: 21 additions & 21 deletions src/component-library/features/badges/Rule/RuleStateBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +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";
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"
[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"
[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 }) => {
export const RuleStateBadge = (props: { value: RuleState; className?: string }) => {
const classes = cn(stateColorClasses[props.value], props.className);
return <Badge value={stateString[props.value]} className={classes}/>
}
return <Badge value={stateString[props.value]} className={classes} />;
};
2 changes: 1 addition & 1 deletion src/component-library/features/utils/filter-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ const dateComparator = (filterLocalDateAtMidnight: Date, cellValue: string | Dat
export const DefaultDateFilterParams = {
maxNumConditions: 1,
comparator: dateComparator,
buttons: ['reset']
buttons: ['reset'],
};
2 changes: 1 addition & 1 deletion src/component-library/features/utils/text-formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export const formatSeconds = (seconds: number): string => {
} else {
return DEFAULT_VALUE;
}
}
};
2 changes: 1 addition & 1 deletion src/component-library/pages/DID/list/ListDID.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const ListDID = (props: ListDIDProps) => {

const queryMeta = async () => {
if (selectedItem !== null) {
const params = new URLSearchParams({scope: selectedItem.scope, name: selectedItem.name});
const params = new URLSearchParams({ scope: selectedItem.scope, name: selectedItem.name });
const url = '/api/feature/get-did-meta?' + params;

const res = await fetch(url);
Expand Down
2 changes: 1 addition & 1 deletion src/component-library/pages/RSE/list/ListRSE.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Template: StoryFn<typeof ListRSE> = args => (
);

// We don't want to generate several of these
const smallList = Array.from({ length: 20 }, fixtureRSEViewModel);
const smallList = Array.from({ length: 20 }, fixtureRSEViewModel);
const mediumList = Array.from({ length: 140 }, fixtureRSEViewModel);
const hugeList = Array.from({ length: 100000 }, fixtureRSEViewModel);
const endpointUrl = '/api/feature/list-rses';
Expand Down
28 changes: 15 additions & 13 deletions src/component-library/pages/Rule/list/ListRule.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +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";
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>;
const Template: StoryFn<typeof ListRule> = args => (
<ToastedTemplate>
<ListRule {...args} />
</ToastedTemplate>
);

export const InitialDataNoEndpoint = Template.bind({});
InitialDataNoEndpoint.args = {
initialData: Array.from({length: 50}, () => fixtureRuleViewModel()),
}
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),
data: Array.from({ length: 500 }, fixtureRuleViewModel),
delay: 1,
}),
]),
];
];
50 changes: 21 additions & 29 deletions src/component-library/pages/Rule/list/ListRule.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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";
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 = '*';

Expand All @@ -21,7 +21,7 @@ export const ListRule = (props: ListRuleProps) => {
const [scope, setScope] = useState<string>(DEFAULT_SCOPE);
const [gridApi, setGridApi] = useState<GridApi<RuleViewModel> | null>(null);

const {toast, dismiss} = useToast();
const { toast, dismiss } = useToast();
const validator = new BaseViewModelValidator(toast);

const onGridReady = (event: GridReadyEvent) => {
Expand All @@ -36,7 +36,7 @@ export const ListRule = (props: ListRuleProps) => {

const onData = (data: RuleViewModel[]) => {
const validData = data.filter(element => validator.isValid(element));
gridApi?.applyTransactionAsync({add: validData});
gridApi?.applyTransactionAsync({ add: validData });
};

const startStreaming = () => {
Expand All @@ -47,7 +47,7 @@ export const ListRule = (props: ListRuleProps) => {
validator.reset();

const url = `/api/feature/list-rules?scope=${scope}`;
streamingHook.start({url, onData});
streamingHook.start({ url, onData });
} else {
toast(noApiToast);
}
Expand Down Expand Up @@ -78,23 +78,15 @@ export const ListRule = (props: ListRuleProps) => {

return (
<div className="flex flex-col space-y-3 w-full grow">
<Heading text="Rules"/>
<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 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}/>
<ListRuleTable streamingHook={streamingHook} onGridReady={onGridReady} />
</div>
);
};
33 changes: 15 additions & 18 deletions src/component-library/pages/Rule/list/ListRuleTable.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React, {useRef, useState} from 'react';
import {AgGridReact} from 'ag-grid-react';
import {UseChunkedStream} from '@/lib/infrastructure/hooks/useChunkedStream';
import {StreamedTable} from '@/component-library/features/table/StreamedTable/StreamedTable';
import {ClickableCell} from '@/component-library/features/table/cells/ClickableCell';
import {badgeCellClasses, badgeCellWrapperStyle} from '@/component-library/features/table/cells/badge-cell';
import {
DefaultTextFilterParams,
DefaultDateFilterParams, buildDiscreteFilterParams
} from '@/component-library/features/utils/filter-parameters';
import {GridReadyEvent, ValueFormatterParams} from 'ag-grid-community';
import {RuleViewModel} from "@/lib/infrastructure/data/view-model/rule";
import {formatDate, formatSeconds} from "@/component-library/features/utils/text-formatters";
import {RuleStateBadge} from "@/component-library/features/badges/Rule/RuleStateBadge";
import {RuleState} from "@/lib/core/entity/rucio";
import React, { useRef, useState } from 'react';
import { AgGridReact } from 'ag-grid-react';
import { UseChunkedStream } from '@/lib/infrastructure/hooks/useChunkedStream';
import { StreamedTable } from '@/component-library/features/table/StreamedTable/StreamedTable';
import { ClickableCell } from '@/component-library/features/table/cells/ClickableCell';
import { badgeCellClasses, badgeCellWrapperStyle } from '@/component-library/features/table/cells/badge-cell';
import { DefaultTextFilterParams, DefaultDateFilterParams, buildDiscreteFilterParams } from '@/component-library/features/utils/filter-parameters';
import { GridReadyEvent, ValueFormatterParams } from 'ag-grid-community';
import { RuleViewModel } from '@/lib/infrastructure/data/view-model/rule';
import { formatDate, formatSeconds } from '@/component-library/features/utils/text-formatters';
import { RuleStateBadge } from '@/component-library/features/badges/Rule/RuleStateBadge';
import { RuleState } from '@/lib/core/entity/rucio';

type ListRuleTableProps = {
streamingHook: UseChunkedStream<RuleViewModel>;
Expand Down Expand Up @@ -73,8 +70,8 @@ export const ListRuleTable = (props: ListRuleTableProps) => {
minWidth: 125,
maxWidth: 125,
valueFormatter: (params: ValueFormatterParams) => {
return formatSeconds(params.value)
}
return formatSeconds(params.value);
},
},
{
headerName: 'State',
Expand Down Expand Up @@ -112,7 +109,7 @@ export const ListRuleTable = (props: ListRuleTableProps) => {
minWidth: 90,
maxWidth: 90,
sortable: false,
}
},
]);

return <StreamedTable columnDefs={columnDefs} tableRef={tableRef} {...props} />;
Expand Down
Loading

0 comments on commit 1f1208b

Please sign in to comment.