Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsaplin committed Nov 21, 2023
1 parent f5c0e87 commit 5bc4f3d
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 421 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion actions/AuthAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function checkForProductContext(endpoint, clientId, org, token, productCon
.filter((obj) => obj.prodCtx.serviceCode === productContext);

// For each entry in filteredProductContext check that
// there is at least one entry where imsOrg matches the owningEntity property
// there is at least one entry where imsOrg matches the owningEntity property
// otherwise, if no match, the user is not authorized
return filteredProductContext.some((obj) => obj.prodCtx.owningEntity === org);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@adobe/aio-sdk": "3.0.0",
"@adobe/exc-app": "^1.2.10",
"@adobe/exc-app": "1.2.10",
"@adobe/generator-add-action-generic": "0.2.9",
"@adobe/react-spectrum": "3.32.0",
"@emotion/css": "11.11.2",
Expand Down
6 changes: 4 additions & 2 deletions web-src/src/components/ApplicationProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import React, { Fragment, useCallback, useContext, useEffect, useMemo, useState } from 'react';
import React, {
Fragment, useCallback, useContext, useEffect, useState,
} from 'react';
import { Content, Heading, InlineAlert } from '@adobe/react-spectrum';
import { useSetRecoilState } from 'recoil';
import excApp from '@adobe/exc-app';
Expand Down Expand Up @@ -57,7 +59,7 @@ function createApplication(configuration, shellConfig) {
completeEndpoint: actions[COMPLETE_ACTION],
feedbackEndpoint: actions[FEEDBACK_ACTION],
}),
shellConfig: shellConfig
shellConfig,
};
}

Expand Down
63 changes: 0 additions & 63 deletions web-src/src/components/AuthProvider.js

This file was deleted.

7 changes: 3 additions & 4 deletions web-src/src/components/ConsentDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import {
Heading,
} from '@adobe/react-spectrum';
import React, { useEffect } from 'react';
import settingsApi, { SettingsLevel } from '@adobe/exc-app/settings';
import { LegalTermsLink } from './LegalTermsLink.js';
import { sampleRUM } from '../rum.js';
import { NoAccessDialog } from './NoAccessDialog.js';

import settingsApi, { SettingsLevel } from '@adobe/exc-app/settings';

const CONSENT_KEY = 'genai-assistant-consent';
const REDIRECT_URL = 'https://experience.adobe.com';

Expand All @@ -35,7 +34,7 @@ export function ConsentDialog() {
const { settings } = await settingsApi.get({
groupId: 'test-aem-genai-assistant',
level: SettingsLevel.USERORG,
settings: {[CONSENT_KEY]: false}
settings: { [CONSENT_KEY]: false },
});
setOpen(!settings[CONSENT_KEY]);
}, []);
Expand All @@ -45,7 +44,7 @@ export function ConsentDialog() {
settingsApi.set({
groupId: 'test-aem-genai-assistant',
level: SettingsLevel.USERORG,
settings: {[CONSENT_KEY]: true}
settings: { [CONSENT_KEY]: true },
});
setOpen(false);
};
Expand Down
1 change: 0 additions & 1 deletion web-src/src/components/HomePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { PromptTemplateCard } from './PromptTemplateCard.js';
import { sessionState } from '../state/SessionState.js';
import { ViewType, viewTypeState } from '../state/ViewType.js';
import { formatTimestamp } from '../helpers/FormatHelper.js';
import { SignOutButton } from './SignOutButton.js';
import { promptTemplatesState } from '../state/PromptTemplatesState.js';
import { sampleRUM } from '../rum.js';

Expand Down
2 changes: 1 addition & 1 deletion web-src/src/components/PromptTemplateCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function PromptTemplateCard({
return (
<a onClick={onClick}>
<motion.div
initial={{ opacity: 0, scale: 0.9 }}
initial={{ opacity: 0.3, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}
whileHover={{ scale: 1.02 }}
transition={{ ease: 'easeInOut', duration: 0.3 }}>
Expand Down
2 changes: 1 addition & 1 deletion web-src/src/components/ResultCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function ResultCard({ result, ...props }) {
isQuiet
UNSAFE_className="hover-cursor-pointer"
onPress={() => {
sampleRUM('genai:prompt:copy', { source: 'ResultCard#onPress'});
sampleRUM('genai:prompt:copy', { source: 'ResultCard#onPress' });
navigator.clipboard.write(toClipboard(toHTML(selectedVariant.content)));
}}>
<Copy/>
Expand Down
41 changes: 22 additions & 19 deletions web-src/src/components/ShellAuthProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@
* governing permissions and limitations under the License.
*/

import React, { useEffect, createContext, useState, useContext } from 'react';
import React, {
useEffect, createContext, useState, useContext,
} from 'react';
import { ToastQueue } from '@react-spectrum/toast';

import { useApplicationContext } from './ApplicationProvider';
import { useApplicationContext } from './ApplicationProvider.js';

export const ShellAuthContext = createContext({});

// Check if the user is authorized
// The user is authorized if userInfo.imsProfile.projectedProductContext which is an array contains inside the array
// an object having the required product context and the owning entity matching the user.imsOrg
const isAuthorized = (user) => {
if (Array.isArray(user.imsProfile.projectedProductContext)) {
const filteredProductContext = user.imsProfile.projectedProductContext
.filter((obj) => obj.prodCtx.serviceCode === process.env.IMS_PRODUCT_CONTEXT);

// For each entry in filteredProductContext check that
// there is at least one entry where user.imsOrg matches the owningEntity property
// otherwise, if no match, the user is not authorized
return filteredProductContext.some((obj) => obj.prodCtx.owningEntity === user.imsOrg);
}
return false;
};

export const ShellAuthProvider = ({ children }) => {
const [user, setUser] = useState(null);
const [isUserAuthorized, setIsUserAuthorized] = useState(false);
Expand All @@ -27,11 +45,11 @@ export const ShellAuthProvider = ({ children }) => {
setUser({
imsProfile: shellConfig.imsProfile,
imsToken: shellConfig.imsToken,
imsOrg: shellConfig.imsOrg
imsOrg: shellConfig.imsOrg,
});
}, [shellConfig]);

// When the user changes, invoke isAuthorized function and display an error message in the UI
// When the user changes, invoke isAuthorized function and display an error message in the UI
// if the user is not authorized
useEffect(() => {
if (user) {
Expand All @@ -42,21 +60,6 @@ export const ShellAuthProvider = ({ children }) => {
}
}, [user]);

// Check if the user is authorized
// The user is authorized if userInfo.imsProfile.projectedProductContext which is an array contains inside the array
// an object having the required product context and the owning entity matching the user.imsOrg
const isAuthorized = (user) => {
if (Array.isArray(user.imsProfile['projectedProductContext'])) {
const filteredProductContext = user.imsProfile['projectedProductContext'].filter((obj) => obj['prodCtx']['serviceCode'] === process.env.IMS_PRODUCT_CONTEXT);

// For each entry in filteredProductContext check that
// there is at least one entry where user.imsOrg matches the owningEntity property
// otherwise, if no match, the user is not authorized
return filteredProductContext.some((obj) => obj['prodCtx']['owningEntity'] === user.imsOrg);
}
return false;
}

return (
<ShellAuthContext.Provider value={{ user, isUserAuthorized }}>
<>{children}</>
Expand Down
1 change: 0 additions & 1 deletion web-src/src/components/SidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { useApplicationContext } from './ApplicationProvider.js';
import { USER_GUIDELINES_URL } from './LegalTermsLink.js';

import LogoIcon from '../assets/logo.svg';
import PromptsIcon from '../assets/prompts.svg';
import FavoritesIcon from '../assets/favorites.svg';
import RecentsIcon from '../assets/recents.svg';
Expand Down
29 changes: 0 additions & 29 deletions web-src/src/components/SignOutButton.js

This file was deleted.

4 changes: 2 additions & 2 deletions web-src/src/helpers/CreateVariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export function createVariants(uuid, response) {
try {
const json = JSON.parse(response);
if (Array.isArray(json)) {
return json.map((content) => ({ id: uuid(), content: content === null || typeof content !== 'object' ? objectToString(content) : content }) );
return json.map((content) => ({ id: uuid(), content: content === null || typeof content !== 'object' ? objectToString(content) : content }));
} else {
return [{ id: uuid(), content: json }];
}
} catch (error) {
return [{ id: uuid(), content: String(response) }];
}
}
}
29 changes: 20 additions & 9 deletions web-src/src/helpers/CreateVariants.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { createVariants } from './CreateVariants.js';

const uuid = () => 123;

describe('createVariants', () => {
test('response is a JSON string: an array of json objects', () => {
const response = [
{key1: 'value1', key2: 'value2'},
{key3: 'value3', key4: 'value4'},
{ key1: 'value1', key2: 'value2' },
{ key3: 'value3', key4: 'value4' },
null,
'Hello!',
'<tag>how</tag> is it going?'
'<tag>how</tag> is it going?',
];
expect(createVariants(uuid, JSON.stringify(response))).toEqual([
{ id: 123, content: {key1: 'value1', key2: 'value2'} },
{ id: 123, content: {key3: 'value3', key4: 'value4'} },
{ id: 123, content: { key1: 'value1', key2: 'value2' } },
{ id: 123, content: { key3: 'value3', key4: 'value4' } },
{ id: 123, content: 'null' },
{ id: 123, content: 'Hello!' },
{ id: 123, content: 'how is it going?' }
{ id: 123, content: 'how is it going?' },
]);
});
test('response is a JSON string: an object', () => {
const response = {key: 'value'};
const response = { key: 'value' };
expect(createVariants(uuid, JSON.stringify(response))).toEqual([
{ id: 123, content: {key: 'value'} },
{ id: 123, content: { key: 'value' } },
]);
});
test('response is a string', () => {
const response = 'Hello! How can I assist you today?';
expect(createVariants(uuid, response)).toEqual([{ id: 123, content: response }]);
});
});
});
2 changes: 1 addition & 1 deletion web-src/src/helpers/ExportPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export function toHTML(input) {
return `<b>${key}</b>: ${value}`;
}).join('<br/>');
}
}
}
16 changes: 13 additions & 3 deletions web-src/src/helpers/ExportPrompt.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { toClipboard, toHTML } from './ExportPrompt.js';
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { toHTML } from './ExportPrompt.js';

describe('toHTML', () => {
test('returns html: prompt result is an key/value pair', () => {
const promptResponse = {key1: 'value1', key2: 'value2'};
const promptResponse = { key1: 'value1', key2: 'value2' };
expect(toHTML(promptResponse)).toEqual('<b>key1</b>: value1<br/><b>key2</b>: value2');
});
test('returns html: prompt result is a string', () => {
const promptResponse = 'hello';
expect(toHTML(promptResponse)).toEqual('hello');
});
});

Loading

0 comments on commit 5bc4f3d

Please sign in to comment.