Skip to content

Commit

Permalink
feat(client): adapt slug and name of dataset (#2723) (#2854)
Browse files Browse the repository at this point in the history
Fix #2723
  • Loading branch information
andre-code authored Nov 30, 2023
1 parent 519492c commit 772f7db
Show file tree
Hide file tree
Showing 32 changed files with 128 additions and 128 deletions.
4 changes: 2 additions & 2 deletions client/src/api-client/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default function addDatasetMethods(client) {
};

client.fetchDatasetFilesFromCoreService = (
name,
slug,
git_url,
versionUrl = null
) => {
Expand All @@ -173,7 +173,7 @@ export default function addDatasetMethods(client) {
headers.append("X-Requested-With", "XMLHttpRequest");

const url = client.versionedCoreUrl("datasets.files_list", versionUrl);
const queryParams = { git_url, name };
const queryParams = { git_url, slug };

const filesPromise = client
.clientFetch(url, {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/form-field/FileUploaderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function notificationFunction(props: NotificationFunctionArgs) {
? `dataset ${props.dataset.name}`
: "new dataset";
const redirectUrl = props.edit
? `/projects/${props.projectPathWithNamespace}/datasets/${props.dataset.name}/modify`
? `/projects/${props.projectPathWithNamespace}/datasets/${props.dataset.slug}/modify`
: `/projects/${props.projectPathWithNamespace}/datasets/new`;
if (success) {
props.notifications.addSuccess(
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/form-field/KeywordsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function FormGeneratorKeywordsInput({
const tagsList = (
<div className={`input-tag ${disabledClass} ${activeClass}`}>
<ul className="input-tag__tags">
{tags.map((tag, i) => (
{tags?.map((tag, i) => (
<li key={tag}>
{tag}
<FontAwesomeIcon
Expand Down
10 changes: 5 additions & 5 deletions client/src/dataset/Dataset.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default function ShowDataset(props) {
versionUrl,
} = coreSupport;

const findDatasetId = (name, datasets) => {
const dataset = datasets?.find((d) => d.name === name);
const findDatasetId = (slug, datasets) => {
const dataset = datasets?.find((d) => d.slug === slug);
return dataset?.identifier;
};

Expand Down Expand Up @@ -79,9 +79,9 @@ export default function ShowDataset(props) {

// use effect to calculate files
useEffect(() => {
const fetchFiles = (name, externalUrl, versionUrl) => {
const fetchFiles = (slug, externalUrl, versionUrl) => {
props.datasetCoordinator.fetchDatasetFilesFromCoreService(
name,
slug,
externalUrl,
versionUrl
);
Expand All @@ -100,7 +100,7 @@ export default function ShowDataset(props) {
backendAvailable &&
!isFilesFetching
) {
fetchFiles(dataset?.name, externalUrl, versionUrl);
fetchFiles(dataset?.slug, externalUrl, versionUrl);
}
}
}, [
Expand Down
7 changes: 4 additions & 3 deletions client/src/dataset/Dataset.present.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function AddToProjectButton({ insideKg, locked, logged, identifier }) {
) : insideKg === false ? (
<ThrottledTooltip
target="add-dataset-to-project-button"
tooltip="Cannot add dataset to project, the project containing this dataset does not have kg activated"
tooltip="Cannot add dataset to project, the project containing this dataset is not indexed"
/>
) : (
<ThrottledTooltip
Expand Down Expand Up @@ -423,7 +423,7 @@ export default function DatasetView(props) {
}
}

const datasetTitle = dataset.title || dataset.name;
const datasetTitle = dataset.name;
const datasetDesc = dataset.description;
const pageTitle = datasetDesc
? `${datasetTitle} • Dataset • ${datasetDesc}`
Expand Down Expand Up @@ -504,9 +504,10 @@ export default function DatasetView(props) {
labelCaption={datasetPublished ? "Published" : "Created"}
links={linksHeader}
otherButtons={[deleteOption, modifyButton, addToProject]}
slug={dataset.slug}
tagList={dataset.keywords}
timeCaption={timeCaption}
title={dataset.title}
title={dataset.name}
url={dataset.identifier}
/>
</div>
Expand Down
4 changes: 1 addition & 3 deletions client/src/dataset/addtoproject/DatasetAdd.present.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ function HeaderAddDataset({ dataset }: HeaderAddDatasetProps) {
<td className="text-dark fw-bold" style={{ width: "120px" }}>
Dataset Title
</td>
<td data-cy="add-dataset-to-project-title">
{dataset?.title || dataset?.name}
</td>
<td data-cy="add-dataset-to-project-title">{dataset?.name}</td>
</tr>
<tr>
<td className="text-dark fw-bold" style={{ width: "120px" }}>
Expand Down
14 changes: 7 additions & 7 deletions client/src/dataset/addtoproject/DatasetAddToProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function DatasetAddToProject({
monitorJobStatusAndHandleResponse(
jobId,
selectedProject.name,
dataset.name
dataset.slug ?? ""
);
}
});
Expand All @@ -280,7 +280,7 @@ function DatasetAddToProject({
const monitorJobStatusAndHandleResponse = (
job_id: string,
projectPath: string,
datasetName: string
datasetSlug: string
) => {
let cont = 0;
const INTERVAL = 6000;
Expand All @@ -294,7 +294,7 @@ function DatasetAddToProject({
monitorJob,
(cont * INTERVAL) / 1000,
projectPath,
datasetName
datasetSlug
);
} catch (e) {
const error = e as { message?: string };
Expand All @@ -310,7 +310,7 @@ function DatasetAddToProject({
monitorJob: ReturnType<typeof setInterval>,
waitedSeconds: number,
projectPath: string,
datasetName: string
datasetSlug: string
) {
if (!job) return;
switch (job.state) {
Expand All @@ -333,7 +333,7 @@ function DatasetAddToProject({
});
setImportingDataset(false);
clearInterval(monitorJob);
redirectUser(projectPath, datasetName);
redirectUser(projectPath, datasetSlug);
break;
case "FAILED":
setCurrentStatus({
Expand Down Expand Up @@ -362,10 +362,10 @@ function DatasetAddToProject({
}
}

const redirectUser = (projectPath: string, datasetName: string) => {
const redirectUser = (projectPath: string, datasetSlug: string) => {
setCurrentStatus(null);
history.push({
pathname: `/projects/${projectPath}/datasets/${datasetName}`,
pathname: `/projects/${projectPath}/datasets/${datasetSlug}`,
state: { reload: true },
});
};
Expand Down
12 changes: 6 additions & 6 deletions client/src/features/datasets/datasets.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import { PostDataset as DatasetAsApiBody } from "../project/dataset/datasetCore.
export interface DeleteDatasetParams
extends CoreVersionUrl,
CoreRepositoryParams {
name: string;
slug: string;
}

interface DatasetOperationResponse {
name: string;
slug: string;
remote_branch: string;
}

export type DeleteDatasetResponse = CoreResponse<DatasetOperationResponse>;

export interface DeleteDataset {
name: string;
slug: string;
remoteBranch: string;
}

Expand All @@ -49,15 +49,15 @@ export interface PostDatasetParams
}

export interface PostDataset {
name: string;
slug: string;
remoteBranch: string;
}

export type PostDatasetResponse = CoreResponse<DatasetOperationResponse>;

export interface AddFilesParams extends CoreVersionUrl, CoreRepositoryParams {
files: DatasetFile[];
name: string;
slug: string;
}

export interface DatasetFile {
Expand All @@ -74,6 +74,6 @@ export type AddFilesResponse = CoreResponse<AddFilesOperationResponse>;

export interface AddFiles {
files: DatasetFile[];
name: string;
slug: string;
remoteBranch: string;
}
14 changes: 7 additions & 7 deletions client/src/features/datasets/datasetsCore.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export const datasetsCoreApi = createApi({
tagTypes: ["datasets"],
endpoints: (builder) => ({
addFiles: builder.mutation<AddFiles, AddFilesParams>({
query: ({ apiVersion, branch, files, gitUrl, metadataVersion, name }) => {
query: ({ apiVersion, branch, files, gitUrl, metadataVersion, slug }) => {
return {
body: { branch, files, git_url: gitUrl, name },
body: { branch, files, git_url: gitUrl, slug },
method: "POST",
url: versionedPathForEndpoint({
endpoint: "datasets.add",
Expand All @@ -54,14 +54,14 @@ export const datasetsCoreApi = createApi({
if (!response.result) throw new Error("Unexpected response");
return {
files: response.result.files,
name: response.result.name,
slug: response.result.slug,
remoteBranch: response.result.remote_branch,
};
},
}),
deleteDataset: builder.mutation<DeleteDataset, DeleteDatasetParams>({
query: ({ apiVersion, gitUrl, metadataVersion, name }) => {
const body = { git_url: gitUrl, name };
query: ({ apiVersion, gitUrl, metadataVersion, slug }) => {
const body = { git_url: gitUrl, slug };
return {
body,
method: "POST",
Expand All @@ -77,7 +77,7 @@ export const datasetsCoreApi = createApi({
transformResponse: (response: DeleteDatasetResponse) => {
if (!response.result) throw new Error("Unexpected response");
return {
name: response.result.name,
slug: response.result.slug,
remoteBranch: response.result.remote_branch,
};
},
Expand Down Expand Up @@ -114,7 +114,7 @@ export const datasetsCoreApi = createApi({
transformResponse: (response: PostDatasetResponse) => {
if (!response.result) throw new Error("Unexpected response");
return {
name: response.result.name,
slug: response.result.slug,
remoteBranch: response.result.remote_branch,
};
},
Expand Down
1 change: 1 addition & 0 deletions client/src/features/kgSearch/KgSearch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface KgSearchResult {
name: string;
namespace: string;
path: string;
slug: string;
type: EntityType;
visibility: Visibilities;
images: any[]; // eslint-disable-line @typescript-eslint/no-explicit-any
Expand Down
7 changes: 3 additions & 4 deletions client/src/features/project/Project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DatasetImage = {

export interface GetDatasetFilesParams extends CoreVersionUrl {
git_url: string;
name: string;
slug: string;
}

export interface GetDatasetFilesResponse {
Expand Down Expand Up @@ -68,8 +68,8 @@ export type DatasetAbstract = {
keywords: string[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mediaContent: any;
name: string;
title: string;
name: string; // before title
slug: string; // before name
};

export interface DatasetCore extends DatasetAbstract {
Expand All @@ -85,7 +85,6 @@ export interface DatasetKg extends DatasetAbstract {
usedIn: UsedIn;
sameAs?: string;
images?: { location: string }[];
slug?: string;
project?: {
visibility: Visibilities;
slug: string;
Expand Down
Loading

0 comments on commit 772f7db

Please sign in to comment.