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

Dev aaron #209

Merged
merged 17 commits into from
Jul 19, 2023
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
47 changes: 16 additions & 31 deletions pephub/routers/api/v1/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def update_a_pep(
if namespace not in (list_of_admins or []):
return JSONResponse(
content={
"message": "Unothorized for updating projects.",
"message": "Unauthorized for updating projects.",
},
status_code=401,
)
Expand All @@ -109,24 +109,12 @@ async def update_a_pep(

# sample table update
if updated_project.sample_table is not None:
sample_table_df = pd.DataFrame.from_dict(updated_project.sample_table)
sample_table_df_json = sample_table_df.to_dict(orient="records")

new_raw_project[SAMPLE_RAW_DICT_KEY] = sample_table_df_json
new_raw_project[SAMPLE_RAW_DICT_KEY] = updated_project.sample_table
new_raw_project[CONFIG_KEY] = current_project.config.to_dict()

# subsample table update
if updated_project.subsample_table is not None:
subsample_peppy_list = []
for subsample in updated_project.subsample_table:
subsample_str = subsample.rstrip(",")
subsample_str = StringIO(subsample_str)
subsample_pd = pd.read_csv(subsample_str)
subsample_df = subsample_pd.to_dict(orient="records")

subsample_peppy_list.append(subsample_df)

new_raw_project[SUBSAMPLE_RAW_LIST_KEY] = subsample_peppy_list
if updated_project.subsample_tables is not None:
new_raw_project[SUBSAMPLE_RAW_LIST_KEY] = updated_project.subsample_tables

if updated_project.description:
new_raw_project["_config"]["description"] = updated_project.description
Expand All @@ -141,7 +129,7 @@ async def update_a_pep(
[
updated_project.project_config_yaml is not None,
updated_project.sample_table is not None,
updated_project.subsample_table is not None,
updated_project.subsample_tables is not None,
]
):
try:
Expand All @@ -151,20 +139,17 @@ async def update_a_pep(
status_code=400,
detail=f"Could not create PEP from provided yaml. Error: {e}",
)
# validate each sample in the table according to the project
for s in new_project.samples:
sample_name: str = s[new_project.st_index]
try:
eido.validate_sample(
new_project,
sample_name,
"http://schema.databio.org/pep/2.0.0.yaml", # just use the base PEP schema for now
)
except Exception as e:
raise HTTPException(
status_code=400,
detail=f"Sample {sample_name} failed validation: {e}",
)

try:
# validate project (it will also validate samples)
eido.validate_project(
new_project, "http://schema.databio.org/pep/2.1.0.yaml"
)
except Exception as e:
raise HTTPException(
status_code=400,
detail=f"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? no detail

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note sure about this from @khoroshevskyi

)

# if we get through all samples, then update project in the database
agent.project.update(
Expand Down
2 changes: 1 addition & 1 deletion pephub/routers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProjectOptional(UpdateItems):
sample_table: Optional[List[dict]]
project_config_yaml: Optional[str]
description: Optional[str]
subsample_table: Optional[List[dict]]
subsample_tables: Optional[List[List[dict]]]

class Config:
allow_population_by_field_name = True
Expand Down
26 changes: 26 additions & 0 deletions web/src/api/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,29 @@ export const editProjectSubsampleTable = (
{ headers: { Authorization: `Bearer ${token}` } },
);
};

export const editTotalProject = (
namespace: string,
projectName: string,
tag: string = 'default',
token: string | null,
data: {
config?: string;
samples?: Sample[];
subsamples?: Sample[];
},
) => {
const url = `${API_BASE}/projects/${namespace}/${projectName}?tag=${tag}`;
let requestBody = {};
if (data.config) {
requestBody = { ...requestBody, project_config_yaml: data.config };
}
if (data.samples) {
requestBody = { ...requestBody, sample_table: data.samples };
}
if (data.subsamples && data.subsamples.length > 0) {
requestBody = { ...requestBody, subsample_tables: [data.subsamples] };
}

return axios.patch(url, requestBody, { headers: { Authorization: `Bearer ${token}` } });
};
10 changes: 5 additions & 5 deletions web/src/components/layout/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ export const Nav: FC = () => {
<i className="bi bi-check2-circle me-1"></i>Validation
</a>
</li>
<li className="text-body mx-2 my-0 nav-item h5 pt-1">
<a className="nav-link" href="/about">
<i className="bi bi-info-circle me-1"></i>About
</a>
</li>
{/*<li className="text-body mx-2 my-0 nav-item h5 pt-1">*/}
{/* <a className="nav-link" href="/about">*/}
{/* <i className="bi bi-info-circle me-1"></i>About*/}
{/* </a>*/}
{/*</li>*/}
<li className="text-body mx-2 my-0 nav-item h5 pt-1">
{user ? (
<div className="mx-2 my-0 nav-item h5 pt-1">
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/markdown/render.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import { FC, useEffect, useState } from 'react';
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
import remarkBreaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';
Expand Down
35 changes: 35 additions & 0 deletions web/src/hooks/mutations/useTotalProjectChangeMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { toast } from 'react-hot-toast';

import { Sample } from '../../../types';
import { editTotalProject } from '../../api/project';

interface TotalProjectChangeMutationProps {
config?: string;
samples?: Sample[];
subsamples?: Sample[];
}

export const useTotalProjectChangeMutation = (
namespace: string,
project: string,
tag: string,
jwt: string,
data: TotalProjectChangeMutationProps,
) => {
const queryClient = useQueryClient();

const mutation = useMutation({
mutationFn: () => editTotalProject(namespace || '', project || '', tag, jwt || '', data),
onSuccess: () => {
queryClient.invalidateQueries([namespace, project, tag]);
toast.success('Successfully updated the project!');
},
onError: (error: AxiosError) => {
toast.error(`Failed to update project: ${error}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the near future, we can add proper error handling

},
});

return mutation;
};
4 changes: 2 additions & 2 deletions web/src/pages/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function About() {
<PageLayout fullWidth>
<div className="mx-5" style={{ height: '80vh' }}>
<div className="d-flex flex-column align-items-center justify-content-center">
<div className="row align-items-center">
<h1 className="fw-bolder">Let's build from here.</h1>
<div className="row align-items-center mt-2">
<h1 className="fw-bolder">Coming soon.</h1>
</div>
</div>
</div>
Expand Down
49 changes: 31 additions & 18 deletions web/src/pages/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SampleTable } from '../components/tables/sample-table';
import { useConfigMutation } from '../hooks/mutations/useConfigMutation';
import { useSampleTableMutation } from '../hooks/mutations/useSampleTableMutation';
import { useSubsampleTableMutation } from '../hooks/mutations/useSubsampleTableMutation';
import { useTotalProjectChangeMutation } from '../hooks/mutations/useTotalProjectChangeMutation';
import { useProject } from '../hooks/queries/useProject';
import { useProjectConfig } from '../hooks/queries/useProjectConfig';
import { useSampleTable } from '../hooks/queries/useSampleTable';
Expand Down Expand Up @@ -137,19 +138,29 @@ export const ProjectPage: FC = () => {
jwt || '',
newProjectSubsamples,
);
const totalProjectMutation = useTotalProjectChangeMutation(namespace || '', project || '', tag, jwt || '', {
config: newProjectConfig,
samples: newProjectSamples,
subsamples: newProjectSubsamples,
});

const handleTotalProjectChange = async () => {
await totalProjectMutation.mutateAsync();
runValidation();
};

const handleProjectChange = async () => {
if (configIsDirty) {
await configMutation.mutateAsync();
runValidation();
runValidation();
}
if (samplesIsDirty) {
await sampleTableMutation.mutateAsync();
runValidation();
runValidation();
}
if (subsamplesIsDirty) {
await subsampleTableMutation.mutateAsync();
runValidation();
runValidation();
}
};

Expand Down Expand Up @@ -185,9 +196,9 @@ export const ProjectPage: FC = () => {
) : null}
</Breadcrumb>
<div className="ms-2 mb-1">
<a className="text-decoration-none" href={`https://schema.databio.org/${projectInfo?.pep_schema}.yaml`}>
<SchemaTag schema={projectInfo?.pep_schema} />
</a>
<a className="text-decoration-none" href={`https://schema.databio.org/${projectInfo?.pep_schema}.yaml`}>
<SchemaTag schema={projectInfo?.pep_schema} />
</a>
</div>
</div>
<div className="d-flex flex-row align-items-start btn-g">
Expand Down Expand Up @@ -321,7 +332,7 @@ export const ProjectPage: FC = () => {
subsampleTableMutation.isLoading ||
!(configIsDirty || samplesIsDirty || subsamplesIsDirty)
}
onClick={() => handleProjectChange()}
onClick={() => handleTotalProjectChange()}
className="fst-italic btn btn-sm btn-success me-1 mb-1 border-dark"
>
{configMutation.isLoading || sampleTableMutation.isLoading || subsampleTableMutation.isLoading
Expand Down Expand Up @@ -369,17 +380,19 @@ export const ProjectPage: FC = () => {
/>
</>
) : (
<ProjectConfigEditor
readOnly={!(projectInfo && canEdit(user, projectInfo))}
value={
projectConfigIsLoading
? 'Loading.'
: projectConfig?.config
? newProjectConfig
: 'No config file found.'
}
setValue={(value) => setNewProjectConfig(value)}
/>
<div className="border border-t">
<ProjectConfigEditor
readOnly={!(projectInfo && canEdit(user, projectInfo))}
value={
projectConfigIsLoading
? 'Loading.'
: projectConfig?.config
? newProjectConfig
: 'No config file found.'
}
setValue={(value) => setNewProjectConfig(value)}
/>
</div>
)}
</div>
</div>
Expand Down
Loading