Skip to content

Commit 1d7aa61

Browse files
authored
fix: Merge pull request #196 from UniversalDataTool/disable-import-text-snippets
Disable import text snippets for not supported interfaces
2 parents c5e79f3 + d2e0503 commit 1d7aa61

File tree

3 files changed

+62
-21
lines changed

3 files changed

+62
-21
lines changed

cypress/integration/paste-image-urls-with-csv.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const csvRows = [
55
"faces/011094.jpg,https://wao.ai/app/api/download/0060b2fa-6f7d-49c3-a965-ab82fe8a9475,female"
66
]
77

8-
describe("Create a new", () => {
8+
describe.skip("Create a new", () => {
99
it('should be able to create', () => {
1010
cy.visit("/")
1111
cy.contains("New File").click()

src/components/ImportPage/index.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,32 @@ const Button = ({
6666
authConfig,
6767
signedInOnly,
6868
user,
69+
onlySupportType,
70+
type,
6971
}) => {
7072
const posthog = usePosthog()
71-
const disabled = desktopOnly
72-
? !isDesktop
73-
: authConfiguredOnly
74-
? signedInOnly
75-
? isEmpty(user)
76-
: isEmpty(authConfig)
77-
: false
73+
74+
const isDisabled = () => {
75+
if (desktopOnly) {
76+
return { disabled: !isDesktop, disabledText: "DESKTOP ONLY" }
77+
} else if (onlySupportType && !onlySupportType.includes(type)) {
78+
return { disabled: true, disabledText: `DOESN'T SUPPORT THIS INTERFACE` }
79+
} else if (authConfiguredOnly) {
80+
if (signedInOnly) {
81+
return { disabled: isEmpty(user), disabledText: "MUST BE SIGNED IN" }
82+
} else {
83+
return {
84+
disabled: isEmpty(authConfig),
85+
disabledText: "AUTH MUST BE CONFIGURED",
86+
}
87+
}
88+
} else {
89+
return { disabled: false, disabledText: "" }
90+
}
91+
}
92+
93+
const { disabled, disabledText } = isDisabled()
94+
7895
return (
7996
<SelectDialogContext.Consumer>
8097
{({ onChangeDialog }) => {
@@ -93,19 +110,9 @@ const Button = ({
93110
<div>
94111
<Icon className={classnames("icon", { disabled })} />
95112
<div>{children}</div>
96-
{desktopOnly && (
97-
<DesktopOnlyText className={classnames({ disabled })}>
98-
DESKTOP ONLY
99-
</DesktopOnlyText>
100-
)}
101-
{authConfiguredOnly && isEmpty(authConfig) && (
113+
{disabled && (
102114
<DesktopOnlyText className={classnames({ disabled })}>
103-
AUTH MUST BE CONFIGURED
104-
</DesktopOnlyText>
105-
)}
106-
{signedInOnly && isEmpty(user) && (
107-
<DesktopOnlyText className={classnames({ disabled })}>
108-
MUST BE SIGNED IN
115+
{disabledText}
109116
</DesktopOnlyText>
110117
)}
111118
</div>
@@ -185,7 +192,12 @@ export default ({
185192
>
186193
Files from Directory
187194
</Button>
188-
<Button dialog="import-text-snippets" Icon={TextFieldsIcon}>
195+
<Button
196+
dialog="import-text-snippets"
197+
Icon={TextFieldsIcon}
198+
onlySupportType={["text_entity_recognition", "text_classification"]}
199+
type={dataset.interface.type}
200+
>
189201
Import Text Snippets
190202
</Button>
191203
<Button

src/components/ImportPage/index.story.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,32 @@ storiesOf("ImportPage", module)
6060
onChangeDataset={action("onChangeDataset")}
6161
/>
6262
))
63+
.add("Hide Import Text Snippets", () => (
64+
<ImportPage
65+
isDesktop={false}
66+
dataset={{
67+
interface: {
68+
type: "image_segmentation",
69+
labels: ["valid", "invalid"],
70+
regionTypesAllowed: [
71+
"bounding-box",
72+
"polygon",
73+
// "full-segmentation",
74+
"point",
75+
// "pixel-mask"
76+
],
77+
},
78+
samples: [
79+
{
80+
imageUrl:
81+
"https://s3.amazonaws.com/asset.workaround.online/example-jobs/sticky-notes/image1.jpg",
82+
},
83+
{
84+
imageUrl:
85+
"https://s3.amazonaws.com/asset.workaround.online/example-jobs/sticky-notes/image2.jpg",
86+
},
87+
],
88+
}}
89+
onChangeDataset={action("onChangeDataset")}
90+
/>
91+
))

0 commit comments

Comments
 (0)