Skip to content

Commit

Permalink
- tree by ownership
Browse files Browse the repository at this point in the history
- get_rank with scenario config id
- hide empty branch on search
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Nov 29, 2024
1 parent 4d43793 commit f2c12f2
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 105 deletions.
12 changes: 10 additions & 2 deletions frontend/taipy-gui/packaging/taipy-gui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,20 @@ export interface TableProps extends TaipyPaginatedTableProps {
}
export declare const Table: (props: TableProps) => JSX.Element;

export interface FilterColumnDesc extends ColumnDesc {
params?: number[];
}
export interface FilterDesc {
col: string;
action: string;
value: string | number | boolean | Date;
type: string;
params?: number[];
}
export interface TableFilterProps {
fieldHeader?: string;
fieldHeaderTooltip?: string;
columns: Record<string, ColumnDesc>;
columns: Record<string, FilterColumnDesc>;
colsOrder?: Array<string>;
onValidate: (data: Array<FilterDesc>) => void;
appliedFilters?: Array<FilterDesc>;
Expand All @@ -144,15 +148,19 @@ export interface TableFilterProps {
}
export declare const TableFilter: (props: TableFilterProps) => JSX.Element;

export interface SortColumnDesc extends ColumnDesc {
params?: number[];
}
export interface SortDesc {
col: string;
order: boolean;
params?: number[];
}

export interface TableSortProps {
fieldHeader?: string;
fieldHeaderTooltip?: string;
columns: Record<string, ColumnDesc>;
columns: Record<string, SortColumnDesc>;
colsOrder?: Array<string>;
onValidate: (data: Array<SortDesc>) => void;
appliedSorts?: Array<SortDesc>;
Expand Down
27 changes: 18 additions & 9 deletions frontend/taipy-gui/src/components/Taipy/TableFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ import { getDateTime, getTypeFromDf } from "../../utils";
import { getSuffixedClassNames } from "./utils";
import { MatchCase } from "../icons/MatchCase";

export interface FilterColumnDesc extends ColumnDesc {
params?: number[];
}

interface TableFilterProps {
fieldHeader?: string;
fieldHeaderTooltip?: string;
columns: Record<string, ColumnDesc>;
columns: Record<string, FilterColumnDesc>;
colsOrder?: Array<string>;
onValidate: (data: Array<FilterDesc>) => void;
appliedFilters?: Array<FilterDesc>;
Expand All @@ -51,7 +55,7 @@ interface FilterRowProps {
fieldHeader?: string;
fieldHeaderTooltip?: string;
filter?: FilterDesc;
columns: Record<string, ColumnDesc>;
columns: Record<string, FilterColumnDesc>;
colsOrder: Array<string>;
setFilter: (idx: number, fd: FilterDesc, remove?: boolean) => void;
}
Expand Down Expand Up @@ -98,7 +102,7 @@ const getActionsByType = (colType?: string) =>
(colType === "any" ? { ...actionsByType.string, ...actionsByType.number } : actionsByType.string);

const getFilterDesc = (
columns: Record<string, ColumnDesc>,
columns: Record<string, FilterColumnDesc>,
colId?: string,
act?: string,
val?: string,
Expand All @@ -118,13 +122,14 @@ const getFilterDesc = (
? colType === "number"
? parseFloat(val)
: colType === "boolean"
? val === "1"
: colType === "date"
? getDateTime(val)
: val
? val === "1"
: colType === "date"
? getDateTime(val)
: val
: val,
type: colType,
matchCase: !!matchCase,
params: columns[colId].params,
} as FilterDesc;
} catch (e) {
console.info("Could not parse value ", val, e);
Expand Down Expand Up @@ -231,7 +236,11 @@ const FilterRow = (props: FilterRowProps) => {
<FormControl margin="dense">
<InputLabel>{fieldHeader}</InputLabel>
<Tooltip title={fieldHeaderTooltip} placement="top">
<Select value={colId || ""} onChange={onColSelect} input={<OutlinedInput label={fieldHeader} />}>
<Select
value={colId || ""}
onChange={onColSelect}
input={<OutlinedInput label={fieldHeader} />}
>
{colsOrder.map((col) =>
columns[col].filter ? (
<MenuItem key={col} value={col}>
Expand Down Expand Up @@ -352,7 +361,7 @@ const TableFilter = (props: TableFilterProps) => {
onValidate,
appliedFilters,
className = "",
filteredCount
filteredCount,
} = props;

const [showFilter, setShowFilter] = useState(false);
Expand Down
24 changes: 17 additions & 7 deletions frontend/taipy-gui/src/components/Taipy/TableSort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ import { getSuffixedClassNames } from "./utils";
export interface SortDesc {
col: string;
order: boolean;
params?: number[];
}

export interface SortColumnDesc extends ColumnDesc {
params?: number[];
}

interface TableSortProps {
fieldHeader?: string;
fieldHeaderTooltip?: string;
columns: Record<string, ColumnDesc>;
columns: Record<string, SortColumnDesc>;
colsOrder?: Array<string>;
onValidate: (data: Array<SortDesc>) => void;
appliedSorts?: Array<SortDesc>;
Expand Down Expand Up @@ -73,12 +78,13 @@ const badgeSx = {
};
const orderCaptionSx = { ml: 1 };

const getSortDesc = (columns: Record<string, ColumnDesc>, colId?: string, asc?: boolean) =>
const getSortDesc = (columns: Record<string, SortColumnDesc>, colId?: string, asc?: boolean) =>
colId && asc !== undefined
? ({
col: columns[colId].dfid,
order: !!asc,
} as SortDesc)
col: columns[colId].dfid,
order: !!asc,
params: columns[colId].params,
} as SortDesc)
: undefined;

const SortRow = (props: SortRowProps) => {
Expand Down Expand Up @@ -138,7 +144,11 @@ const SortRow = (props: SortRowProps) => {
<FormControl margin="dense">
<InputLabel>Column</InputLabel>
<Tooltip title={fieldHeaderTooltip} placement="top">
<Select value={colId || ""} onChange={onColSelect} input={<OutlinedInput label={fieldHeader} />}>
<Select
value={colId || ""}
onChange={onColSelect}
input={<OutlinedInput label={fieldHeader} />}
>
{cols.map((col) => (
<MenuItem key={col} value={col}>
{columns[col].title || columns[col].dfid}
Expand Down Expand Up @@ -183,7 +193,7 @@ const TableSort = (props: TableSortProps) => {
columns,
onValidate,
appliedSorts,
className = ""
className = "",
} = props;

const [showSort, setShowSort] = useState(false);
Expand Down
1 change: 1 addition & 0 deletions frontend/taipy-gui/src/components/Taipy/tableUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface FilterDesc {
value: string | number | boolean | Date;
type: string;
matchcase?: boolean;
params?: number[];
}

export const defaultColumns = {} as Record<string, ColumnDesc>;
Expand Down
8 changes: 5 additions & 3 deletions frontend/taipy-gui/src/extensions/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import FileSelector from "../components/Taipy/FileSelector";
import Login from "../components/Taipy/Login";
import Router from "../components/Router";
import Table from "../components/Taipy/Table";
import TableFilter from "../components/Taipy/TableFilter";
import TableFilter, { FilterColumnDesc } from "../components/Taipy/TableFilter";
import { FilterDesc } from "../components/Taipy/tableUtils";
import TableSort, { SortDesc } from "../components/Taipy/TableSort";
import {getComponentClassName} from "../components/Taipy/TaipyStyle";
import TableSort, { SortColumnDesc, SortDesc } from "../components/Taipy/TableSort";
import { getComponentClassName } from "../components/Taipy/TaipyStyle";
import Metric from "../components/Taipy/Metric";
import { useLovListMemo, LoV, LoVElt } from "../components/Taipy/lovUtils";
import { LovItem } from "../utils/lov";
Expand Down Expand Up @@ -72,12 +72,14 @@ export {

export type {
ColumnDesc,
FilterColumnDesc,
FilterDesc,
LoV,
LoVElt,
LovItem,
RowType,
RowValue,
SortColumnDesc,
SortDesc,
TaipyStore as Store,
TaipyState as State,
Expand Down
94 changes: 50 additions & 44 deletions frontend/taipy/src/CoreSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,41 @@ import { SimpleTreeView } from "@mui/x-tree-view/SimpleTreeView";
import { TreeItem } from "@mui/x-tree-view/TreeItem";

import {
useDispatch,
useModule,
getUpdateVar,
createRequestUpdateAction,
createSendUpdateAction,
getSuffixedClassNames,
getUpdateVar,
useClassNames,
useDispatch,
useDispatchRequestUpdateOnFirstRender,
createRequestUpdateAction,
useModule,
useDynamicProperty,
ColumnDesc,
FilterColumnDesc,
FilterDesc,
TableFilter,
SortColumnDesc,
SortDesc,
TableFilter,
TableSort,
useClassNames,
getSuffixedClassNames,
} from "taipy-gui";

import { Cycles, Cycle, DataNodes, NodeType, Scenarios, Scenario, DataNode, Sequence, Sequences } from "./utils/types";
import { Cycle, Cycles, DataNode, DataNodes, NodeType, Scenario, Scenarios, Sequence, Sequences } from "./utils/types";
import {
Cycle as CycleIcon,
Datanode as DatanodeIcon,
Sequence as SequenceIcon,
Scenario as ScenarioIcon,
Sequence as SequenceIcon,
} from "./icons";
import {
getUpdateVarNames,
iconLabelSx,
tinyIconButtonSx,
tinySelPinIconButtonSx,
BadgePos,
BadgeSx,
BaseTreeViewSx,
CoreProps,
FlagSx,
ParentItemSx,
getUpdateVarNames,
iconLabelSx,
tinyIconButtonSx,
tinySelPinIconButtonSx,
} from "./utils";

export interface EditProps {
Expand Down Expand Up @@ -282,7 +283,7 @@ const filterTree = (entities: Entities, search: string, leafType: NodeType, coun
count.nb++;
return emptyEntity;
})
.filter((i) => (i as unknown[]).length !== 0);
.filter((item) => (item as unknown[]).length > 3 && (item[3] == leafType || !item[2] || item[2].length > 0));
if (top && count.nb == 0) {
return entities;
}
Expand Down Expand Up @@ -502,21 +503,22 @@ const CoreSelector = (props: CoreSelectorProps) => {
const colFilters = useMemo(() => {
try {
const res = props.filter
? (JSON.parse(props.filter) as Array<[string, string, string, string[]]>)
? (JSON.parse(props.filter) as Array<[string, string, string, string[], number[]]>)
: undefined;
return Array.isArray(res)
? res.reduce((pv, [name, id, coltype, lov], idx) => {
? res.reduce((pv, [name, id, colType, lov, params], idx) => {
pv[name] = {
dfid: id,
title: name,
type: coltype,
type: colType,
index: idx,
filter: true,
lov: lov,
lov,
freeLov: !!lov,
params
};
return pv;
}, {} as Record<string, ColumnDesc>)
}, {} as Record<string, FilterColumnDesc>)
: undefined;
} catch {
return undefined;
Expand All @@ -531,18 +533,20 @@ const CoreSelector = (props: CoreSelectorProps) => {
if (old.length != filters.length || JSON.stringify(old) != jsonFilters) {
localStoreSet(jsonFilters, id, lovPropertyName, "filter");
const filterVar = getUpdateVar(updateCoreVars, "filter");
const lovVar = getUpdateVarNames(updateVars, lovPropertyName);
Promise.resolve().then(() =>
dispatch(
createRequestUpdateAction(
id,
module,
lovVar,
true,
filterVar ? { [filterVar]: filters } : undefined
if (filterVar) {
const lovVar = getUpdateVarNames(updateVars, lovPropertyName);
Promise.resolve().then(() =>
dispatch(
createRequestUpdateAction(
id,
module,
lovVar,
true,
{ [filterVar]: filters }
)
)
)
);
);
}
return filters;
}
return old;
Expand All @@ -554,12 +558,12 @@ const CoreSelector = (props: CoreSelectorProps) => {
// sort
const colSorts = useMemo(() => {
try {
const res = props.sort ? (JSON.parse(props.sort) as Array<[string, string]>) : undefined;
const res = props.sort ? (JSON.parse(props.sort) as Array<[string, string, number[]]>) : undefined;
return Array.isArray(res)
? res.reduce((pv, [name, id], idx) => {
pv[name] = { dfid: id, title: name, type: "str", index: idx };
? res.reduce((pv, [name, id, params], idx) => {
pv[name] = { dfid: id, title: name, type: "str", index: idx, params };
return pv;
}, {} as Record<string, ColumnDesc>)
}, {} as Record<string, SortColumnDesc>)
: undefined;
} catch {
return undefined;
Expand All @@ -574,15 +578,17 @@ const CoreSelector = (props: CoreSelectorProps) => {
if (old.length != sorts.length || JSON.stringify(old) != jsonSorts) {
localStoreSet(jsonSorts, id, lovPropertyName, "sort");
const sortVar = getUpdateVar(updateCoreVars, "sort");
dispatch(
createRequestUpdateAction(
id,
module,
getUpdateVarNames(updateVars, lovPropertyName),
true,
sortVar ? { [sortVar]: sorts } : undefined
)
);
if (sortVar) {
dispatch(
createRequestUpdateAction(
id,
module,
getUpdateVarNames(updateVars, lovPropertyName),
true,
{ [sortVar]: sorts }
)
);
}
return sorts;
}
return old;
Expand Down
Loading

0 comments on commit f2c12f2

Please sign in to comment.