Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
8f8a54be
Commit
8f8a54be
authored
May 13, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
display mixed submit result
parent
0499c291
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
20 deletions
+130
-20
PublicTagsSubmit.tsx
ui/pages/PublicTagsSubmit.tsx
+1
-1
PublicTagsSubmitResult.tsx
ui/publicTags/submit/PublicTagsSubmitResult.tsx
+2
-2
mocks.ts
ui/publicTags/submit/mocks.ts
+42
-4
PublicTagsSubmitResultSuccess.tsx
...ublicTags/submit/result/PublicTagsSubmitResultSuccess.tsx
+1
-1
PublicTagsSubmitResultWithErrors.tsx
...icTags/submit/result/PublicTagsSubmitResultWithErrors.tsx
+72
-6
utils.ts
ui/publicTags/submit/utils.ts
+12
-6
No files found.
ui/pages/PublicTagsSubmit.tsx
View file @
8f8a54be
...
@@ -15,7 +15,7 @@ type Screen = 'form' | 'result' | 'initializing' | 'error';
...
@@ -15,7 +15,7 @@ type Screen = 'form' | 'result' | 'initializing' | 'error';
const
PublicTagsSubmit
=
()
=>
{
const
PublicTagsSubmit
=
()
=>
{
const
[
screen
,
setScreen
]
=
React
.
useState
<
Screen
>
(
'
result
'
);
const
[
screen
,
setScreen
]
=
React
.
useState
<
Screen
>
(
'
result
'
);
const
[
submitResult
,
setSubmitResult
]
=
React
.
useState
<
FormSubmitResult
>
(
mocks
.
allSuccess
Responses
);
const
[
submitResult
,
setSubmitResult
]
=
React
.
useState
<
FormSubmitResult
>
(
mocks
.
mixed
Responses
);
const
configQuery
=
useApiQuery
(
'
address_metadata_tag_types
'
);
const
configQuery
=
useApiQuery
(
'
address_metadata_tag_types
'
);
...
...
ui/publicTags/submit/PublicTagsSubmitResult.tsx
View file @
8f8a54be
...
@@ -18,7 +18,7 @@ interface Props {
...
@@ -18,7 +18,7 @@ interface Props {
const
PublicTagsSubmitResult
=
({
data
}:
Props
)
=>
{
const
PublicTagsSubmitResult
=
({
data
}:
Props
)
=>
{
const
groupedData
=
React
.
useMemo
(()
=>
groupSubmitResult
(
data
),
[
data
]);
const
groupedData
=
React
.
useMemo
(()
=>
groupSubmitResult
(
data
),
[
data
]);
const
hasErrors
=
groupedData
.
items
.
length
>
0
&&
groupedData
.
items
[
0
].
error
!==
null
;
const
hasErrors
=
groupedData
.
items
.
some
((
item
)
=>
item
.
error
!==
null
)
;
const
companyWebsite
=
makePrettyLink
(
groupedData
.
companyWebsite
);
const
companyWebsite
=
makePrettyLink
(
groupedData
.
companyWebsite
);
return
(
return
(
...
@@ -52,7 +52,7 @@ const PublicTagsSubmitResult = ({ data }: Props) => {
...
@@ -52,7 +52,7 @@ const PublicTagsSubmitResult = ({ data }: Props) => {
</
Grid
>
</
Grid
>
<
Box
as=
"h2"
textStyle=
"h4"
mt=
{
8
}
mb=
{
5
}
>
Public tags/labels
</
Box
>
<
Box
as=
"h2"
textStyle=
"h4"
mt=
{
8
}
mb=
{
5
}
>
Public tags/labels
</
Box
>
{
hasErrors
?
<
PublicTagsSubmitResultWithErrors
data=
{
d
ata
}
/>
:
<
PublicTagsSubmitResultSuccess
data=
{
groupedData
}
/>
}
{
hasErrors
?
<
PublicTagsSubmitResultWithErrors
data=
{
groupedD
ata
}
/>
:
<
PublicTagsSubmitResultSuccess
data=
{
groupedData
}
/>
}
<
Button
size=
"lg"
mt=
{
8
}
as=
"a"
href=
{
route
({
pathname
:
'
/public-tags/submit
'
})
}
>
Add new tag
</
Button
>
<
Button
size=
"lg"
mt=
{
8
}
as=
"a"
href=
{
route
({
pathname
:
'
/public-tags/submit
'
})
}
>
Add new tag
</
Button
>
</
div
>
</
div
>
...
...
ui/publicTags/submit/mocks.ts
View file @
8f8a54be
import
type
{
FormSubmitResultItem
}
from
'
./types
'
;
import
type
{
FormSubmitResultItem
}
from
'
./types
'
;
const
address1
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
9
'
;
const
address1
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
1
'
;
const
address2
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
8
'
;
const
address2
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
2
'
;
const
address3
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
7
'
;
const
address3
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
3
'
;
const
address4
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
6
'
;
const
address4
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB585
4
'
;
const
address5
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB5855
'
;
const
address5
=
'
0xd789a607CEac2f0E14867de4EB15b15C9FFB5855
'
;
const
responseBaseFields
=
{
const
responseBaseFields
=
{
...
@@ -57,3 +57,41 @@ export const allSuccessResponses: Array<FormSubmitResultItem> = [
...
@@ -57,3 +57,41 @@ export const allSuccessResponses: Array<FormSubmitResultItem> = [
},
},
}))))
}))))
.
flat
();
.
flat
();
export
const
mixedResponses
:
Array
<
FormSubmitResultItem
>
=
[
// address1
{
error
:
null
,
payload
:
{
address
:
address1
,
...
tag1
},
},
{
error
:
'
Some error
'
,
payload
:
{
address
:
address1
,
...
tag2
},
},
{
error
:
'
Some error
'
,
payload
:
{
address
:
address1
,
...
tag3
},
},
// address2
{
error
:
'
Some error
'
,
payload
:
{
address
:
address2
,
...
tag2
},
},
{
error
:
'
Some error
'
,
payload
:
{
address
:
address2
,
...
tag3
},
},
// address3
{
error
:
'
Some error
'
,
payload
:
{
address
:
address3
,
...
tag1
},
},
{
error
:
'
Another nasty error
'
,
payload
:
{
address
:
address3
,
...
tag2
},
},
{
error
:
null
,
payload
:
{
address
:
address3
,
...
tag3
},
},
].
map
((
item
)
=>
({
...
item
,
payload
:
{
...
item
.
payload
,
...
responseBaseFields
}
}));
ui/publicTags/submit/result/PublicTagsSubmitResultSuccess.tsx
View file @
8f8a54be
...
@@ -18,7 +18,7 @@ const PublicTagsSubmitResultSuccess = ({ data }: Props) => {
...
@@ -18,7 +18,7 @@ const PublicTagsSubmitResultSuccess = ({ data }: Props) => {
<
Grid
gridTemplateColumns=
{
{
base
:
'
1fr
'
,
lg
:
'
1fr 1fr
'
}
}
rowGap=
{
3
}
columnGap=
{
3
}
>
<
Grid
gridTemplateColumns=
{
{
base
:
'
1fr
'
,
lg
:
'
1fr 1fr
'
}
}
rowGap=
{
3
}
columnGap=
{
3
}
>
<
GridItem
>
<
GridItem
>
<
Box
fontSize=
"sm"
color=
"text_secondary"
fontWeight=
{
500
}
>
Smart contract / Address (0x...)
</
Box
>
<
Box
fontSize=
"sm"
color=
"text_secondary"
fontWeight=
{
500
}
>
Smart contract / Address (0x...)
</
Box
>
<
Flex
flexDir=
"column"
rowGap=
{
3
}
mt=
{
2
}
>
<
Flex
flexDir=
"column"
rowGap=
{
2
}
mt=
{
2
}
>
{
data
.
items
{
data
.
items
.
map
(({
addresses
})
=>
addresses
)
.
map
(({
addresses
})
=>
addresses
)
.
flat
()
.
flat
()
...
...
ui/publicTags/submit/result/PublicTagsSubmitResultWithErrors.tsx
View file @
8f8a54be
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Button
,
Flex
,
Grid
,
GridItem
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
FormSubmitResult
}
from
'
../types
'
;
import
type
{
FormSubmitResultGrouped
}
from
'
../types
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
AddressEntity
from
'
ui/shared/entities/address/AddressEntity
'
;
import
EntityTag
from
'
ui/shared/EntityTags/EntityTag
'
;
interface
Props
{
interface
Props
{
data
:
FormSubmitResult
;
data
:
FormSubmitResult
Grouped
;
}
}
const
PublicTagsSubmitResultWithErrors
=
(
props
:
Props
)
=>
{
const
PublicTagsSubmitResultWithErrors
=
({
data
}:
Props
)
=>
{
return
<
Box
>
{
props
.
data
.
length
}
</
Box
>;
const
isMobile
=
useIsMobile
();
const
bgColorSuccess
=
useColorModeValue
(
'
green.50
'
,
'
green.800
'
);
const
bgColorError
=
useColorModeValue
(
'
red.50
'
,
'
red.800
'
);
return
(
<
Flex
flexDir=
"column"
rowGap=
{
3
}
>
{
data
.
items
.
map
((
item
,
index
)
=>
{
return
(
<
Flex
key=
{
index
}
flexDir=
{
{
base
:
'
column
'
,
lg
:
'
row
'
}
}
>
<
Box
flexGrow=
{
1
}
>
<
Grid
gridTemplateColumns=
{
{
base
:
'
1fr
'
,
lg
:
'
1fr 1fr
'
}
}
bgColor=
{
item
.
error
?
bgColorError
:
bgColorSuccess
}
borderRadius=
"base"
rowGap=
{
3
}
>
<
GridItem
px=
{
6
}
pt=
{
4
}
pb=
{
{
base
:
0
,
lg
:
4
}
}
>
<
Box
fontSize=
"sm"
color=
"text_secondary"
fontWeight=
{
500
}
>
Smart contract / Address (0x...)
</
Box
>
<
Flex
flexDir=
"column"
rowGap=
{
2
}
mt=
{
2
}
>
{
item
.
addresses
.
map
((
hash
)
=>
(
<
AddressEntity
key=
{
hash
}
address=
{
{
hash
}
}
noIcon
truncation=
{
isMobile
?
'
constant
'
:
'
dynamic
'
}
/>
))
}
</
Flex
>
</
GridItem
>
<
GridItem
px=
{
6
}
pb=
{
4
}
pt=
{
{
base
:
0
,
lg
:
4
}
}
>
<
Box
fontSize=
"sm"
color=
"text_secondary"
fontWeight=
{
500
}
>
Tag
</
Box
>
<
Flex
rowGap=
{
2
}
columnGap=
{
2
}
mt=
{
2
}
justifyContent=
"flex-start"
flexWrap=
"wrap"
>
{
item
.
tags
.
map
((
tag
)
=>
(
<
EntityTag
key=
{
tag
.
name
}
truncate
data=
{
{
...
tag
,
slug
:
''
,
ordinal
:
0
}
}
/>
))
}
</
Flex
>
</
GridItem
>
</
Grid
>
{
item
.
error
&&
<
Box
color=
"red.500"
mt=
{
1
}
fontSize=
"sm"
>
{
item
.
error
}
</
Box
>
}
</
Box
>
{
item
.
error
&&
(
<
Button
variant=
"outline"
size=
"sm"
flexShrink=
{
0
}
mt=
{
{
base
:
1
,
lg
:
6
}
}
ml=
{
{
base
:
0
,
lg
:
6
}
}
w=
"min-content"
>
Start over
</
Button
>
)
}
{
!
item
.
error
&&
!
isMobile
&&
<
Box
w=
"95px"
ml=
{
6
}
flexShrink=
{
0
}
/>
}
</
Flex
>
);
})
}
</
Flex
>
);
};
};
export
default
PublicTagsSubmitResultWithErrors
;
export
default
React
.
memo
(
PublicTagsSubmitResultWithErrors
)
;
ui/publicTags/submit/utils.ts
View file @
8f8a54be
import
type
{
FormSubmitResult
,
FormSubmitResultGrouped
,
FormSubmitResultItemGrouped
}
from
'
./types
'
;
import
_isEqual
from
'
lodash/isEqual
'
;
const
tagIdentity
=
(
tag
:
FormSubmitResultItemGrouped
[
'
tags
'
][
number
])
=>
tag
.
name
+
'
:
'
+
tag
.
tagType
;
import
type
{
FormSubmitResult
,
FormSubmitResultGrouped
,
FormSubmitResultItemGrouped
}
from
'
./types
'
;
export
function
groupSubmitResult
(
data
:
FormSubmitResult
):
FormSubmitResultGrouped
{
export
function
groupSubmitResult
(
data
:
FormSubmitResult
):
FormSubmitResultGrouped
{
const
_items
:
Array
<
FormSubmitResultItemGrouped
>
=
[];
const
_items
:
Array
<
FormSubmitResultItemGrouped
>
=
[];
...
@@ -24,9 +24,7 @@ export function groupSubmitResult(data: FormSubmitResult): FormSubmitResultGroup
...
@@ -24,9 +24,7 @@ export function groupSubmitResult(data: FormSubmitResult): FormSubmitResultGroup
// merge items with the same error and tags
// merge items with the same error and tags
for
(
const
item
of
_items
)
{
for
(
const
item
of
_items
)
{
const
existingItem
=
items
.
find
(({
error
,
tags
})
=>
error
===
item
.
error
&&
const
existingItem
=
items
.
find
(({
error
,
tags
})
=>
error
===
item
.
error
&&
_isEqual
(
tags
,
item
.
tags
));
tags
.
length
===
item
.
tags
.
length
&&
tags
.
every
(
tagIdentity
),
);
if
(
existingItem
)
{
if
(
existingItem
)
{
existingItem
.
addresses
.
push
(...
item
.
addresses
);
existingItem
.
addresses
.
push
(...
item
.
addresses
);
continue
;
continue
;
...
@@ -40,6 +38,14 @@ export function groupSubmitResult(data: FormSubmitResult): FormSubmitResultGroup
...
@@ -40,6 +38,14 @@ export function groupSubmitResult(data: FormSubmitResult): FormSubmitResultGroup
requesterEmail
:
data
[
0
].
payload
.
requesterEmail
,
requesterEmail
:
data
[
0
].
payload
.
requesterEmail
,
companyName
:
data
[
0
].
payload
.
companyName
,
companyName
:
data
[
0
].
payload
.
companyName
,
companyWebsite
:
data
[
0
].
payload
.
companyWebsite
,
companyWebsite
:
data
[
0
].
payload
.
companyWebsite
,
items
,
items
:
items
.
sort
((
a
,
b
)
=>
{
if
(
a
.
error
&&
!
b
.
error
)
{
return
1
;
}
if
(
!
a
.
error
&&
b
.
error
)
{
return
-
1
;
}
return
0
;
}),
};
};
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment