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

add action to create dataset from project page #474

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
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 };
Loading