Skip to content

Commit

Permalink
feat(Assets): support files without external source URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Sep 4, 2024
1 parent 8c102f2 commit 0368c12
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
28 changes: 20 additions & 8 deletions client/src/components/ControlledInputs/CtlTextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { FieldValues, FieldPath, Controller } from "react-hook-form";
import { Form, FormInputProps } from "semantic-ui-react";
import { Form, FormInputProps, Icon, Popup } from "semantic-ui-react";
import { ControlledInputProps } from "../../types";

interface CtlTextInputProps extends FormInputProps {
label?: string;
required?: boolean;
showErrorMsg?: boolean;
helpText?: string;
}

/**
Expand All @@ -22,6 +23,7 @@ export default function CtlTextInput<
label,
required = false,
showErrorMsg = true,
helpText,
...rest
}: ControlledInputProps<TFieldValues, TName> & CtlTextInputProps) {
const { className: restClassName } = rest;
Expand All @@ -38,11 +40,21 @@ export default function CtlTextInput<
}) => (
<div className={`${restClassName ?? ""}`}>
{label && (
<label
className={`form-field-label ${required ? "form-required" : ""}`}
>
{label}
</label>
<>
<label
className={`form-field-label ${required ? "form-required" : ""}`}
>
{label}
</label>
{
helpText && (
<Popup
content={helpText}
trigger={<Icon name="question circle outline" className="pl-1" />}
/>
)
}
</>
)}
<Form.Input
value={value}
Expand All @@ -52,8 +64,8 @@ export default function CtlTextInput<
error?.message && showErrorMsg
? error.message
: error?.message
? true
: false
? true
: false
} // Display error message if showErrorMsg is true, otherwise just display error state
className={`mt-1 ${rest.disabled ? 'bg-gray-200 border-slate-600 border rounded-md' : ''}`}
{...rest}
Expand Down
22 changes: 22 additions & 0 deletions client/src/components/FilesManager/EditFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ const EditFile: React.FC<EditFileProps> = ({
onFinishedEdit();
}

function handleNoExternalSource() {
setValue("license.sourceURL", "local");
}

function handleResetExternalSource() {
setValue("license.sourceURL", "");
}

return (
<Modal open={show} onClose={onClose} size="fullscreen" {...rest}>
<Modal.Header>
Expand Down Expand Up @@ -665,7 +673,21 @@ const EditFile: React.FC<EditFileProps> = ({
className="mt-2"
required
rules={required}
helpText="URL where the file was sourced from"
disabled={watch('license.sourceURL') === 'local'}
/>
{
watch("license.sourceURL") !== "local" && (
<p className="text-sky-500 ml-1 mt-1 cursor-pointer hover:underline" onClick={handleNoExternalSource}>
This file doesn't have an external source.
</p>
)}
{
watch("license.sourceURL") === "local" && (
<p className="text-sky-500 ml-1 mt-1 cursor-pointer hover:underline" onClick={handleResetExternalSource}>
Add an external source URL
</p>
)}
<div className="flex items-start mt-3">
<CtlCheckbox
name="license.modifiedFromSource"
Expand Down
2 changes: 1 addition & 1 deletion server/api/validators/projectfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const projectFileSchema = z.object({
name: z.string().trim().max(255).optional().or(z.literal("")),
url: z.string().trim().url().optional().or(z.literal("")),
version: z.string().trim().max(255).optional().or(z.literal("")),
sourceURL: z.string().url().optional(),
sourceURL: z.string().url().optional().or(z.literal("local")),
modifiedFromSource: z.coerce.boolean().optional(),
additionalTerms: z.string().trim().max(500).optional(),
})
Expand Down

0 comments on commit 0368c12

Please sign in to comment.