-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Vis Builder] Add an experimental table visualization in vis builder #2705
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1030e4
[Vis Builder] Add an experimental table visualization in vis builder
ananzh a52185d
remove unused scss tyle
ananzh c0c463f
remove total func and percentage col
ananzh 4136f0a
comment out cellActions
ananzh bc8af31
Merge branch 'main' into visBuilder-table
ananzh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
109 changes: 109 additions & 0 deletions
109
src/plugins/vis_builder/public/visualizations/table/components/table_viz_options.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,109 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { get } from 'lodash'; | ||
import React, { useCallback, useEffect, useMemo } from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { FormattedMessage } from '@osd/i18n/react'; | ||
import produce from 'immer'; | ||
import { Draft } from 'immer'; | ||
import { EuiIconTip } from '@elastic/eui'; | ||
import { search } from '../../../../../data/public'; | ||
import { NumberInputOption, SwitchOption } from '../../../../../charts/public'; | ||
import { | ||
useTypedDispatch, | ||
useTypedSelector, | ||
setStyleState, | ||
} from '../../../application/utils/state_management'; | ||
import { TableOptionsDefaults } from '../table_viz_type'; | ||
import { Option } from '../../../application/app'; | ||
|
||
function TableVizOptions() { | ||
const styleState = useTypedSelector((state) => state.style) as TableOptionsDefaults; | ||
const dispatch = useTypedDispatch(); | ||
|
||
const setOption = useCallback( | ||
(callback: (draft: Draft<typeof styleState>) => void) => { | ||
const newState = produce(styleState, callback); | ||
dispatch(setStyleState<TableOptionsDefaults>(newState)); | ||
}, | ||
[dispatch, styleState] | ||
); | ||
|
||
const isPerPageValid = styleState.perPage === '' || styleState.perPage > 0; | ||
|
||
return ( | ||
<> | ||
<Option | ||
title={i18n.translate('visTypeTableNewNew.params.settingsTitle', { | ||
defaultMessage: 'Settings', | ||
})} | ||
initialIsOpen | ||
> | ||
<NumberInputOption | ||
label={ | ||
<> | ||
{i18n.translate('visTypeTableNewNew.params.perPageLabel', { | ||
defaultMessage: 'Max rows per page', | ||
})} | ||
<EuiIconTip | ||
content={ | ||
<FormattedMessage | ||
id="visTypeTableNewNews.field.emptyTooltip" | ||
defaultMessage="Leaving this field empty means it will use number of buckets from the response." | ||
ananzh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
} | ||
position="right" | ||
/> | ||
</> | ||
} | ||
isInvalid={!isPerPageValid} | ||
min={1} | ||
paramName="perPage" | ||
value={styleState.perPage} | ||
setValue={(_, value) => | ||
setOption((draft) => { | ||
draft.perPage = value; | ||
}) | ||
} | ||
/> | ||
|
||
<SwitchOption | ||
label={i18n.translate('visTypeTableNewNew.params.showMetricsLabel', { | ||
ananzh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultMessage: 'Show metrics for every bucket/level', | ||
})} | ||
paramName="showMetricsAtAllLevels" | ||
value={styleState.showMetricsAtAllLevels} | ||
setValue={(_, value) => | ||
setOption((draft) => { | ||
draft.showMetricsAtAllLevels = value; | ||
}) | ||
} | ||
data-test-subj="showMetricsAtAllLevels" | ||
/> | ||
|
||
<SwitchOption | ||
label={i18n.translate('visTypeTableNewNew.params.showPartialRowsLabel', { | ||
defaultMessage: 'Show partial rows', | ||
})} | ||
tooltip={i18n.translate('visTypeTableNewNew.params.showPartialRowsTip', { | ||
defaultMessage: | ||
'Show rows that have partial data. This will still calculate metrics for every bucket/level, even if they are not displayed.', | ||
})} | ||
paramName="showPartialRows" | ||
value={styleState.showPartialRows} | ||
setValue={(_, value) => | ||
setOption((draft) => { | ||
draft.showPartialRows = value; | ||
}) | ||
} | ||
data-test-subj="showPartialRows" | ||
/> | ||
</Option> | ||
</> | ||
); | ||
} | ||
|
||
export { TableVizOptions }; |
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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { createTableConfig } from './table_viz_type'; |
95 changes: 95 additions & 0 deletions
95
src/plugins/vis_builder/public/visualizations/table/table_viz_type.ts
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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { Schemas } from '../../../../vis_default_editor/public'; | ||
import { AggGroupNames } from '../../../../data/public'; | ||
import { TableVizOptions } from './components/table_viz_options'; | ||
import { VisualizationTypeOptions } from '../../services/type_service'; | ||
import { toExpression } from './to_expression'; | ||
|
||
export interface TableOptionsDefaults { | ||
perPage: number | ''; | ||
showPartialRows: boolean; | ||
showMetricsAtAllLevels: boolean; | ||
} | ||
|
||
export const createTableConfig = (): VisualizationTypeOptions<TableOptionsDefaults> => ({ | ||
name: 'table', | ||
title: 'Table', | ||
icon: 'visTable', | ||
description: 'Display table visualizations', | ||
toExpression, | ||
ui: { | ||
containerConfig: { | ||
data: { | ||
schemas: new Schemas([ | ||
{ | ||
group: AggGroupNames.Metrics, | ||
name: 'metric', | ||
title: i18n.translate('visTypeTableNewNew.tableVisEditorConfig.schemas.metricTitle', { | ||
defaultMessage: 'Metric', | ||
}), | ||
min: 1, | ||
aggFilter: ['!geo_centroid', '!geo_bounds'], | ||
aggSettings: { | ||
top_hits: { | ||
allowStrings: true, | ||
}, | ||
}, | ||
defaults: { | ||
aggTypes: ['avg', 'cardinality'], | ||
}, | ||
}, | ||
{ | ||
group: AggGroupNames.Buckets, | ||
name: 'bucket', | ||
title: i18n.translate('visTypeTableNewNew.tableVisEditorConfig.schemas.bucketTitle', { | ||
defaultMessage: 'Split rows', | ||
}), | ||
aggFilter: ['!filter'], | ||
defaults: { | ||
aggTypes: ['terms'], | ||
}, | ||
}, | ||
{ | ||
group: AggGroupNames.Buckets, | ||
name: 'split_row', | ||
title: i18n.translate('visTypeTableNewNew.tableVisEditorConfig.schemas.splitTitle', { | ||
defaultMessage: 'Split table in rows', | ||
}), | ||
min: 0, | ||
max: 1, | ||
aggFilter: ['!filter'], | ||
defaults: { | ||
aggTypes: ['terms'], | ||
}, | ||
}, | ||
{ | ||
group: AggGroupNames.Buckets, | ||
name: 'split_column', | ||
title: i18n.translate('visTypeTableNewNew.tableVisEditorConfig.schemas.splitTitle', { | ||
defaultMessage: 'Split table in columns', | ||
}), | ||
min: 0, | ||
max: 1, | ||
aggFilter: ['!filter'], | ||
defaults: { | ||
aggTypes: ['terms'], | ||
}, | ||
}, | ||
]), | ||
}, | ||
style: { | ||
defaults: { | ||
perPage: 10, | ||
showPartialRows: false, | ||
showMetricsAtAllLevels: false, | ||
}, | ||
render: TableVizOptions, | ||
}, | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!