@haus-tech/badge-plugin 4.0.6 → 4.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/dashboard/badge-detail.tsx +9 -7
- package/src/dashboard/badge-list.tsx +7 -9
- package/src/dashboard/gql.ts +146 -0
- package/src/ui/badge-list.component.d.ts +1 -1
- package/src/ui/badge-list.component.html +2 -2
- package/src/ui/badge-list.component.scss +12 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
Page,
|
|
6
6
|
PageTitle,
|
|
7
7
|
PageActionBar,
|
|
8
|
-
|
|
8
|
+
ActionBarItem,
|
|
9
9
|
PageLayout,
|
|
10
10
|
PageBlock,
|
|
11
11
|
FormFieldWrapper,
|
|
@@ -23,7 +23,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
|
23
23
|
import { useCallback, useState, useRef, useEffect } from 'react'
|
|
24
24
|
import { toast } from 'sonner'
|
|
25
25
|
import { api } from '@vendure/dashboard'
|
|
26
|
-
import { graphql } from '
|
|
26
|
+
import { graphql } from './gql'
|
|
27
27
|
import { UploadIcon } from 'lucide-react'
|
|
28
28
|
import type { ComponentProps } from 'react'
|
|
29
29
|
|
|
@@ -117,7 +117,7 @@ export const badgeDetailRoute: DashboardRouteDefinition = {
|
|
|
117
117
|
],
|
|
118
118
|
}),
|
|
119
119
|
component: (route) => {
|
|
120
|
-
return <BadgeDetailPage route={route as
|
|
120
|
+
return <BadgeDetailPage route={route as AnyRoute} />
|
|
121
121
|
},
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -209,7 +209,9 @@ function BadgeDetailPage({ route }: { route: AnyRoute }) {
|
|
|
209
209
|
const createAssetMutation = useMutation({
|
|
210
210
|
mutationFn: async (file: File) => {
|
|
211
211
|
const input = [{ file }]
|
|
212
|
-
const result
|
|
212
|
+
const result = await api.mutate(createAssetsDocument, { input }) as {
|
|
213
|
+
createAssets: Array<{ id?: string; name?: string; source?: string; preview?: string; message?: string }>
|
|
214
|
+
}
|
|
213
215
|
const assetResult = result.createAssets[0]
|
|
214
216
|
if ('id' in assetResult) {
|
|
215
217
|
return assetResult
|
|
@@ -324,7 +326,7 @@ function BadgeDetailPage({ route }: { route: AnyRoute }) {
|
|
|
324
326
|
toast.success('Badge created successfully')
|
|
325
327
|
await navigate({ to: `/badges/${result.createBadge.id}` })
|
|
326
328
|
queryClient.invalidateQueries({ queryKey: ['badges'] })
|
|
327
|
-
} catch (error:
|
|
329
|
+
} catch (error: unknown) {
|
|
328
330
|
toast.error('Failed to create badge', {
|
|
329
331
|
description: error instanceof Error ? error.message : 'Unknown error',
|
|
330
332
|
})
|
|
@@ -361,7 +363,7 @@ function BadgeDetailPage({ route }: { route: AnyRoute }) {
|
|
|
361
363
|
{creatingNewEntity ? 'New Badge' : entity?.id ? `Badge ${entity.id}` : 'Edit Badge'}
|
|
362
364
|
</PageTitle>
|
|
363
365
|
<PageActionBar>
|
|
364
|
-
<
|
|
366
|
+
<ActionBarItem itemId="save-button">
|
|
365
367
|
<Button
|
|
366
368
|
type="submit"
|
|
367
369
|
disabled={
|
|
@@ -372,7 +374,7 @@ function BadgeDetailPage({ route }: { route: AnyRoute }) {
|
|
|
372
374
|
>
|
|
373
375
|
{isPending || uploading ? 'Saving...' : creatingNewEntity ? 'Create' : 'Update'}
|
|
374
376
|
</Button>
|
|
375
|
-
</
|
|
377
|
+
</ActionBarItem>
|
|
376
378
|
</PageActionBar>
|
|
377
379
|
<PageLayout>
|
|
378
380
|
<PageBlock column="main" blockId="main-form">
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DashboardRouteDefinition,
|
|
3
3
|
ListPage,
|
|
4
|
-
|
|
4
|
+
ActionBarItem,
|
|
5
5
|
Button,
|
|
6
6
|
VendureImage,
|
|
7
7
|
Badge as BadgeComponent,
|
|
8
8
|
} from '@vendure/dashboard'
|
|
9
9
|
import { PencilIcon, PlusIcon } from 'lucide-react'
|
|
10
10
|
import { Link } from '@tanstack/react-router'
|
|
11
|
-
import { graphql } from '
|
|
11
|
+
import { graphql } from './gql'
|
|
12
12
|
|
|
13
13
|
const getBadgeListDocument = graphql(`
|
|
14
14
|
query GetBadges($options: BadgeListOptions) {
|
|
@@ -128,14 +128,12 @@ export const badgeListRoute: DashboardRouteDefinition = {
|
|
|
128
128
|
}}
|
|
129
129
|
defaultColumnOrder={['asset', 'position', 'collection', 'updatedAt']}
|
|
130
130
|
>
|
|
131
|
-
<
|
|
132
|
-
<Button
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
New Badge
|
|
136
|
-
</Link>
|
|
131
|
+
<ActionBarItem itemId="create-button">
|
|
132
|
+
<Button render={<Link to="./new" />}>
|
|
133
|
+
<PlusIcon />
|
|
134
|
+
New Badge
|
|
137
135
|
</Button>
|
|
138
|
-
</
|
|
136
|
+
</ActionBarItem>
|
|
139
137
|
</ListPage>
|
|
140
138
|
)
|
|
141
139
|
},
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import gql from 'graphql-tag'
|
|
2
|
+
import type { TypedDocumentNode } from '@graphql-typed-document-node/core'
|
|
3
|
+
|
|
4
|
+
type AnyDoc = TypedDocumentNode<any, any>
|
|
5
|
+
|
|
6
|
+
const getBadgesDocument = gql(`
|
|
7
|
+
query GetBadges($options: BadgeListOptions) {
|
|
8
|
+
badges(options: $options) {
|
|
9
|
+
items {
|
|
10
|
+
id
|
|
11
|
+
createdAt
|
|
12
|
+
updatedAt
|
|
13
|
+
collection {
|
|
14
|
+
id
|
|
15
|
+
name
|
|
16
|
+
}
|
|
17
|
+
collectionId
|
|
18
|
+
position
|
|
19
|
+
asset {
|
|
20
|
+
id
|
|
21
|
+
name
|
|
22
|
+
type
|
|
23
|
+
mimeType
|
|
24
|
+
width
|
|
25
|
+
height
|
|
26
|
+
fileSize
|
|
27
|
+
source
|
|
28
|
+
preview
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
totalItems
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`) as AnyDoc
|
|
35
|
+
|
|
36
|
+
const deleteBadgeDocument = gql(`
|
|
37
|
+
mutation DeleteBadge($id: ID!) {
|
|
38
|
+
deleteBadge(ids: [$id]) {
|
|
39
|
+
result
|
|
40
|
+
message
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`) as AnyDoc
|
|
44
|
+
|
|
45
|
+
const getBadgeDetailDocument = gql(`
|
|
46
|
+
query GetBadgeDetail($id: ID!) {
|
|
47
|
+
badge(id: $id) {
|
|
48
|
+
id
|
|
49
|
+
createdAt
|
|
50
|
+
updatedAt
|
|
51
|
+
collection {
|
|
52
|
+
id
|
|
53
|
+
name
|
|
54
|
+
}
|
|
55
|
+
collectionId
|
|
56
|
+
position
|
|
57
|
+
assetId
|
|
58
|
+
asset {
|
|
59
|
+
id
|
|
60
|
+
name
|
|
61
|
+
type
|
|
62
|
+
mimeType
|
|
63
|
+
width
|
|
64
|
+
height
|
|
65
|
+
fileSize
|
|
66
|
+
source
|
|
67
|
+
preview
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
`) as AnyDoc
|
|
72
|
+
|
|
73
|
+
const createBadgeDocument = gql(`
|
|
74
|
+
mutation CreateBadge($input: CreateBadgeInput!) {
|
|
75
|
+
createBadge(input: $input) {
|
|
76
|
+
id
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`) as AnyDoc
|
|
80
|
+
|
|
81
|
+
const updateBadgeDocument = gql(`
|
|
82
|
+
mutation UpdateBadge($input: UpdateBadgeInput!) {
|
|
83
|
+
updateBadge(input: $input) {
|
|
84
|
+
id
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`) as AnyDoc
|
|
88
|
+
|
|
89
|
+
const getBadgePluginConfigDocument = gql(`
|
|
90
|
+
query GetBadgePluginConfig {
|
|
91
|
+
getBadgePluginConfig {
|
|
92
|
+
availablePositions
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`) as AnyDoc
|
|
96
|
+
|
|
97
|
+
const getCollectionsDocument = gql(`
|
|
98
|
+
query GetCollections {
|
|
99
|
+
collections {
|
|
100
|
+
items {
|
|
101
|
+
id
|
|
102
|
+
name
|
|
103
|
+
slug
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`) as AnyDoc
|
|
108
|
+
|
|
109
|
+
const createAssetsDocument = gql(`
|
|
110
|
+
mutation CreateAssets($input: [CreateAssetInput!]!) {
|
|
111
|
+
createAssets(input: $input) {
|
|
112
|
+
... on Asset {
|
|
113
|
+
id
|
|
114
|
+
name
|
|
115
|
+
source
|
|
116
|
+
preview
|
|
117
|
+
}
|
|
118
|
+
... on MimeTypeError {
|
|
119
|
+
message
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`) as AnyDoc
|
|
124
|
+
|
|
125
|
+
function normalize(source: string): string {
|
|
126
|
+
return source.replace(/\s+/g, ' ').trim()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const documents = new Map<string, AnyDoc>([
|
|
130
|
+
[normalize(getBadgesDocument.loc?.source.body ?? ''), getBadgesDocument],
|
|
131
|
+
[normalize(deleteBadgeDocument.loc?.source.body ?? ''), deleteBadgeDocument],
|
|
132
|
+
[normalize(getBadgeDetailDocument.loc?.source.body ?? ''), getBadgeDetailDocument],
|
|
133
|
+
[normalize(createBadgeDocument.loc?.source.body ?? ''), createBadgeDocument],
|
|
134
|
+
[normalize(updateBadgeDocument.loc?.source.body ?? ''), updateBadgeDocument],
|
|
135
|
+
[normalize(getBadgePluginConfigDocument.loc?.source.body ?? ''), getBadgePluginConfigDocument],
|
|
136
|
+
[normalize(getCollectionsDocument.loc?.source.body ?? ''), getCollectionsDocument],
|
|
137
|
+
[normalize(createAssetsDocument.loc?.source.body ?? ''), createAssetsDocument],
|
|
138
|
+
])
|
|
139
|
+
|
|
140
|
+
export function graphql(source: string): AnyDoc {
|
|
141
|
+
const document = documents.get(normalize(source))
|
|
142
|
+
if (!document) {
|
|
143
|
+
throw new Error('Unknown dashboard GraphQL operation in badge-plugin')
|
|
144
|
+
}
|
|
145
|
+
return document
|
|
146
|
+
}
|
|
@@ -2,7 +2,7 @@ import { TypedBaseListComponent, NotificationService, ModalService, SelectionMan
|
|
|
2
2
|
import { OnInit, OnChanges, SimpleChanges } from '@angular/core';
|
|
3
3
|
import { Badge } from './gql/graphql';
|
|
4
4
|
import { Asset } from '@vendure/core';
|
|
5
|
-
declare const getBadgeListDocument: import("
|
|
5
|
+
declare const getBadgeListDocument: import("@graphql-typed-document-node/core").TypedDocumentNode<import("./gql/graphql").GetBadgesQuery, import("./gql/graphql").Exact<{
|
|
6
6
|
options?: import("./gql/graphql").InputMaybe<import("./gql/graphql").BadgeListOptions>;
|
|
7
7
|
}>>;
|
|
8
8
|
export interface BadgePluginOptions {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
[disabled]="true"
|
|
28
28
|
[hiddenWhenOff]="true"
|
|
29
29
|
></vdr-select-toggle>
|
|
30
|
-
<img class="asset-thumb" [src]="item.asset | assetPreview
|
|
30
|
+
<img class="asset-thumb" [src]="item.asset | assetPreview: 'medium'" />
|
|
31
31
|
</div>
|
|
32
32
|
<div class="detail">
|
|
33
33
|
<span [title]="item.position">{{ item.position }}</span>
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
<div class="card stack" [class.visible]="selectionManager.selection.length > 1"></div>
|
|
68
68
|
<div class="selection-count" [class.visible]="selectionManager.selection.length > 1">
|
|
69
69
|
{{
|
|
70
|
-
'asset.assets-selected-count' | translate
|
|
70
|
+
'asset.assets-selected-count' | translate: { count: selectionManager.selection.length }
|
|
71
71
|
}}
|
|
72
72
|
<ul>
|
|
73
73
|
<li *ngFor="let asset of selectionManager.selection">{{ asset.name }}</li>
|
|
@@ -86,14 +86,18 @@ vdr-select-toggle {
|
|
|
86
86
|
opacity: 0;
|
|
87
87
|
transform: perspective(500px) translateZ(0px) translateY(-16px);
|
|
88
88
|
height: 16px;
|
|
89
|
-
transition:
|
|
89
|
+
transition:
|
|
90
|
+
transform 0.3s,
|
|
91
|
+
opacity 0s 0.3s;
|
|
90
92
|
background-color: white;
|
|
91
93
|
|
|
92
94
|
&.visible {
|
|
93
95
|
opacity: 1;
|
|
94
96
|
transform: perspective(500px) translateZ(-44px) translateY(0px);
|
|
95
97
|
background-color: var(--color-component-bg-100);
|
|
96
|
-
transition:
|
|
98
|
+
transition:
|
|
99
|
+
transform 0.3s,
|
|
100
|
+
color 0.3s;
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
|
|
@@ -102,11 +106,15 @@ vdr-select-toggle {
|
|
|
102
106
|
position: relative;
|
|
103
107
|
text-align: center;
|
|
104
108
|
visibility: hidden;
|
|
105
|
-
transition:
|
|
109
|
+
transition:
|
|
110
|
+
opacity 0.3s,
|
|
111
|
+
visibility 0s 0.3s;
|
|
106
112
|
&.visible {
|
|
107
113
|
opacity: 1;
|
|
108
114
|
visibility: visible;
|
|
109
|
-
transition:
|
|
115
|
+
transition:
|
|
116
|
+
opacity 0.3s,
|
|
117
|
+
visibility 0s;
|
|
110
118
|
}
|
|
111
119
|
ul {
|
|
112
120
|
text-align: start;
|