Skip to content

Commit 6f8b708

Browse files
authored
Added WfoGraphqlErrorsMeta handler, added isLoading to WfoSubscriptionActions, using fragments in some graphql queries, changes required for #1320 (#1380)
1 parent f0fde20 commit 6f8b708

File tree

6 files changed

+91
-63
lines changed

6 files changed

+91
-63
lines changed

.changeset/bright-dragons-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': minor
3+
---
4+
5+
Added WfoGraphqlErrorsMeta handler, added isLoading to WfoSubscriptionActions, using fragments in some graphql queries, changes required for #1320

packages/orchestrator-ui-components/src/components/WfoError/WfoError.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { WfoXCircleFill } from '@/icons';
99
import { WfoGraphqlError } from '@/rtk';
1010

1111
interface WfoErrorWithMessageProps {
12-
error: WfoGraphqlError[];
12+
error: WfoGraphqlError[] | undefined;
1313
}
1414

1515
export const WfoError = () => {
@@ -27,7 +27,7 @@ export const WfoErrorWithMessage = ({ error }: WfoErrorWithMessageProps) => {
2727
const t = useTranslations('common');
2828
const { theme } = useOrchestratorTheme();
2929
const message =
30-
error.length > 0
30+
error && error.length > 0
3131
? error.map((err) => err.message).join(', ')
3232
: t('unknownError');
3333
return (

packages/orchestrator-ui-components/src/components/WfoSubscription/WfoSubscriptionActions.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,24 @@ const MenuBlock: FC<MenuBlockProps> = ({ title }) => (
4444

4545
export type WfoSubscriptionActionsProps = {
4646
subscriptionId: string;
47+
isLoading?: boolean;
4748
};
4849

4950
export const WfoSubscriptionActions: FC<WfoSubscriptionActionsProps> = ({
5051
subscriptionId,
52+
isLoading,
5153
}) => {
5254
const { theme } = useOrchestratorTheme();
5355

5456
const router = useRouter();
5557
const t = useTranslations('subscriptions.detail.actions');
5658
const [isPopoverOpen, setPopover] = useState(false);
57-
const { data: subscriptionActions } = useGetSubscriptionActionsQuery({
58-
subscriptionId,
59-
});
59+
const { data: subscriptionActions } = useGetSubscriptionActionsQuery(
60+
{
61+
subscriptionId,
62+
},
63+
{ skip: isLoading },
64+
);
6065
const { isEngineRunningNow } = useCheckEngineStatus();
6166
const { isAllowed } = usePolicy();
6267

@@ -176,6 +181,7 @@ export const WfoSubscriptionActions: FC<WfoSubscriptionActionsProps> = ({
176181
iconType="arrowDown"
177182
iconSide="right"
178183
onClick={onButtonClick}
184+
isLoading={isLoading}
179185
>
180186
{t('actions')}
181187
</EuiButton>

packages/orchestrator-ui-components/src/rtk/api.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ type ExtraOptions = {
3232
apiName?: string;
3333
};
3434

35+
export type WfoGraphqlError = {
36+
extensions: GraphQLErrorExtensions;
37+
message: string;
38+
};
39+
40+
export type WfoGraphqlErrorsMeta = {
41+
errors: WfoGraphqlError[];
42+
};
43+
3544
export const prepareHeaders = async (headers: Headers) => {
3645
const session = (await getSession()) as WfoSession;
3746
if (session?.accessToken) {
@@ -54,6 +63,12 @@ export const handlePromiseErrorWithCallback = <T>(
5463
});
5564
};
5665

66+
export const handleGraphqlMetaErrors = (meta: WfoGraphqlErrorsMeta) => {
67+
if (meta.errors && meta.errors.length > 0) {
68+
throw meta.errors[0];
69+
}
70+
};
71+
5772
const isUnauthorized = (status: HttpStatus) =>
5873
status === HttpStatus.Unauthorized || status === HttpStatus.Forbidden;
5974
const isNotSuccessful = (status: HttpStatus) =>
@@ -75,11 +90,6 @@ export const catchErrorResponse = async (
7590
}
7691
};
7792

78-
export type WfoGraphqlError = {
79-
extensions: GraphQLErrorExtensions;
80-
message: string;
81-
};
82-
8393
export const orchestratorApi = createApi({
8494
reducerPath: 'orchestratorApi',
8595
baseQuery: (args, api, extraOptions: ExtraOptions) => {

packages/orchestrator-ui-components/src/rtk/endpoints/subscriptionDetail.ts

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,70 @@ import {
77
} from '@/types';
88
import { getCacheTag } from '@/utils/cacheTag';
99

10+
export const subscriptionDetailFragment = `
11+
fragment SubscriptionDetail on SubscriptionInterface {
12+
subscriptionId
13+
description
14+
fixedInputs
15+
insync
16+
note
17+
product {
18+
createdAt
19+
name
20+
status
21+
endDate
22+
description
23+
tag
24+
productType
25+
productId
26+
}
27+
endDate
28+
startDate
29+
status
30+
customerId
31+
metadata
32+
customer {
33+
fullname
34+
customerId
35+
shortcode
36+
}
37+
customerDescriptions {
38+
subscriptionId
39+
description
40+
customerId
41+
}
42+
productBlockInstances {
43+
id
44+
subscription {
45+
subscriptionId
46+
description
47+
}
48+
parent
49+
productBlockInstanceValues
50+
subscriptionInstanceId
51+
inUseByRelations
52+
}
53+
processes(sortBy: { field: "startedAt", order: ASC }) {
54+
page {
55+
processId
56+
lastStatus
57+
startedAt
58+
createdBy
59+
workflowTarget
60+
workflowName
61+
isTask
62+
}
63+
}
64+
}
65+
`;
66+
1067
export const subscriptionDetailQuery = `
1168
query SubscriptionDetail($subscriptionId: String!) {
1269
subscriptions(
1370
filterBy: { field: "subscriptionId", value: $subscriptionId }
1471
) {
1572
page {
16-
subscriptionId
17-
description
18-
fixedInputs
19-
insync
20-
note
21-
product {
22-
createdAt
23-
name
24-
status
25-
endDate
26-
description
27-
tag
28-
productType
29-
productId
30-
}
31-
endDate
32-
startDate
33-
status
34-
customerId
35-
metadata
36-
customer {
37-
fullname
38-
customerId
39-
shortcode
40-
}
41-
customerDescriptions {
42-
subscriptionId
43-
description
44-
customerId
45-
}
46-
productBlockInstances {
47-
id
48-
subscription {
49-
subscriptionId
50-
description
51-
}
52-
parent
53-
productBlockInstanceValues
54-
subscriptionInstanceId
55-
inUseByRelations
56-
}
57-
processes(sortBy: { field: "startedAt", order: ASC }) {
58-
page {
59-
processId
60-
lastStatus
61-
startedAt
62-
createdBy
63-
workflowTarget
64-
workflowName
65-
isTask
66-
}
67-
}
73+
...SubscriptionDetail
6874
}
6975
}
7076
}
@@ -81,7 +87,7 @@ const subscriptionDetailApi = orchestratorApi.injectEndpoints({
8187
{ subscriptionId: string }
8288
>({
8389
query: (variables) => ({
84-
document: subscriptionDetailQuery,
90+
document: subscriptionDetailQuery + subscriptionDetailFragment,
8591
variables,
8692
}),
8793
transformResponse: (

packages/orchestrator-ui-components/src/rtk/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './store';
44
export * from './slices';
55
export * from './storeProvider';
66
export * from './wfoGraphqlRequestBaseQuery';
7+
export * from './utils';

0 commit comments

Comments
 (0)