Skip to content

Commit

Permalink
Merge pull request #474 from EyeSeeTea/feature/create-dataset-from-pr…
Browse files Browse the repository at this point in the history
…ojects

add action to create dataset from project page
  • Loading branch information
MiquelAdell authored Dec 12, 2024
2 parents 82e17c0 + 09033a6 commit 2679969
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/webapp/components/dataset-table/DataSetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { EditOrgUnits } from "$/webapp/components/edit-orgunits/EditOrgUnits";
import { DataSetLogs } from "$/webapp/components/dataset-logs/DataSetLogs";
import { HomeTabs } from "$/webapp/components/home-tabs/HomeTabs";
import { Maybe } from "$/utils/ts-utils";
import { useDeleteDataSets } from "$/webapp/hooks/useDataSets";
import { useDataSetsRoutes, useDeleteDataSets } from "$/webapp/hooks/useDataSets";
import { useTableConfig } from "$/webapp/components/dataset-table/DataSetTableConfig";
import { useNavigateTo } from "$/webapp/routes";
import { DataSetDetails } from "$/webapp/components/dataset-table/DataSetDetails";

export type DataSetColumns = DataSetAttrs & { permissionDescription: string };
Expand All @@ -33,11 +32,11 @@ export const DataSetTable: React.FC = React.memo(() => {
const [refreshTable, setRefreshTable] = React.useState(0);
const [tableAction, setTableAction] = React.useState<TableAction>();

const navigateTo = useNavigateTo();
const snackbar = useSnackbar();
const action = getSelectedAction(tableAction);
const selectedIds = getSelectedIds(tableAction);
const tableConfig = useTableConfig({ onAction: setTableAction, refreshTable });
const { goToCreateDataSet } = useDataSetsRoutes();

const clearTableAction = React.useCallback((refreshTable?: boolean) => {
setTableAction(undefined);
Expand All @@ -63,10 +62,6 @@ export const DataSetTable: React.FC = React.memo(() => {
setTableAction(undefined);
}, []);

const goToCreateDataSet = React.useCallback(() => {
navigateTo("createDataSets");
}, [navigateTo]);

const renderActions = () => {
switch (action) {
case "remove":
Expand Down
5 changes: 4 additions & 1 deletion src/webapp/components/projects/ProjectTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import i18n from "$/utils/i18n";
import { TooltipTruncate } from "$/webapp/components/tooltip-truncate/TooltipTruncate";
import { useAppContext } from "$/webapp/contexts/app-context";
import { parseSortField } from "$/utils/parse-sort-field";
import { useDataSetsRoutes } from "$/webapp/hooks/useDataSets";

type ProjectColumns = ProjectAttrs & { orgUnits: string; coreCompetencies: string };

Expand All @@ -24,6 +25,7 @@ export const ProjectTable = React.memo(() => {
const { compositionRoot } = useAppContext();
const loading = useLoading();
const snackbar = useSnackbar();
const { goToCreateDataSet } = useDataSetsRoutes();

const tableConfig = useObjectsTable<ProjectColumns>(
React.useMemo(() => {
Expand Down Expand Up @@ -90,8 +92,9 @@ export const ProjectTable = React.memo(() => {
paginationOptions: { pageSizeInitialValue: 50, pageSizeOptions: [50, 100, 200] },
searchBoxLabel: i18n.t("Search"),
childrenKeys: ["dataSets"],
onActionButtonClick: goToCreateDataSet,
};
}, []),
}, [goToCreateDataSet]),
React.useCallback(
(search, pagination, sorting) => {
loading.show(true, i18n.t("Loading projects..."));
Expand Down
11 changes: 11 additions & 0 deletions src/webapp/hooks/useDataSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DataSet } from "$/domain/entities/DataSet";
import { Id } from "$/domain/entities/Ref";
import i18n from "$/utils/i18n";
import { useAppContext } from "$/webapp/contexts/app-context";
import { useNavigateTo } from "$/webapp/routes";

export function useGetDataSetsByIds(ids: Id[]) {
const { compositionRoot } = useAppContext();
Expand Down Expand Up @@ -89,4 +90,14 @@ export function useDeleteDataSets(props: DeleteDataSetsProps) {
return { deleteDataSets };
}

export function useDataSetsRoutes() {
const navigateTo = useNavigateTo();

const goToCreateDataSet = React.useCallback(() => {
navigateTo("createDataSets");
}, [navigateTo]);

return { goToCreateDataSet };
}

type DeleteDataSetsProps = { ids: Id[]; onError: (message: string) => void; onSuccess: () => void };

0 comments on commit 2679969

Please sign in to comment.