Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sample Data checkbox of the Repository Create form #8255

Merged
merged 1 commit into from
Oct 1, 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
20 changes: 8 additions & 12 deletions webui/src/lib/components/repositoryCreateForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,19 @@ import Accordion from "react-bootstrap/Accordion";
const DEFAULT_BLOCKSTORE_EXAMPLE = "e.g. s3://example-bucket/";
const DEFAULT_BLOCKSTORE_VALIDITY_REGEX = new RegExp(`^s3://`);

export const RepositoryCreateForm = ({ id, config, onSubmit, formValid, setFormValid, error = null, sampleRepoChecked = false }) => {
export const RepositoryCreateForm = ({ id, config, onSubmit, formValid, setFormValid, error = null }) => {
const repoValidityRegex = /^[a-z0-9][a-z0-9-]{2,62}$/;

const [repoValid, setRepoValid] = useState(null);
const defaultNamespacePrefix = config.default_namespace_prefix

const [storageNamespaceValid, setStorageNamespaceValid] = useState(defaultNamespacePrefix ? true : null);
const [defaultBranchValid, setDefaultBranchValid] = useState(true);

const [addSampleData, setAddSampleData] = useState(false);

const storageNamespaceField = useRef(null);
const defaultBranchField = useRef(null);
const repoNameField = useRef(null);
const sampleDataCheckbox = useRef(null);

useEffect(() => {
if (sampleDataCheckbox.current) {
sampleDataCheckbox.current.checked = sampleRepoChecked;
}
}, [sampleRepoChecked, sampleDataCheckbox.current]);


const onRepoNameChange = () => {
const isRepoValid = repoValidityRegex.test(repoNameField.current.value);
Expand Down Expand Up @@ -64,7 +57,10 @@ export const RepositoryCreateForm = ({ id, config, onSubmit, formValid, setFormV

const sampleCheckbox = (
<Form.Group controlId="sampleData" className="mt-3">
<Form.Check ref={sampleDataCheckbox} type="checkbox" label="Add sample data, hooks, and configuration" />
<Form.Check type="checkbox"
label="Add sample data, hooks, and configuration"
onChange={(ev) => setAddSampleData(ev.target.checked)}
/>
</Form.Group>
);

Expand Down Expand Up @@ -154,7 +150,7 @@ export const RepositoryCreateForm = ({ id, config, onSubmit, formValid, setFormV
name: repoNameField.current.value,
storage_namespace: storageNamespaceField.current.value,
default_branch: defaultBranchField.current.value,
sample_data: sampleDataCheckbox.current.checked,
sample_data: addSampleData,
});
}}>
<h4 className="mb-3">Create A New Repository</h4>
Expand Down
7 changes: 1 addition & 6 deletions webui/src/pages/repositories/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const GettingStartedCreateRepoButton = ({text, variant = "success", enabled = fa
);
}

const CreateRepositoryModal = ({show, error, onSubmit, onCancel, inProgress, samlpleRepoChecked = false }) => {
const CreateRepositoryModal = ({show, error, onSubmit, onCancel, inProgress }) => {

const [formValid, setFormValid] = useState(false);

Expand Down Expand Up @@ -79,7 +79,6 @@ const CreateRepositoryModal = ({show, error, onSubmit, onCancel, inProgress, sam
onSubmit={onSubmit}
onCancel={onCancel}
inProgress={inProgress}
sampleRepoChecked={samlpleRepoChecked}
/>
</Modal.Body>
<Modal.Footer>
Expand Down Expand Up @@ -186,7 +185,6 @@ const RepositoryList = ({ onPaginate, prefix, after, refresh, onCreateSampleRepo
const RepositoriesPage = () => {
const router = useRouter();
const [showCreateRepositoryModal, setShowCreateRepositoryModal] = useState(false);
const [sampleRepoChecked, setSampleRepoChecked] = useState(false);
const [createRepoError, setCreateRepoError] = useState(null);
const [refresh, setRefresh] = useState(false);
const [creatingRepo, setCreatingRepo] = useState(false);
Expand Down Expand Up @@ -222,7 +220,6 @@ const RepositoriesPage = () => {
}, [setShowActionsBar]);

const createRepositoryButtonCallback = useCallback(() => {
setSampleRepoChecked(false);
setShowCreateRepositoryModal(true);
setCreateRepoError(null);
}, [showCreateRepositoryModal, setShowCreateRepositoryModal]);
Expand All @@ -240,7 +237,6 @@ const RepositoriesPage = () => {
await createRepo(sampleRepo);
return;
}
setSampleRepoChecked(true);
setShowCreateRepositoryModal(true);
setCreateRepoError(null);
}, [showCreateRepositoryModal, setShowCreateRepositoryModal, loading, err, response, createRepo]);
Expand Down Expand Up @@ -294,7 +290,6 @@ const RepositoriesPage = () => {
show={showCreateRepositoryModal}
error={createRepoError}
onSubmit={(repo) => createRepo(repo, true)}
samlpleRepoChecked={sampleRepoChecked}
inProgress={creatingRepo}
/>

Expand Down
Loading