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: My extensions list #2479

Merged
merged 25 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cd01362
refactor(apps): refetch published extensions
josenriagu Nov 6, 2024
879ebdd
chore(ds): update utils
josenriagu Nov 7, 2024
bcc1537
refactor(ds); update text field and story
josenriagu Nov 7, 2024
1f8316e
refactor(ds): update dropdown component and story
josenriagu Nov 7, 2024
8a71e28
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 8, 2024
e7ce7a4
Merge branch 'next' into dev-443
josenriagu Nov 8, 2024
0b231b7
chore(ds): update file names
josenriagu Nov 8, 2024
e05408b
chore(ds): update dropdown component
josenriagu Nov 8, 2024
b580f51
refactor(extensions): my extensions dropdown
josenriagu Nov 8, 2024
cff0eae
Merge branch 'dev-443' into fix/my-extensions-list
josenriagu Nov 8, 2024
0663c9d
chore(ds): update styles
josenriagu Nov 8, 2024
b2d8e4e
Merge branch 'dev-443' into fix/my-extensions-list
josenriagu Nov 8, 2024
7931f07
chore(apps): update page
josenriagu Nov 8, 2024
43551dc
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 11, 2024
f12154e
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 12, 2024
fabaed9
refactor(ds): update extension icon component
josenriagu Nov 13, 2024
00dabb4
refactor(extensions): update components
josenriagu Nov 13, 2024
03a2c2d
chore(extensions): revert
josenriagu Nov 13, 2024
6013d92
feat(extensions): update cache after removing a published extension
josenriagu Nov 13, 2024
768ba6c
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 13, 2024
b0fae42
feat(extensions): update cache afte publishing an extension
josenriagu Nov 14, 2024
3faf697
chore(extensions): add missing fields
josenriagu Nov 14, 2024
10bc1cb
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 16, 2024
88616ba
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 18, 2024
eb5d934
Merge branch 'next' into fix/my-extensions-list
josenriagu Nov 20, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
CreateAppMutation,
GetAppsByPublisherDidQuery,
} from '@akashaorg/typings/lib/sdk/graphql-operation-types-new';
import { SortOrder } from '@akashaorg/typings/lib/sdk/graphql-types-new';
import { GetAppsByPublisherDidDocument } from '@akashaorg/ui-awf-hooks/lib/generated/apollo';
import { selectApps } from '@akashaorg/ui-awf-hooks/lib/selectors/get-apps-by-publisher-did-query';
import { ApolloCache } from '@apollo/client';

interface IUpdateCache {
cache: ApolloCache<unknown>;
authenticatedDID: string;
document: CreateAppMutation['setAkashaApp']['document'];
}

export async function createAppMutationCache({ cache, authenticatedDID, document }: IUpdateCache) {
const variables = {
id: authenticatedDID,
first: 10,
sorting: { createdAt: SortOrder.Desc },
};
const query = cache.readQuery<GetAppsByPublisherDidQuery>({
query: GetAppsByPublisherDidDocument,
variables,
});
const apps = selectApps(query);
const updatedApps = [
{
...document,
logoImage: null,
coverImage: null,
gallery: null,
meta: null,
links: [],
createdAt: new Date().toISOString(),
},
...apps,
];

cache.writeQuery<GetAppsByPublisherDidQuery>({
query: GetAppsByPublisherDidDocument,
variables,
data: {
node: {
...query.node,
akashaAppList: {
...('akashaAppList' in query.node && query.node?.akashaAppList),
edges: updatedApps.map(app => ({
node: app,
cursor: '',
})),
},
},
},
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from '@tanstack/react-router';
import appRoutes, { SUBMIT_EXTENSION } from '../../routes';
import Stack from '@akashaorg/design-system-core/lib/components/Stack';
import Text from '@akashaorg/design-system-core/lib/components/Text';
import ErrorLoader from '@akashaorg/design-system-core/lib/components/ErrorLoader';
Expand All @@ -17,14 +16,16 @@ import {
useRootComponentProps,
} from '@akashaorg/ui-awf-hooks';
import { Extension, NotificationEvents, NotificationTypes } from '@akashaorg/typings/lib/ui';
import { DRAFT_EXTENSIONS, DRAFT_RELEASES, MAX_CONTRIBUTORS_DISPLAY } from '../../constants';
import getSDK from '@akashaorg/core-sdk';
import {
useCreateAppMutation,
useGetAppsByPublisherDidQuery,
} from '@akashaorg/ui-awf-hooks/lib/generated';
import { SubmitType } from '../app-routes';
import { selectAkashaApp } from '@akashaorg/ui-awf-hooks/lib/selectors/get-apps-by-publisher-did-query';
import { SubmitType } from '../../app-routes';
import appRoutes, { SUBMIT_EXTENSION } from '../../../routes';
import { DRAFT_EXTENSIONS, DRAFT_RELEASES, MAX_CONTRIBUTORS_DISPLAY } from '../../../constants';
import { createAppMutationCache } from './create-app-mutation-cache';

type ExtensionPublishPageProps = {
extensionId: string;
Expand Down Expand Up @@ -80,6 +81,16 @@ export const ExtensionPublishPage: React.FC<ExtensionPublishPageProps> = ({ exte

const [createAppMutation, { loading: loadingAppMutation }] = useCreateAppMutation({
context: { source: sdk.current.services.gql.contextSources.composeDB },
update: (
cache,
{
data: {
setAkashaApp: { document },
},
},
) => {
createAppMutationCache({ cache, authenticatedDID, document });
},
onCompleted: data => {
// after the extension has been published to the ceramic model
// search for it in the list of local draft extensions and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const ReleasesPage = (props: ReleasesPageProps) => {
/>
</>
)}
{releases && (
{releases && releases.length > 0 && (
<DynamicInfiniteScroll
count={releases.length}
overScan={5}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from '@tanstack/react-router';
import getSDK from '@akashaorg/core-sdk';
import ExtensionIcon from '@akashaorg/design-system-core/lib/components/ExtensionIcon';
import Stack from '@akashaorg/design-system-core/lib/components/Stack';
import AppAvatar from '@akashaorg/design-system-core/lib/components/AppAvatar';
import Icon from '@akashaorg/design-system-core/lib/components/Icon';
import Divider from '@akashaorg/design-system-core/lib/components/Divider';
import Text from '@akashaorg/design-system-core/lib/components/Text';
import Menu from '@akashaorg/design-system-core/lib/components/Menu';
Expand Down Expand Up @@ -188,91 +187,83 @@ export const ExtensionElement: React.FC<ExtensionElement> = ({
}
};

const iconType = useMemo(() => extensionData?.applicationType, [extensionData]);

if (!showElement()) return null;

return (
<>
{showElement() && (
<Stack spacing="gap-y-4">
<Stack direction="row" justify="between" spacing="gap-x-8" fullWidth>
<Stack direction="row" spacing="gap-x-3" customStyle="max-h-[60px] w-[60%]">
<AppAvatar
appType={extensionData?.applicationType}
avatar={transformSource(extensionData?.logoImage)}
extensionId={extensionData?.id}
/>
<Stack direction="column" justify="between" customStyle="w-0 min-w-full">
<Stack direction="row" spacing="gap-2">
<Text variant="button-sm" truncate>
{extensionData?.name}
</Text>
<Stack spacing="gap-y-4">
<Stack direction="row" justify="between" spacing="gap-x-8" fullWidth>
<Stack direction="row" spacing="gap-x-3" customStyle="max-h-[60px] w-[60%]">
<AppAvatar
appType={extensionData?.applicationType}
avatar={transformSource(extensionData?.logoImage)}
extensionId={extensionData?.id}
/>
<Stack direction="column" justify="between" customStyle="w-0 min-w-full">
<Stack direction="row" spacing="gap-2">
<Text variant="button-sm" truncate>
{extensionData?.name}
</Text>

{extensionData?.applicationType && (
<Stack
customStyle="w-[18px] h-[18px] rounded-full shrink-0"
background={{ light: 'tertiaryLight', dark: 'tertiaryDark' }}
justify="center"
align="center"
>
<Icon
color={{ light: 'white', dark: 'white' }}
size={'xs'}
solid
icon={<ExtensionIcon type={extensionData?.applicationType} />}
/>
</Stack>
)}
</Stack>
<Text
variant="footnotes2"
weight="normal"
color={{ light: 'grey4', dark: 'grey7' }}
truncate
{extensionData?.applicationType && (
<Stack
customStyle="w-[18px] h-[18px] rounded-full shrink-0"
background={{ light: 'tertiaryLight', dark: 'tertiaryDark' }}
justify="center"
align="center"
>
{extensionData?.description || extensionData?.displayName}
</Text>
</Stack>
<ExtensionIcon size="xs" type={iconType} />
</Stack>
)}
</Stack>

<Stack
direction="column"
justify={showMenu ? 'between' : 'end'}
align="end"
customStyle="shrink-0"
padding={showMenu ? 'p-0' : 'pr-4'}
<Text
variant="footnotes2"
weight="normal"
color={{ light: 'grey4', dark: 'grey7' }}
truncate
>
{showMenu && (
<Menu
anchor={{
icon: <EllipsisHorizontalIcon />,
variant: 'primary',
greyBg: true,
iconOnly: true,
'aria-label': 'settings',
}}
items={menuItems(
getExtensionStatus(
extensionData?.localDraft,
appStreamData?.edges[0]?.node?.status,
),
)}
customStyle="w-max z-99"
/>
{extensionData?.description || extensionData?.displayName}
</Text>
</Stack>
</Stack>

<Stack
direction="column"
justify={showMenu ? 'between' : 'end'}
align="end"
customStyle="shrink-0"
padding={showMenu ? 'p-0' : 'pr-4'}
>
{showMenu && (
<Menu
anchor={{
icon: <EllipsisHorizontalIcon />,
variant: 'primary',
greyBg: true,
iconOnly: true,
'aria-label': 'settings',
}}
items={menuItems(
getExtensionStatus(
extensionData?.localDraft,
appStreamData?.edges[0]?.node?.status,
),
)}
<Stack direction="row" align="center" spacing="gap-x-1.5">
<Stack
customStyle={`w-2 h-2 rounded-full ${getStatusIndicatorStyle(extensionData?.localDraft, appStreamData?.edges[0]?.node?.status)}`}
/>
<Text variant="footnotes2" weight="normal">
{getExtensionStatus(
extensionData?.localDraft,
appStreamData?.edges[0]?.node?.status,
)}
</Text>
</Stack>
</Stack>
customStyle="w-max z-99"
/>
)}
<Stack direction="row" align="center" spacing="gap-x-1.5">
<Stack
customStyle={`w-2 h-2 rounded-full ${getStatusIndicatorStyle(extensionData?.localDraft, appStreamData?.edges[0]?.node?.status)}`}
/>
<Text variant="footnotes2" weight="normal">
{getExtensionStatus(extensionData?.localDraft, appStreamData?.edges[0]?.node?.status)}
</Text>
</Stack>
{showDivider && <Divider />}
</Stack>
)}
</>
</Stack>
{showDivider && <Divider />}
</Stack>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { useGetAppsByPublisherDidQuery } from '@akashaorg/ui-awf-hooks/lib/generated/apollo';
import {
EventTypes,
Extension,
ExtensionStatus,
NotificationEvents,
NotificationTypes,
Expand Down Expand Up @@ -94,7 +93,6 @@ export const MyExtensionsPage: React.FC<unknown> = () => {
error,
loading,
fetchMore,
refetch,
} = useGetAppsByPublisherDidQuery({
variables: {
id: authenticatedDID,
Expand Down Expand Up @@ -151,9 +149,6 @@ export const MyExtensionsPage: React.FC<unknown> = () => {
next: (eventInfo: UIEventData) => {
if (eventInfo.event === EventTypes.RefetchMyExtensions) {
getDraftExtensions();
refetch({
id: authenticatedDID,
});
}
},
});
Expand All @@ -163,12 +158,7 @@ export const MyExtensionsPage: React.FC<unknown> = () => {
eventsSub.unsubscribe();
}
};
}, [authenticatedDID, getDraftExtensions, refetch]);

const allMyExtensions = useMemo(
() => [...draftExtensions, ...appElements],
[draftExtensions, appElements],
);
}, [authenticatedDID, getDraftExtensions]);

const handleConnectButtonClick = () => {
navigateTo?.({
Expand All @@ -181,6 +171,11 @@ export const MyExtensionsPage: React.FC<unknown> = () => {
});
};

const allMyExtensions = useMemo(
() => [...draftExtensions, ...appElements],
[draftExtensions, appElements],
);

if (!authenticatedDID) {
return (
<ErrorLoader
Expand Down Expand Up @@ -267,7 +262,7 @@ export const MyExtensionsPage: React.FC<unknown> = () => {
const extensionData = allMyExtensions[itemIndex];
return (
<ExtensionElement
extensionData={extensionData as Extension}
extensionData={extensionData}
showDivider={itemIndex < allMyExtensions.length - 1}
filter={selectedStatus}
filterShowAllOptionValue={extensionStatusMenuItems[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@ import { useUpdateAppMutation } from '@akashaorg/ui-awf-hooks/lib/generated/apol
import Text from '@akashaorg/design-system-core/lib/components/Text';
import getSDK from '@akashaorg/core-sdk';
import { DRAFT_EXTENSIONS, DRAFT_RELEASES } from '../../constants';
import { updateAppMutationCache } from './update-app-mutation-cache';

const Component: React.FC<IRootExtensionProps> = () => {
const sdk = getSDK();
const { t } = useTranslation();
const { modalData } = useModalData();
const [updateApp, updateAppQuery] = useUpdateAppMutation({
context: { source: sdk.services.gql.contextSources.composeDB },
update: (
cache,
{
data: {
updateAkashaApp: {
document: { id },
},
},
},
) => {
updateAppMutationCache({ cache, authenticatedDID, removedAppId: id });
},
});
const { uiEvents } = useRootComponentProps();
const {
Expand Down
Loading