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

refactor: Align portal administration application with the new app management models #862

Merged
merged 3 commits into from
Nov 12, 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
5 changes: 5 additions & 0 deletions .changeset/pr-862-2174620281.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": minor
---
Align portal administration application with the new app management models
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Button, Icon } from '@equinor/eds-core-react';
import { PortalApp, PortalApplication } from '../../types';
import { PortalApplication } from '../../types';

import { add_circle_filled } from '@equinor/eds-icons';
import { useMemo } from 'react';

type ActivateSelectedWithContextButtonProps = {
selection: PortalApplication[];
Expand All @@ -12,7 +13,9 @@ export const ActivateSelectedWithContextButton = ({
selection,
activateSelectedWithContext,
}: ActivateSelectedWithContextButtonProps) => {
const isActive = selection.some((a) => !a.isActive) && selection.length < 2;

// Only active if one is selected or the selected has contextTypes active
const isActive = useMemo(()=> (!!selection.find(app => app.contextTypes.length !== 0) && selection.some((a) => !a.isActive) && selection.length < 2),[selection]);

if (!isActive) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export function ContextAppSideSheet({
const { activeContexts, contextTypes } = useActiveOnboardedContext();
const [selectedContexts, setSelectedContexts] = useState<OnboardedContext[]>([]);

const { data: activeApp, isLoading } = useGetPortalApp(activePortalId, app.key);
const { data: activeApp, isLoading } = useGetPortalApp(activePortalId, app.appManifest.appKey);

const contexts: OnboardedContext[] = useMemo(() => {
if (!activeApp || !activeContexts) return [];

if (!activeApp || !activeContexts) return [];
return activeContexts.map((context) => ({
...context,
isActive: activeApp.contextIds?.includes(context.contextId),
Expand All @@ -103,7 +103,7 @@ export function ContextAppSideSheet({
minWidth={1200}
isDismissable={true}
>
<SideSheet.Title title={`Activate ${app.appManifest.name} Application`} />
<SideSheet.Title title={`Activate ${app.appManifest.displayName} Application`} />
<SideSheet.SubTitle subTitle="Activate application with contexts" />
<SideSheet.Actions></SideSheet.Actions>
<SideSheet.Content>
Expand Down Expand Up @@ -165,9 +165,9 @@ export function ContextAppSideSheet({
onCellValueChanged: (event) => {
if (event.newValue) {
console.log('Activate context', event.data);
add({ appKey: app.key, contextIds: [event.data.contextId] });
add({ appKey: app.appManifest.appKey, contextIds: [event.data.contextId] });
} else {
remove({ appKey: app.key, contextIds: [event.data.contextId] });
remove({ appKey: app.appManifest.appKey, contextIds: [event.data.contextId] });
}
},
},
Expand Down Expand Up @@ -200,7 +200,7 @@ export function ContextAppSideSheet({
<Button
onClick={() => {
add({
appKey: app.key,
appKey: app.appManifest.appKey,
contextIds: selectedContexts
.filter((a) => !a.isActive)
.map((a) => a.contextId),
Expand All @@ -214,7 +214,7 @@ export function ContextAppSideSheet({
<Button
onClick={() => {
remove({
appKey: app.key,
appKey: app.appManifest.appKey,
contextIds: selectedContexts
.filter((a) => a.isActive)
.map((a) => a.contextId),
Expand Down
14 changes: 7 additions & 7 deletions client/apps/portal-administration/src/query/apps-mutations.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { QueryClient } from '@tanstack/react-query';
import { OnboardedContext, PortalApplication } from '../types';
import { PortalApplication } from '../types';

export const mutatePortalApps = (queryClient: QueryClient, portalId: string | undefined, apps: PortalApplication[]) => {
queryClient.cancelQueries({ queryKey: ['portal-onboarded-apps', portalId] });

const prevApps = queryClient.getQueryData<PortalApplication[]>(['portal-onboarded-apps', portalId]) || [];

const newApps = prevApps.map((a) => {
const isActive = apps.find((app) => app.key === a.key);
const newApps = prevApps.map((prevApp) => {
const isActive = apps.find((app) => app.appManifest.appKey === prevApp.appManifest.appKey);
if (isActive) {
return { ...a, isActive: true };
return { ...prevApp, isActive: true };
}
return a;
return prevApp;
});

queryClient.setQueryData(['portal-onboarded-apps', portalId], newApps);
Expand All @@ -26,8 +26,8 @@ export const mutateDeletePortalApps = (
queryClient.cancelQueries({ queryKey: ['portal-onboarded-apps', portalId] });
const prevApps = queryClient.getQueryData<PortalApplication[]>(['portal-onboarded-apps', portalId]) || [];

const appKeys = apps.map((a) => a.key);
const newApps = prevApps?.map((a) => (appKeys.includes(a.key) ? { ...a, isActive: false } : a));
const appKeys = apps.map((app) => app.appManifest.appKey);
const newApps = prevApps?.map((prevApp) => (appKeys.includes(prevApp.appManifest.appKey) ? { ...prevApp, isActive: false } : prevApp));
queryClient.setQueryData(['portal-onboarded-apps', portalId], newApps);
return { prevApps, newApps };
};
Expand Down
4 changes: 2 additions & 2 deletions client/apps/portal-administration/src/query/apps-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const addPortalApps = async (client: IHttpClient, portalApps: PortalAppli
const results: Result[] = [];

for (const app of portalApps) {
const result = await addPortalApp(client, app.key, portalId);
const result = await addPortalApp(client, app.appManifest.appKey, portalId);
results.push(result);
}

Expand Down Expand Up @@ -165,7 +165,7 @@ export const removePortalApps = async (client: IHttpClient, portalApps: PortalAp
const results: Result[] = [];

for (const app of portalApps) {
const result = await removePortalApp(client, app.key, portalId);
const result = await removePortalApp(client, app.appManifest.appKey, portalId);
results.push(result);
}

Expand Down
4 changes: 2 additions & 2 deletions client/apps/portal-administration/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type PortalApp = {

export type PortalApplication = {
id: string;
key: string;
appKey: string;
contextTypes: string[];
appManifest: AppManifest;
isActive?: boolean;
Expand All @@ -80,7 +80,7 @@ export type PortalAppMutation = {
};

export type AppManifestResponse = {
key: string;
appKey: string;
contextTypes: ContextType[];
appManifest: AppManifest;
};
Expand Down
Loading