Skip to content

Commit

Permalink
FeatureHighlights the previously selected query (#1006)
Browse files Browse the repository at this point in the history
* Highlights the previously selected query

* Rebase

* Using isCollapse to expand generateGroupsFromList

Co-authored-by: Charles Wahome <thewahome.cw@gmail.com>

* use groups instead of this.groups

Co-authored-by: Charles Wahome <thewahome.cw@gmail.com>

* set the entire props.item instead of just the id

Co-authored-by: Charles Wahome <thewahome.cw@gmail.com>

* Update the query id

Co-authored-by: Charles Wahome <thewahome.cw@gmail.com>
  • Loading branch information
gracet9182 and thewahome authored Aug 10, 2021
1 parent 7e51662 commit 47ba6c3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/app/views/sidebar/sample-queries/SampleQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Announced, DetailsList, DetailsRow, FontSizes, FontWeights, getId,
GroupHeader, IColumn, Icon, MessageBar, MessageBarType, SearchBox,
GroupHeader, IColumn, Icon, IDetailsRowStyles, MessageBar, MessageBarType, SearchBox,
SelectionMode, Spinner, SpinnerSize, styled, TooltipHost
} from 'office-ui-fabric-react';
import React, { Component } from 'react';
Expand Down Expand Up @@ -34,7 +34,8 @@ export class SampleQueries extends Component<ISampleQueriesProps, any> {
constructor(props: ISampleQueriesProps) {
super(props);
this.state = {
sampleQueries: []
sampleQueries: [],
selectedQuery: null,
};
}

Expand Down Expand Up @@ -206,6 +207,10 @@ export class SampleQueries extends Component<ISampleQueriesProps, any> {
const { tokenPresent } = this.props;
const classes = classNames(this.props);
let selectionDisabled = false;
const customStyles: Partial<IDetailsRowStyles> = {};
if (this.state.selectedQuery?.id === props.item.id) {
customStyles.root = { backgroundColor: '#eaeaea' };
}

if (props) {
if (!tokenPresent && props.item.method !== 'GET') {
Expand All @@ -215,10 +220,12 @@ export class SampleQueries extends Component<ISampleQueriesProps, any> {
<div className={classes.groupHeader}>
<DetailsRow
{...props}
styles={customStyles}
onClick={() => {
if (!selectionDisabled) {
this.querySelected(props.item);
}
this.setState({ selectedQuery: props.item })
}}
className={
classes.queryRow +
Expand Down Expand Up @@ -330,6 +337,10 @@ export class SampleQueries extends Component<ISampleQueriesProps, any> {
const { sampleQueries } = this.state;
const classes = classNames(this.props);
const groups = generateGroupsFromList(sampleQueries, 'category');
if (this.state.selectedQuery) {
const index = groups.findIndex(k => k.key === this.state.selectedQuery.category);
groups[index].isCollapsed = false;
}

if (pending) {
return (
Expand Down

0 comments on commit 47ba6c3

Please sign in to comment.