forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Drag and Drop plugin code (opensearch-project#946)
* Initial Drag and Drop plugin code Signed-off-by: Ashwin Pc <[email protected]>
- Loading branch information
Showing
41 changed files
with
1,317 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"prefix": "wizard", | ||
"paths": { | ||
"wizard": "." | ||
}, | ||
"translations": ["translations/ja-JP.json"] | ||
} |
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,11 @@ | ||
# wizard | ||
|
||
A OpenSearch Dashboards plugin | ||
|
||
--- | ||
|
||
## Development | ||
|
||
See the [OpenSearch Dashboards contributing | ||
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/master/CONTRIBUTING.md) for instructions | ||
setting up your development environment. |
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,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const PLUGIN_ID = 'wizard'; | ||
export const PLUGIN_NAME = 'Wizard'; | ||
|
||
export { WizardSavedObjectAttributes, WIZARD_SAVED_OBJECT } from './wizard_saved_object_attributes'; |
14 changes: 14 additions & 0 deletions
14
src/plugins/wizard/common/wizard_saved_object_attributes.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,14 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectAttributes } from 'opensearch-dashboards/public'; | ||
|
||
export const WIZARD_SAVED_OBJECT = 'wizard'; | ||
|
||
export interface WizardSavedObjectAttributes extends SavedObjectAttributes { | ||
title: string; | ||
description?: string; | ||
state: string; | ||
} |
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,16 @@ | ||
{ | ||
"id": "wizard", | ||
"version": "1.0.0", | ||
"opensearchDashboardsVersion": "opensearchDashboards", | ||
"server": true, | ||
"ui": true, | ||
"requiredPlugins": [ | ||
"navigation", | ||
"data", | ||
"opensearchDashboardsReact", | ||
"savedObjects", | ||
"embeddable", | ||
"dashboard" | ||
], | ||
"optionalPlugins": [] | ||
} |
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,3 @@ | ||
@import '@elastic/eui/src/global_styling/variables/header'; | ||
|
||
$osdHeaderOffset: $euiHeaderHeightCompensation * 2; |
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,13 @@ | ||
@import "variables"; | ||
|
||
.wizLayout { | ||
padding: 0; | ||
display: grid; | ||
grid-template-rows: min-content 1fr; | ||
grid-template-columns: 420px 1fr; | ||
grid-template-areas: | ||
"topNav topNav" | ||
"sideNav workspace" | ||
; | ||
height: calc(100vh - #{$osdHeaderOffset}); // TODO: update 190px to correct offset variable | ||
} |
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,54 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import { I18nProvider } from '@osd/i18n/react'; | ||
import { EuiPage } from '@elastic/eui'; | ||
import { DataPublicPluginStart, IndexPattern } from '../../../data/public'; | ||
import { SideNav } from './components/side_nav'; | ||
import { DragDropProvider } from './utils/drag_drop/drag_drop_context'; | ||
import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public'; | ||
import { WizardServices } from '../types'; | ||
import { Workspace } from './components/workspace'; | ||
|
||
import './app.scss'; | ||
import { TopNav } from './components/top_nav'; | ||
|
||
export const WizardApp = () => { | ||
const { | ||
services: { data }, | ||
} = useOpenSearchDashboards<WizardServices>(); | ||
|
||
const [indexPattern, setIndexPattern] = useIndexPattern(data); | ||
|
||
// Render the application DOM. | ||
return ( | ||
<I18nProvider> | ||
<DragDropProvider> | ||
<EuiPage className="wizLayout"> | ||
<TopNav /> | ||
<SideNav indexPattern={indexPattern} setIndexPattern={setIndexPattern} /> | ||
<Workspace /> | ||
</EuiPage> | ||
</DragDropProvider> | ||
</I18nProvider> | ||
); | ||
}; | ||
|
||
// TODO: Temporary. Need to update it fetch the index pattern cohesively | ||
function useIndexPattern(data: DataPublicPluginStart) { | ||
const [indexPattern, setIndexPattern] = useState<IndexPattern | null>(null); | ||
useEffect(() => { | ||
const fetchIndexPattern = async () => { | ||
const defaultIndexPattern = await data.indexPatterns.getDefault(); | ||
if (defaultIndexPattern) { | ||
setIndexPattern(defaultIndexPattern); | ||
} | ||
}; | ||
fetchIndexPattern(); | ||
}, [data.indexPatterns]); | ||
|
||
return [indexPattern, setIndexPattern] as const; | ||
} |
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,8 @@ | ||
@mixin scrollNavParent ($template-row: none) { | ||
display: grid; | ||
min-height: 0; | ||
|
||
@if $template-row != 'none' { | ||
grid-template-rows: $template-row; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/plugins/wizard/public/application/components/data_tab/config_panel.scss
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,9 @@ | ||
.wizConfigPanel { | ||
background: #f0f1f3; | ||
border-left: $euiBorderThin; | ||
padding: $euiSizeS; | ||
} | ||
|
||
.wizConfigPanel__title { | ||
margin-left: $euiSizeS; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/plugins/wizard/public/application/components/data_tab/config_panel.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,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiForm, EuiTitle } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { BUCKET_TYPES, METRIC_TYPES } from '../../../../../data/public'; | ||
import { ConfigSection } from './config_section'; | ||
|
||
import './config_panel.scss'; | ||
|
||
// TODO: Temp. Remove once visualizations can be refgistered and editor configs can be passed along | ||
const CONFIG = { | ||
x: { | ||
title: 'X Axis', | ||
allowedAggregation: BUCKET_TYPES.TERMS, | ||
}, | ||
y: { | ||
title: 'Y Axis', | ||
allowedAggregation: METRIC_TYPES.AVG, | ||
}, | ||
}; | ||
|
||
export function ConfigPanel() { | ||
const sections = CONFIG; | ||
|
||
return ( | ||
<EuiForm className="wizConfigPanel"> | ||
<EuiTitle size="xxxs"> | ||
<h2 className="wizConfigPanel__title"> | ||
{i18n.translate('wizard.nav.dataTab.configPanel.title', { | ||
defaultMessage: 'Configuration', | ||
})} | ||
</h2> | ||
</EuiTitle> | ||
{Object.entries(sections).map(([sectionId, sectionProps], index) => ( | ||
<ConfigSection key={index} id={sectionId} {...sectionProps} onChange={() => {}} /> | ||
))} | ||
</EuiForm> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/plugins/wizard/public/application/components/data_tab/config_section.scss
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,23 @@ | ||
.wizConfigSection { | ||
margin-top: $euiSize; | ||
border-bottom: $euiBorderThin; | ||
padding-bottom: $euiSize; | ||
|
||
&:last-child { | ||
border-bottom: none; | ||
} | ||
|
||
& .euiFormRow__labelWrapper { | ||
margin-left: $euiSizeS; | ||
} | ||
} | ||
|
||
.wizConfigSection__dropTarget { | ||
@include euiSlightShadow; | ||
background: $euiColorEmptyShade; | ||
border: $euiBorderThin; | ||
box-shadow: 0px 2px 2px rgba(152, 162, 179, 0.15); | ||
border-radius: $euiBorderRadius; | ||
padding: $euiSizeS $euiSizeM; | ||
color: $euiColorDarkShade; | ||
} |
62 changes: 62 additions & 0 deletions
62
src/plugins/wizard/public/application/components/data_tab/config_section.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,62 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiButtonIcon, EuiFormRow, EuiPanel, EuiText } from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import { IndexPatternField } from 'src/plugins/data/common'; | ||
import { useDrop } from '../../utils/drag_drop'; | ||
|
||
import './config_section.scss'; | ||
|
||
interface ConfigSectionProps { | ||
id: string; | ||
title: string; | ||
onChange: Function; | ||
} | ||
|
||
export const ConfigSection = ({ title, id, onChange }: ConfigSectionProps) => { | ||
const [currentField, setCurrentField] = useState<IndexPatternField>(); | ||
|
||
const dropHandler = useCallback((field: IndexPatternField) => { | ||
setCurrentField(field); | ||
}, []); | ||
const [dropProps, { isValidDropTarget, dragData }] = useDrop('dataPlane', dropHandler); | ||
|
||
const dropTargetString = dragData | ||
? dragData.type | ||
: i18n.translate('wizard.nav.dataTab.configPanel.dropTarget.placeholder', { | ||
defaultMessage: 'Click or drop to add', | ||
}); | ||
|
||
useEffect(() => { | ||
onChange(id, currentField); | ||
}, [id, currentField, onChange]); | ||
|
||
return ( | ||
<EuiFormRow label={title} className="wizConfigSection"> | ||
{currentField ? ( | ||
<EuiPanel paddingSize="s" className="wizConfigSection__field"> | ||
<EuiText grow size="m"> | ||
{currentField.displayName} | ||
</EuiText> | ||
<EuiButtonIcon | ||
color="danger" | ||
iconType="cross" | ||
aria-label="clear-field" | ||
onClick={() => setCurrentField(undefined)} | ||
/> | ||
</EuiPanel> | ||
) : ( | ||
<div | ||
className={`wizConfigSection__dropTarget ${isValidDropTarget && 'validDropTarget'}`} | ||
{...dropProps} | ||
> | ||
<EuiText size="s">{dropTargetString}</EuiText> | ||
</div> | ||
)} | ||
</EuiFormRow> | ||
); | ||
}; |
10 changes: 10 additions & 0 deletions
10
src/plugins/wizard/public/application/components/data_tab/field_selector.scss
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,10 @@ | ||
@import "../util"; | ||
|
||
.wizFieldSelector { | ||
@include scrollNavParent(auto 1fr); | ||
padding: $euiSizeS; | ||
} | ||
|
||
.wizFieldSelector__fieldGroups { | ||
overflow-y: auto; | ||
} |
Oops, something went wrong.