forked from SigNoz/signoz
-
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.
feat: dashboard variables (SigNoz#1552)
* feat: dashboard variables * fix: variable wipe on few instances * feat: error handling states * feat: eslint and tsc fixes
- Loading branch information
Pranshu Chittora
authored
Sep 9, 2022
1 parent
9e6d901
commit 461a15d
Showing
35 changed files
with
1,254 additions
and
135 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,26 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/dashboard/variables/query'; | ||
|
||
const query = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.get( | ||
`/variables/query?query=${encodeURIComponent(props.query)}`, | ||
); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
}; | ||
|
||
export default query; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
112 changes: 112 additions & 0 deletions
112
frontend/src/container/NewDashboard/DashboardSettings/General/index.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,112 @@ | ||
import { SaveOutlined } from '@ant-design/icons'; | ||
import { Col, Divider, Input, Space, Typography } from 'antd'; | ||
import AddTags from 'container/NewDashboard/DashboardSettings/General/AddTags'; | ||
import React, { useCallback, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { connect, useSelector } from 'react-redux'; | ||
import { bindActionCreators, Dispatch } from 'redux'; | ||
import { ThunkDispatch } from 'redux-thunk'; | ||
import { | ||
UpdateDashboardTitleDescriptionTags, | ||
UpdateDashboardTitleDescriptionTagsProps, | ||
} from 'store/actions'; | ||
import { AppState } from 'store/reducers'; | ||
import AppActions from 'types/actions'; | ||
import DashboardReducer from 'types/reducer/dashboards'; | ||
|
||
import { Button } from './styles'; | ||
|
||
function GeneralDashboardSettings({ | ||
updateDashboardTitleDescriptionTags, | ||
}: DescriptionOfDashboardProps): JSX.Element { | ||
const { dashboards } = useSelector<AppState, DashboardReducer>( | ||
(state) => state.dashboards, | ||
); | ||
|
||
const [selectedDashboard] = dashboards; | ||
const selectedData = selectedDashboard.data; | ||
const { title } = selectedData; | ||
const { tags } = selectedData; | ||
const { description } = selectedData; | ||
|
||
const [updatedTitle, setUpdatedTitle] = useState<string>(title); | ||
const [updatedTags, setUpdatedTags] = useState<string[]>(tags || []); | ||
const [updatedDescription, setUpdatedDescription] = useState( | ||
description || '', | ||
); | ||
|
||
const { t } = useTranslation('common'); | ||
|
||
const onSaveHandler = useCallback(() => { | ||
const dashboard = selectedDashboard; | ||
// @TODO need to update this function to take title,description,tags only | ||
updateDashboardTitleDescriptionTags({ | ||
dashboard: { | ||
...dashboard, | ||
data: { | ||
...dashboard.data, | ||
description: updatedDescription, | ||
tags: updatedTags, | ||
title: updatedTitle, | ||
}, | ||
}, | ||
}); | ||
}, [ | ||
updatedTitle, | ||
updatedTags, | ||
updatedDescription, | ||
selectedDashboard, | ||
updateDashboardTitleDescriptionTags, | ||
]); | ||
|
||
return ( | ||
<Col> | ||
<Space direction="vertical" style={{ width: '100%' }}> | ||
<div> | ||
<Typography style={{ marginBottom: '0.5rem' }}>Name</Typography> | ||
<Input | ||
value={updatedTitle} | ||
onChange={(e): void => setUpdatedTitle(e.target.value)} | ||
/> | ||
</div> | ||
|
||
<div> | ||
<Typography style={{ marginBottom: '0.5rem' }}>Description</Typography> | ||
<Input.TextArea | ||
value={updatedDescription} | ||
onChange={(e): void => setUpdatedDescription(e.target.value)} | ||
/> | ||
</div> | ||
<div> | ||
<Typography style={{ marginBottom: '0.5rem' }}>Tags</Typography> | ||
<AddTags tags={updatedTags} setTags={setUpdatedTags} /> | ||
</div> | ||
<div> | ||
<Divider /> | ||
<Button icon={<SaveOutlined />} onClick={onSaveHandler} type="primary"> | ||
{t('save')} | ||
</Button> | ||
</div> | ||
</Space> | ||
</Col> | ||
); | ||
} | ||
|
||
interface DispatchProps { | ||
updateDashboardTitleDescriptionTags: ( | ||
props: UpdateDashboardTitleDescriptionTagsProps, | ||
) => (dispatch: Dispatch<AppActions>) => void; | ||
} | ||
|
||
const mapDispatchToProps = ( | ||
dispatch: ThunkDispatch<unknown, unknown, AppActions>, | ||
): DispatchProps => ({ | ||
updateDashboardTitleDescriptionTags: bindActionCreators( | ||
UpdateDashboardTitleDescriptionTags, | ||
dispatch, | ||
), | ||
}); | ||
|
||
type DescriptionOfDashboardProps = DispatchProps; | ||
|
||
export default connect(null, mapDispatchToProps)(GeneralDashboardSettings); |
20 changes: 20 additions & 0 deletions
20
frontend/src/container/NewDashboard/DashboardSettings/General/styles.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,20 @@ | ||
import { Button as ButtonComponent, Drawer } from 'antd'; | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
margin-top: 0.5rem; | ||
`; | ||
|
||
export const Button = styled(ButtonComponent)` | ||
&&& { | ||
display: flex; | ||
align-items: center; | ||
} | ||
`; | ||
|
||
export const DrawerContainer = styled(Drawer)` | ||
.ant-drawer-header { | ||
padding: 0; | ||
border: none; | ||
} | ||
`; |
Oops, something went wrong.