Skip to content

Commit

Permalink
feat: add filter compaction level
Browse files Browse the repository at this point in the history
Signed-off-by: Shafiya Adzhani <adz.arsym@gmail.com>
  • Loading branch information
adzshaf authored and Ben Ye committed Nov 6, 2021
1 parent 65c5bc5 commit c7d29b0
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
34 changes: 34 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/BlockFilterCompaction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { FC, ChangeEvent } from 'react';
import Checkbox from '../../../components/Checkbox';
import { Input } from 'reactstrap';
import styles from './blocks.module.css';

interface BlockFilterCompactionProps {
id: string;
defaultChecked: boolean;
onChangeCheckbox: ({ target }: ChangeEvent<HTMLInputElement>) => void;
onChangeInput: ({ target }: ChangeEvent<HTMLInputElement>) => void;
defaultValue: string;
}

export const BlockFilterCompaction: FC<BlockFilterCompactionProps> = ({
id,
defaultChecked,
onChangeCheckbox,
onChangeInput,
defaultValue,
}) => {
return (
<div className={styles.blockFilter}>
<Checkbox style={{ marginRight: '4px' }} id={id} defaultChecked={defaultChecked} onChange={onChangeCheckbox} />
<p style={{ marginRight: '4px' }}>Filter by compaction level</p>
<Input
type="number"
style={{ width: '100px', marginBottom: '1rem' }}
onChange={onChangeInput}
defaultValue={defaultValue}
min={0}
/>
</div>
);
};
25 changes: 25 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/Blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Block } from './block';
import { SourceView } from './SourceView';
import { BlockDetails } from './BlockDetails';
import { BlockSearchInput } from './BlockSearchInput';
import { BlockFilterCompaction } from './BlockFilterCompaction';
import { sortBlocks } from './helpers';
import styles from './blocks.module.css';
import TimeRange from './TimeRange';
Expand All @@ -24,6 +25,10 @@ export interface BlockListProps {
export const BlocksContent: FC<{ data: BlockListProps }> = ({ data }) => {
const [selectedBlock, selectBlock] = useState<Block>();
const [searchState, setSearchState] = useState<string>('');
const [filterCompaction, setFilterCompaction] = useState<boolean>(false);
const [compactionLevel, setCompactionLevel] = useState<number>(0);
const [compactionLevelInput, setCompactionLevelInput] = useState<string>('0');

const { blocks, label, err } = data;

const [gridMinTime, gridMaxTime] = useMemo(() => {
Expand Down Expand Up @@ -95,6 +100,25 @@ export const BlocksContent: FC<{ data: BlockListProps }> = ({ data }) => {
>
Enable finding overlapping blocks
</Checkbox>
<BlockFilterCompaction
id="filter-compaction-checkbox"
defaultChecked={filterCompaction}
onChangeCheckbox={({ target }) => {
setFilterCompaction(target.checked);
if (target.checked) {
setCompactionLevel(parseInt(compactionLevelInput));
} else {
setCompactionLevel(0);
}
}}
onChangeInput={({ target }: ChangeEvent<HTMLInputElement>): void => {
if (filterCompaction) {
setCompactionLevel(parseInt(target.value));
}
setCompactionLevelInput(target.value);
}}
defaultValue={compactionLevelInput}
/>
<div className={styles.container}>
<div className={styles.grid}>
<div className={styles.sources}>
Expand All @@ -107,6 +131,7 @@ export const BlocksContent: FC<{ data: BlockListProps }> = ({ data }) => {
gridMinTime={viewMinTime}
gridMaxTime={viewMaxTime}
blockSearch={blockSearch}
compactionLevel={compactionLevel}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Blocks SourceView', () => {
gridMinTime: 1596096000000,
gridMaxTime: 1595108031471,
blockSearch: '',
compactionLevel: 0,
};

const sourceView = mount(<SourceView {...defaultProps} />);
Expand Down
20 changes: 16 additions & 4 deletions pkg/ui/react-app/src/thanos/pages/blocks/SourceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import React, { FC } from 'react';
import { Block, BlocksPool } from './block';
import { BlockSpan } from './BlockSpan';
import styles from './blocks.module.css';
import { getBlockByUlid } from './helpers';
import { getBlockByUlid, getBlocksByCompactionLevel } from './helpers';

export const BlocksRow: FC<{
blocks: Block[];
gridMinTime: number;
gridMaxTime: number;
selectBlock: React.Dispatch<React.SetStateAction<Block | undefined>>;
blockSearch: string;
}> = ({ blocks, gridMinTime, gridMaxTime, selectBlock, blockSearch }) => {
const blockSearchValue = getBlockByUlid(blocks, blockSearch);
compactionLevel: number;
}> = ({ blocks, gridMinTime, gridMaxTime, selectBlock, blockSearch, compactionLevel }) => {
let blockSearchValue = getBlockByUlid(blocks, blockSearch);
blockSearchValue = getBlocksByCompactionLevel(blockSearchValue, compactionLevel);

return (
<div className={styles.row}>
Expand All @@ -29,9 +31,18 @@ export interface SourceViewProps {
gridMaxTime: number;
selectBlock: React.Dispatch<React.SetStateAction<Block | undefined>>;
blockSearch: string;
compactionLevel: number;
}

export const SourceView: FC<SourceViewProps> = ({ data, title, gridMaxTime, gridMinTime, selectBlock, blockSearch }) => {
export const SourceView: FC<SourceViewProps> = ({
data,
title,
gridMaxTime,
gridMinTime,
selectBlock,
blockSearch,
compactionLevel,
}) => {
return (
<>
<div className={styles.source}>
Expand All @@ -49,6 +60,7 @@ export const SourceView: FC<SourceViewProps> = ({ data, title, gridMaxTime, grid
gridMaxTime={gridMaxTime}
gridMinTime={gridMinTime}
blockSearch={blockSearch}
compactionLevel={compactionLevel}
/>
))}
</React.Fragment>
Expand Down
6 changes: 6 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/blocks.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@
.blockInput {
margin-bottom: 12px;
}

.blockFilter {
display: flex;
flex-direction: row;
align-items: center;
}
9 changes: 9 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,12 @@ export const getBlockByUlid = (blocks: Block[], ulid: string): Block[] => {
const blockResult = blocks.filter((block, index) => resultIndex.includes(index));
return blockResult;
};

export const getBlocksByCompactionLevel = (blocks: Block[], compactionLevel: number): Block[] => {
if (compactionLevel === 0 || Number.isNaN(compactionLevel)) {
return blocks;
}

const blockResult = blocks.filter((block) => block.compaction.level === compactionLevel);
return blockResult;
};

0 comments on commit c7d29b0

Please sign in to comment.