feat: store display type in URL

This commit is contained in:
Yury Moladau 2021-11-23 19:03:17 +03:00
parent e3534dca20
commit ccc242c69a
3 changed files with 10 additions and 6 deletions

View File

@ -12,8 +12,12 @@ export type DisplayType = "table" | "chart" | "code";
const StylizedToggleButton = withStyles({ const StylizedToggleButton = withStyles({
root: { root: {
padding: 6, display: "grid",
gridTemplateColumns: "18px auto",
gridGap: 6,
padding: "8px 12px",
color: "white", color: "white",
lineHeight: "19px",
"&.Mui-selected": { "&.Mui-selected": {
color: "white" color: "white"
} }
@ -34,13 +38,13 @@ export const DisplayTypeSwitch: FC = () => {
dispatch({type: "SET_DISPLAY_TYPE", payload: val ?? displayType}) dispatch({type: "SET_DISPLAY_TYPE", payload: val ?? displayType})
}> }>
<StylizedToggleButton value="chart" aria-label="display as chart"> <StylizedToggleButton value="chart" aria-label="display as chart">
<ShowChartIcon/>&nbsp;Query Range as Chart <ShowChartIcon/><span>Query Range as Chart</span>
</StylizedToggleButton> </StylizedToggleButton>
<StylizedToggleButton value="code" aria-label="display as code"> <StylizedToggleButton value="code" aria-label="display as code">
<CodeIcon/>&nbsp;Instant Query as JSON <CodeIcon/><span>Instant Query as JSON</span>
</StylizedToggleButton> </StylizedToggleButton>
<StylizedToggleButton value="table" aria-label="display as table"> <StylizedToggleButton value="table" aria-label="display as table">
<TableChartIcon/>&nbsp;Instant Query as Table <TableChartIcon/><span>Instant Query as Table</span>
</StylizedToggleButton> </StylizedToggleButton>
</ToggleButtonGroup>; </ToggleButtonGroup>;
}; };

View File

@ -50,7 +50,7 @@ const query = getQueryStringValue("g0.expr", getFromStorage("LAST_QUERY") as str
export const initialState: AppState = { export const initialState: AppState = {
serverUrl: getDefaultServer(), serverUrl: getDefaultServer(),
displayType: "chart", displayType: getQueryStringValue("tab", "chart") as DisplayType,
query: query, // demo_memory_usage_bytes query: query, // demo_memory_usage_bytes
queryHistory: { index: 0, values: [query] }, queryHistory: { index: 0, values: [query] },
time: { time: {

View File

@ -6,7 +6,7 @@ const stateToUrlParams = {
"time.duration": "g0.range_input", "time.duration": "g0.range_input",
"time.period.date": "g0.end_input", "time.period.date": "g0.end_input",
"time.period.step": "g0.step_input", "time.period.step": "g0.step_input",
"stacked": "g0.stacked", "displayType": "tab"
}; };
// TODO need function for detect types. // TODO need function for detect types.