Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/service now create incident #23

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @equinor/amplify-frontend
* @equinor/amplify-component-lib
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/subsurface-app-management",
"version": "1.1.0",
"version": "1.1.1",
"description": "React Typescript components/hooks to communicate with equinor/sam",
"types": "dist/index.d.ts",
"type": "module",
Expand Down
5 changes: 2 additions & 3 deletions src/api/models/AccessRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* tslint:disable */
/* eslint-disable */
export type AccessRoles = {
role: string;
description: string;
role: string;
description: string;
};

8 changes: 4 additions & 4 deletions src/api/models/ApplicationCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* tslint:disable */
/* eslint-disable */
export enum ApplicationCategory {
JSDigitalFrontrunner = 'JS Digital Frontrunner',
Upscaling = 'Upscaling',
Toolbox = 'Toolbox',
External = 'External',
JSDigitalFrontrunner = 'JS Digital Frontrunner',
Upscaling = 'Upscaling',
Toolbox = 'Toolbox',
External = 'External',
}
9 changes: 4 additions & 5 deletions src/api/models/Chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
/* tslint:disable */
/* eslint-disable */
export type Chapter = {
order: number;
title: string;
subTitle: string;
content: string;
order: number;
title: string;
subTitle: string;
content: string;
};

5 changes: 2 additions & 3 deletions src/api/models/ContentTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/* eslint-disable */
import type { Chapter } from './Chapter';
export type ContentTab = {
name: string;
chapters: Array<Chapter>;
name: string;
chapters: Array<Chapter>;
};

5 changes: 2 additions & 3 deletions src/api/services/FeatureToggleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { FeatureToggleDto } from '../models/FeatureToggleDto';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI_Portal_Prod} from '../core/OpenAPI';
import type { CancelablePromise, FeatureToggleDto } from 'src/api';
import { OpenAPI_Portal_Prod } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class FeatureToggleService {
/**
Expand Down
11 changes: 6 additions & 5 deletions src/api/services/ImpersonateUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ImpersonateUser } from '../models/ImpersonateUser';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI_Portal} from '../core/OpenAPI';
import { CancelablePromise, ImpersonateUser } from 'src/api';
import { OpenAPI_Portal } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class ImpersonateUserService {
/**
* Get all impersonate users
* @returns ImpersonateUser Success
* @throws ApiError
*/
public static getApiV1ImpersonateUser(): CancelablePromise<ImpersonateUser> {
public static getApiV1ImpersonateUser(): CancelablePromise<
Array<ImpersonateUser>
> {
return __request(OpenAPI_Portal, {
method: 'GET',
url: '/api/v1/ImpersonateUser',
Expand All @@ -30,7 +31,7 @@ export class ImpersonateUserService {
public static createImpersonateUser(
requestBody?: ImpersonateUser
): CancelablePromise<ImpersonateUser> {
return __request(OpenAPI_Portal, {
return __request(OpenAPI_Portal, {
method: 'POST',
url: '/api/v1/ImpersonateUser',
body: requestBody,
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/ReleaseNotesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI_Portal} from '../core/OpenAPI';
import type { CancelablePromise } from 'src/api';
import { OpenAPI_Portal } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class ReleaseNotesService {
/**
Expand Down
18 changes: 6 additions & 12 deletions src/api/services/ServiceNowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ServiceNowUrgency } from '../models/ServiceNowUrgency';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI_Portal } from '../core/OpenAPI';
import { request as __request } from '../core/request';
import { CancelablePromise, ServiceNowIncidentResponse } from 'src/api';
export class ServiceNowService {
/**
* Creates a incident report in service now
* @param formData
* @returns any Success
* @throws ApiError
*/
public static createIncident(formData?: {
ConfigurationItem: string;
Title: string;
Description: string;
CallerEmail: string;
urgency?: ServiceNowUrgency;
Images?: Array<Blob>;
}): CancelablePromise<any> {
public static createIncident(
formData?: FormData
): CancelablePromise<ServiceNowIncidentResponse> {
return __request(OpenAPI_Portal, {
method: 'POST',
url: '/api/v1/ServiceNow/incident',
formData: formData,
mediaType: 'multipart/form-data',
body: formData,
});
}
}
4 changes: 2 additions & 2 deletions src/api/services/SlackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { CancelablePromise } from '../core/CancelablePromise';
import {OpenAPI_Portal } from '../core/OpenAPI';
import type { CancelablePromise } from 'src/api';
import { OpenAPI_Portal } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class SlackService {
/**
Expand Down
5 changes: 2 additions & 3 deletions src/api/services/TutorialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Tutorial } from '../models/Tutorial';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI_Portal_Prod} from '../core/OpenAPI';
import {CancelablePromise, Tutorial} from 'src/api';
import { OpenAPI_Portal_Prod } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class TutorialService {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useFeatureToggleContext} from "../providers/FeatureToggleProvider";
import { useFeatureToggleContext } from '../providers/FeatureToggleProvider';
import { useFeatureToggling } from './useFeatureToggling';
import { useReleaseNotesQuery } from './useReleaseNotesQuery';

Expand Down
58 changes: 31 additions & 27 deletions src/hooks/useFeatureToggling.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ vi.mock('src/api/services/FeatureToggleService', () => {
return new CancelablePromise((resolve, reject) => {
setTimeout(() => {
if (mockServiceHasError) {
reject( 'error featureToggle');
reject('error featureToggle');
} else {
resolve(mockedAppFeatures.find((f) => f.applicationName === key));
}
Expand Down Expand Up @@ -153,7 +153,7 @@ test('should return true for showContent feature is not found', async () => {
await waitFor(
() => {
expect(result.current.showContent).toBe(true);
expect(consoleWarnSpy).toHaveBeenCalledTimes(1)
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
},
{ timeout: 600 }
);
Expand All @@ -178,7 +178,7 @@ test('should return true for showContent when there is a feature and we have a w
await waitFor(
() => {
expect(result.current.showContent).toBe(true);
expect(consoleWarnSpy).toHaveBeenCalled()
expect(consoleWarnSpy).toHaveBeenCalled();
},
{ timeout: 600 }
);
Expand Down Expand Up @@ -235,10 +235,10 @@ test('should return false if is loading', async () => {
}
);
await waitFor(
() => {
expect(result.current.showContent).toBe(false);
},
{ timeout: 1000 }
() => {
expect(result.current.showContent).toBe(false);
},
{ timeout: 1000 }
);
await new Promise((resolve) => setTimeout(resolve, 5000));
await waitFor(
Expand All @@ -254,23 +254,27 @@ test('should return true if is loading and showIfIsLoading=true', async () => {
vi.stubEnv('VITE_NAME', Scenarios.WITH_FEATURES_KEY);
vi.stubEnv('VITE_ENVIRONMENT_NAME', ENVIRONMENT);
const { result } = renderHook(
() => useFeatureToggling({ featureKey: uniqueFeatureKey, showIfIsLoading: true}),
{
wrapper: Wrappers,
}
() =>
useFeatureToggling({
featureKey: uniqueFeatureKey,
showIfIsLoading: true,
}),
{
wrapper: Wrappers,
}
);
await waitFor(
() => {
expect(result.current.showContent).toBe(true);
},
{ timeout: 1000 }
() => {
expect(result.current.showContent).toBe(true);
},
{ timeout: 1000 }
);
await new Promise((resolve) => setTimeout(resolve, 5000));
await waitFor(
() => {
expect(result.current.showContent).toBe(true);
},
{ timeout: 1000 }
() => {
expect(result.current.showContent).toBe(true);
},
{ timeout: 1000 }
);
}, 10000);

Expand All @@ -279,17 +283,17 @@ test('should return false if error request has error', async () => {
vi.stubEnv('VITE_NAME', Scenarios.WITH_FEATURES_KEY);
vi.stubEnv('VITE_ENVIRONMENT_NAME', ENVIRONMENT);
const { result } = renderHook(
() => useFeatureToggling({ featureKey: uniqueFeatureKey }),
{
wrapper: Wrappers,
}
() => useFeatureToggling({ featureKey: uniqueFeatureKey }),
{
wrapper: Wrappers,
}
);
await new Promise((resolve) => setTimeout(resolve, 5000));
await waitFor(
() => {
expect(result.current.showContent).toBe(false);
},
{ timeout: 6000 }
() => {
expect(result.current.showContent).toBe(false);
},
{ timeout: 6000 }
);
}, 10000);

Expand Down
26 changes: 19 additions & 7 deletions src/hooks/useFeatureToggling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ interface UseFeatureTogglingOptions {
* @param username - username to feature toggle on, typically username from azure. Does not need to be provided if not feature-toggling for specific user
* @param showIfKeyIsMissing - Show/hide if the key was not found/has been deleted. Defaults to true
* @param ShowIfIsLoading - Show/hide if the feature toggles are still loading. Defaults to false
*/
*/
export function useFeatureToggling({
featureKey,
username,
showIfKeyIsMissing = true,
showIfIsLoading = false,
}: UseFeatureTogglingOptions) {
const { features, isError, environmentName, isLoading } = useFeatureToggleContext();
const { features, isError, environmentName, isLoading } =
useFeatureToggleContext();

if (!showIfKeyIsMissing) {
console.warn(`[FeatureToggle] Feature: ${featureKey} will not show when the feature toggle is removed! Was this intentional?`)
console.warn(
`[FeatureToggle] Feature: ${featureKey} will not show when the feature toggle is removed! Was this intentional?`
);
}

const showContent = useMemo(() => {
if ((!showIfIsLoading && isLoading) || isError) return false
if ((!showIfIsLoading && isLoading) || isError) return false;

const feature = features?.find(
(feature) => feature.featureKey === featureKey
(feature) => feature.featureKey === featureKey
);

if (feature) {
Expand All @@ -53,12 +56,21 @@ export function useFeatureToggling({
return feature.activeEnvironments.includes(environmentName);
} else {
console.warn(
`[FeatureToggle] Feature ${featureKey} was not found, has it been removed?`
`[FeatureToggle] Feature ${featureKey} was not found, has it been removed?`
);
}

return showIfKeyIsMissing;
}, [showIfIsLoading, isLoading, isError, features, showIfKeyIsMissing, featureKey, username, environmentName]);
}, [
showIfIsLoading,
isLoading,
isError,
features,
showIfKeyIsMissing,
featureKey,
username,
environmentName,
]);

return { showContent };
}
7 changes: 2 additions & 5 deletions src/providers/FeatureToggleProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { createContext, FC, ReactElement, ReactNode, useContext } from 'react';
import { useQuery } from '@tanstack/react-query';

// These 2 api imports need to be separated to be able to use vi.mock in tests
import {
FeatureAPIType,
GraphUser,
} from 'src/api';
import { FeatureToggleService } from 'src/api/services/FeatureToggleService'
import { FeatureAPIType, GraphUser } from 'src/api';
import { FeatureToggleService } from 'src/api/services/FeatureToggleService';
import { EnvironmentType } from 'src/types';
import { environment } from 'src/utils';
import { getEnvironmentName } from 'src/utils/environment';
Expand Down