Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Make parent resource not mandatory #73

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 3 additions & 5 deletions packages/app/src/components/ResourceFinder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type InputSelectProps
} from '@commercelayer/app-elements/dist/ui/forms/InputSelect'

interface Props {
interface Props extends Pick<InputSelectProps, 'feedback' | 'hint'> {
/**
* Text to show above the input
*/
Expand All @@ -33,10 +33,6 @@ interface Props {
* callback function fired when the resource is selected from the list
*/
onSelect?: (resourceId: string | null) => void
/**
* Validation feedback
*/
feedback?: InputSelectProps['feedback']
}

export function ResourceFinder({
Expand All @@ -45,6 +41,7 @@ export function ResourceFinder({
resourceType,
sdkClient,
feedback,
hint,
onSelect
}: Props): JSX.Element {
const [isLoading, setIsLoading] = useState(true)
Expand Down Expand Up @@ -85,6 +82,7 @@ export function ResourceFinder({
initialValues={initialValues}
isClearable
feedback={feedback}
hint={hint}
placeholder={placeholder}
isLoading={isLoading}
onSelect={(selected) => {
Expand Down
17 changes: 4 additions & 13 deletions packages/app/src/pages/NewImportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function NewImportPage(): JSX.Element {
)
const [_location, setLocation] = useLocation()

const [isTouched, setIsTouched] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const [apiError, setApiError] = useState<string | undefined>()
const [parentResourceId, setParentResourceId] = useState<string | null>()
Expand Down Expand Up @@ -128,9 +127,7 @@ function NewImportPage(): JSX.Element {

const parentResource = getParentResourceIfNeeded(resourceType)
const canCreateImport =
importCreateValue != null &&
importCreateValue.length > 0 &&
(parentResourceId != null || parentResource === false)
importCreateValue != null && importCreateValue.length > 0

return (
<PageLayout
Expand Down Expand Up @@ -160,14 +157,9 @@ function NewImportPage(): JSX.Element {
resourceType={parentResource}
sdkClient={sdkClient}
onSelect={setParentResourceId}
feedback={
parentResourceId == null && isTouched
? {
message: 'Please select a parent resource',
variant: 'danger'
}
: undefined
}
hint={{
text: 'Required when creating new records. Can also be specified in the import data, for each single record.'
}}
/>
</Spacer>
)}
Expand Down Expand Up @@ -215,7 +207,6 @@ function NewImportPage(): JSX.Element {
<Button
variant='primary'
onClick={() => {
setIsTouched(true)
if (!canCreateImport) {
return
}
Expand Down
Loading