Skip to content

Commit

Permalink
Fix: repopulate modify permissions when panel closed (#999)
Browse files Browse the repository at this point in the history
* repopulate open modify permissions when permissions panel is closed

* move all fetch scopes logic to action creator
  • Loading branch information
thewahome authored Jun 17, 2021
1 parent 1b323b8 commit f3732f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/app/services/actions/permissions-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { MessageBarType } from 'office-ui-fabric-react';
import { geLocale } from '../../../appLocale';
import { authenticationWrapper } from '../../../modules/authentication';
import { IAction } from '../../../types/action';
import { IQuery } from '../../../types/query-runner';
import { IRequestOptions } from '../../../types/request';
import { IRootState } from '../../../types/root';
import { sanitizeQueryUrl } from '../../utils/query-url-sanitization';
import { parseSampleUrl } from '../../utils/sample-url-generation';
import { translateMessage } from '../../utils/translate-messages';
Expand Down Expand Up @@ -39,14 +39,14 @@ export function fetchScopesError(response: object): IAction {
};
}

export function fetchScopes(query?: IQuery): Function {
export function fetchScopes(): Function {
return async (dispatch: Function, getState: Function) => {
let hasUrl = false; // whether permissions are for a specific url
try {
const { devxApi } = getState();
const { devxApi, permissionsPanelOpen, sampleQuery: query }: IRootState = getState();
let permissionsUrl = `${devxApi.baseUrl}/permissions`;

if (query) {
if (!permissionsPanelOpen) {
const signature = sanitizeQueryUrl(query.sampleUrl);
const { requestUrl, sampleUrl } = parseSampleUrl(signature);

Expand Down
18 changes: 7 additions & 11 deletions src/app/views/query-runner/request/permissions/Permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Permission extends Component<IPermissionProps, IPermissionState> {
}

public componentDidUpdate = (prevProps: IPermissionProps) => {
if (prevProps.sample !== this.props.sample) {
if ((prevProps.sample !== this.props.sample) || (prevProps.permissionsPanelOpen !== this.props.permissionsPanelOpen)) {
this.getPermissions();
}
const permissions = this.props.scopes.data;
Expand All @@ -51,20 +51,15 @@ export class Permission extends Component<IPermissionProps, IPermissionState> {
}

private getPermissions() {
const { panel, sample } = this.props;
if (panel) {
this.props.actions!.fetchScopes();
}
else {
this.props.actions!.fetchScopes(sample);
}
this.props.actions!.fetchScopes();
}

public shouldComponentUpdate(nextProps: IPermissionProps, nextState: IPermissionState) {
const shouldUpdate = nextProps.sample !== this.props.sample
|| nextProps.scopes !== this.props.scopes
|| nextProps.consentedScopes !== this.props.consentedScopes
|| nextProps.dimensions !== this.props.dimensions
|| nextProps.permissionsPanelOpen !== this.props.permissionsPanelOpen
|| nextState.permissions !== this.state.permissions;
return shouldUpdate;
}
Expand Down Expand Up @@ -242,7 +237,7 @@ export class Permission extends Component<IPermissionProps, IPermissionState> {
if (loading) {
return <Label>
<FormattedMessage id={'Fetching permissions'} />...
</Label>;
</Label>;
}

const displayPermissionsPanel = () => {
Expand Down Expand Up @@ -278,13 +273,14 @@ export class Permission extends Component<IPermissionProps, IPermissionState> {
}
}

function mapStateToProps({ sampleQuery, scopes, authToken, consentedScopes, dimensions }: IRootState) {
function mapStateToProps({ sampleQuery, scopes, authToken, consentedScopes, dimensions, permissionsPanelOpen }: IRootState) {
return {
sample: sampleQuery,
scopes,
tokenPresent: authToken.token,
consentedScopes,
dimensions
dimensions,
permissionsPanelOpen
};
}

Expand Down
1 change: 1 addition & 0 deletions src/types/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IPermissionProps {
panel: boolean;
sample: IQuery[];
tokenPresent: boolean;
permissionsPanelOpen: boolean;
consentedScopes: string[];
setPermissions: Function;
actions?: {
Expand Down
2 changes: 2 additions & 0 deletions src/types/root.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAdaptiveCardResponse } from './adaptivecard';
import { IAuthenticateResult } from './authentication';
import { IAutocompleteResponse } from './auto-complete';
import { IDevxAPI } from './devx-api';
import { IDimensions } from './dimensions';
import { Mode } from './enums';
import { IHistoryItem } from './history';
Expand Down Expand Up @@ -33,6 +34,7 @@ export interface IRootState {
responseAreaExpanded: boolean;
dimensions: IDimensions;
autoComplete: IAutocompleteResponse;
devxApi: IDevxAPI;
}

export interface IApiFetch {
Expand Down

0 comments on commit f3732f8

Please sign in to comment.