Skip to content

Commit

Permalink
add archive, outputs, dataWarehouse column
Browse files Browse the repository at this point in the history
  • Loading branch information
ousmaneo committed Jun 27, 2024
1 parent 87df367 commit cdc8c3b
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ interface PluginDataWarehouse {
}>,
StreamDataWarehouse: React.ComponentType<{}>,
DataWarehouseJobs: React.ComponentType<{}>,
streamDataWarehouseTableElements: {
attributeName: string,
attributes: any,
columnRenderer: any,
}
}

declare module 'graylog-web-plugin/plugin' {
Expand All @@ -199,7 +204,6 @@ declare module 'graylog-web-plugin/plugin' {
dataTiering?: Array<DataTiering>
defaultNavigation?: Array<PluginNavigation>;
navigationItems?: Array<PluginNavigationItems>;
dataWarehouse?: Array<PluginDataWarehouse>
globalNotifications?: Array<GlobalNotification>;
fieldValueProviders?:Array<FieldValueProvider>;
// Global context providers allow to fetch and process data once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import type { Output } from 'src/stores/outputs/OutputsStore';
import { PluginStore } from 'graylog-web-plugin/plugin';

import type { Stream, StreamRule } from 'stores/streams/StreamsStore';
import type { ColumnRenderers } from 'components/common/EntityDataTable';
Expand All @@ -25,6 +27,11 @@ import type { IndexSet } from 'stores/indices/IndexSetsStore';

import StatusCell from './cells/StatusCell';
import StreamRulesCell from './cells/StreamRulesCell';
import PipelinesCell from './cells/PipelinesCell';
import OutputsCell from './cells/OutputsCell';
import ArchivingsCell from './cells/ArchivingsCell';

const streamDataWarehouseColumnRenderer = PluginStore.exports('dataWarehouse')?.[0]?.streamDataWarehouseTableElements.columnRenderer;

const customColumnRenderers = (indexSets: Array<IndexSet>): ColumnRenderers<Stream> => ({
attributes: {
Expand All @@ -47,6 +54,19 @@ const customColumnRenderers = (indexSets: Array<IndexSet>): ColumnRenderers<Stre
renderCell: (_rules: StreamRule[], stream) => <StreamRulesCell stream={stream} />,
staticWidth: 130,
},
pipelines: {
renderCell: (_pipeline: any[], stream) => <PipelinesCell stream={stream} />,
staticWidth: 130,
},
outputs: {
renderCell: (_outputs: Output[], stream) => <OutputsCell stream={stream} />,
staticWidth: 130,
},
archiving: {
renderCell: (_archiving:boolean, stream) => <ArchivingsCell stream={stream} indexSets={indexSets} />,
staticWidth: 130,
},
...(streamDataWarehouseColumnRenderer || {}),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,47 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import { PluginStore } from 'graylog-web-plugin/plugin';

import type { Sort, Attribute } from 'stores/PaginationTypes';

const streamDataWarehousePlugin = PluginStore.exports('dataWarehouse')?.[0]?.streamDataWarehouseTableElements;
export const DEFAULT_LAYOUT = {
entityTableId: 'streams',
defaultPageSize: 20,
defaultSort: { attributeId: 'title', direction: 'asc' } as Sort,
defaultDisplayedAttributes: ['title', 'index_set_title', 'rules', 'throughput', 'disabled'],
defaultDisplayedAttributes: [
'title',
'index_set_title',
'archiving',
...streamDataWarehousePlugin?.attributeName ? [streamDataWarehousePlugin.attributeName] : [],
'rules',
'pipelines',
'outputs',
'throughput',
'disabled',
],
};

export const COLUMNS_ORDER = ['title', 'index_set_title', 'rules', 'throughput', 'disabled', 'created_at'];
export const COLUMNS_ORDER = [
'title',
'index_set_title',
'archiving',
...streamDataWarehousePlugin?.attributeName ? [streamDataWarehousePlugin.attributeName] : [],
'rules',
'pipelines',
'outputs',
'throughput',
'disabled',
'created_at',
];

export const ADDITIONAL_ATTRIBUTES: Array<Attribute> = [
{ id: 'index_set_title', title: 'Index Set', sortable: true, permissions: ['indexsets:read'] },
{ id: 'throughput', title: 'Throughput' },
{ id: 'rules', title: 'Rules' },
{ id: 'pipelines', title: 'Pipelines' },
{ id: 'outputs', title: 'Outputs' },
{ id: 'archiving', title: 'Archiving' },
...(streamDataWarehousePlugin?.attributes || []),
];
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Props = {

const StreamsOverview = ({ indexSets }: Props) => {
const queryClient = useQueryClient();

const { entityActions, expandedSections, bulkActions } = useTableElements({ indexSets });
useRefetchStreamsOnStoreChange(() => queryClient.invalidateQueries(KEY_PREFIX));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import * as React from 'react';
import styled, { css } from 'styled-components';

import type { Stream } from 'stores/streams/StreamsStore';
import { Icon, Tooltip } from 'components/common';
import type { IndexSet } from 'stores/indices/IndexSetsStore';
import { ARCHIVE_RETENTION_STRATEGY } from 'stores/indices/IndicesStore';

type Props = {
stream: Stream,
indexSets: Array<IndexSet>,
}

const Wrapper = styled.div<{ $enabled: boolean }>(({ theme, $enabled }) => css`
color: ${$enabled ? theme.colors.variant.success : theme.colors.variant.default};
width: fit-content;
`);

const ArchivingsCell = ({ stream, indexSets }: Props) => {
if (stream.is_default || !stream.is_editable) {
return null;
}

const indexSet = indexSets.find((is) => is.id === stream.index_set_id);

const archivingEnabled = indexSet?.retention_strategy_class === ARCHIVE_RETENTION_STRATEGY || indexSet?.data_tiering?.archive_before_deletion;

return (
<Tooltip withArrow position="right" label={`Archiving is ${archivingEnabled ? 'enabled' : 'disabled'}`}>
<Wrapper $enabled={archivingEnabled}>
<Icon name={archivingEnabled ? 'check_circle' : 'cancel'} />
</Wrapper>
</Tooltip>
);
};

export default ArchivingsCell;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import { useRef } from 'react';
import * as React from 'react';
import styled from 'styled-components';

import type { Stream } from 'stores/streams/StreamsStore';
import { CountBadge } from 'components/common';

const StyledCountBadge = styled(CountBadge)`
cursor: pointer;
`;

type Props = {
stream: Stream
}

const OutputsCell = ({ stream }: Props) => {
const buttonRef = useRef();

if (stream.is_default || !stream.is_editable) {
return null;
}

return (
<StyledCountBadge ref={buttonRef} title="Stream Outputs">
{stream.outputs?.length || 0}
</StyledCountBadge>
);
};

export default OutputsCell;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import { useRef } from 'react';
import * as React from 'react';
import styled from 'styled-components';

import useStreamOutputs from 'hooks/useStreamOutputs';
import type { Stream } from 'stores/streams/StreamsStore';
import { CountBadge } from 'components/common';

const StyledCountBadge = styled(CountBadge)`
cursor: pointer;
`;

type Props = {
stream: Stream
}

const PipelinesCell = ({ stream }: Props) => {
const buttonRef = useRef();
const { data, isInitialLoading, isError } = useStreamOutputs(stream.id);

if (stream.is_default || !stream.is_editable || isInitialLoading || isError) {
return null;
}

return (
<StyledCountBadge ref={buttonRef} title="Connected pipelines">
{data.outputs.length}
</StyledCountBadge>
);
};

export default PipelinesCell;

0 comments on commit cdc8c3b

Please sign in to comment.