Skip to content

Commit

Permalink
Merge branch 'develop' into fix-open-close-folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadrian committed Dec 11, 2023
2 parents 0e5bc52 + 8ea09ea commit c9ee56d
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 52 deletions.
2 changes: 1 addition & 1 deletion frontend/src/js/app/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Content = () => {
>
{displayTooltip ? <Tooltip /> : <ActivateTooltip />}
</Panel>
<ResizeHandle />
<ResizeHandle disabled={!displayTooltip} />
<Panel minSize={350} defaultSize={600}>
<LeftPane />
</Panel>
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/js/common/ResizeHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ const Line = styled("div")`
background-color: ${({ theme }) => theme.col.grayMediumLight};
`;

export const ResizeHandle = ({ style }: { style?: CSSProperties }) => {
export const ResizeHandle = ({
style,
disabled,
}: {
style?: CSSProperties;
disabled?: boolean;
}) => {
return (
<SxPanelResizeHandle style={style}>
<SxPanelResizeHandle style={style} disabled={disabled}>
<Handle>
<Line />
</Handle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ const FormConceptGroup = (props: Props) => {
allowlistedTables: props.allowlistedTables,
blocklistedTables: props.blocklistedTables,
};
const selectConfig = {
allowlistedSelects: props.allowlistedSelects,
blocklistedSelects: props.blocklistedSelects,
};

// indicator if it should be scrolled down back to the dropZone
const [scrollToDropzone, setScrollToDropzone] = useState<boolean>(false);
Expand Down Expand Up @@ -163,6 +167,7 @@ const FormConceptGroup = (props: Props) => {
onChange: props.onChange,
defaults,
tableConfig,
selectConfig,
isValidConcept: props.isValidConcept,
});

Expand Down Expand Up @@ -216,7 +221,7 @@ const FormConceptGroup = (props: Props) => {

const concept = isMovedObject(item)
? copyConcept(item)
: initializeConcept(item, defaults, tableConfig);
: initializeConcept(item, defaults, tableConfig, selectConfig);

let insertIndex = i;
let newPropsValue = props.value;
Expand Down Expand Up @@ -301,7 +306,7 @@ const FormConceptGroup = (props: Props) => {

const concept = isMovedObject(item)
? copyConcept(item)
: initializeConcept(item, defaults, tableConfig);
: initializeConcept(item, defaults, tableConfig, selectConfig);
return props.onChange(
addConcept(
addValue(props.value, newValue),
Expand Down Expand Up @@ -435,7 +440,12 @@ const FormConceptGroup = (props: Props) => {
props.value,
i,
j,
initializeConcept(item, defaults, tableConfig),
initializeConcept(
item,
defaults,
tableConfig,
selectConfig,
),
),
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { TreesT } from "../../concept-trees/reducer";
import { mergeFilterOptions } from "../../model/filter";
import { NodeResetConfig } from "../../model/node";
import { resetSelects } from "../../model/select";
import { SelectConfig, resetSelects } from "../../model/select";
import { resetTables, tableWithDefaults } from "../../model/table";
import { filterSuggestionToSelectOption } from "../../query-node-editor/suggestionsHelper";
import type {
Expand Down Expand Up @@ -278,6 +278,7 @@ export const addConceptsFromFile = (
resolvedConcepts: string[],

tableConfig: TableConfig,
selectConfig: SelectConfig,
defaults: ConceptListDefaultsType,
isValidConcept: ((item: FormConceptNodeT) => boolean) | undefined,

Expand All @@ -301,7 +302,12 @@ export const addConceptsFromFile = (

if (!queryElement) return value;

const concept = initializeConcept(queryElement, defaults, tableConfig);
const concept = initializeConcept(
queryElement,
defaults,
tableConfig,
selectConfig,
);

if (!concept || (!!isValidConcept && !isValidConcept(concept))) return value;

Expand All @@ -325,6 +331,7 @@ export const initializeConcept = (
item: FormConceptNodeT,
defaults: ConceptListDefaultsType,
tableConfig: TableConfig,
selectConfig: SelectConfig,
) => {
if (!item) return item;

Expand All @@ -336,8 +343,8 @@ export const initializeConcept = (
...item,
excludeFromSecondaryId: false,
excludeTimestamps: false,
tables: resetTables(item.tables, { useDefaults: true }),
selects: resetSelects(item.selects, { useDefaults: true }),
tables: resetTables(item.tables, { useDefaults: true, selectConfig }),
selects: resetSelects(item.selects, { useDefaults: true, selectConfig }),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "../../upload-concept-list-modal/actions";
import type { ConceptListDefaults as ConceptListDefaultsType } from "../config-types";

import { SelectConfig } from "../../model/select";
import {
addConceptsFromFile,
FormConceptGroupT,
Expand All @@ -30,13 +31,15 @@ export const useUploadConceptListModal = ({
newValue,
defaults,
tableConfig,
selectConfig,
isValidConcept,
}: {
value: FormConceptGroupT[];
onChange: (value: FormConceptGroupT[]) => void;
newValue: FormConceptGroupT;
defaults: ConceptListDefaultsType;
tableConfig: TableConfig;
selectConfig: SelectConfig;
isValidConcept?: (concept: DragItemConceptTreeNode) => boolean;
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -108,6 +111,7 @@ export const useUploadConceptListModal = ({
resolvedConcepts,

tableConfig,
selectConfig,
defaults,
isValidConcept,

Expand Down
10 changes: 9 additions & 1 deletion frontend/src/js/external-forms/form-configs/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { exists } from "../../common/helpers/exists";
import type { ProjectItemsFilterStateT } from "../../previous-queries/filter/reducer";
import { FormConfigT } from "../../previous-queries/list/reducer";

const configHasOwner = (config: FormConfigT, searchTerm: string) => {
return (
!!config.ownerName &&
config.ownerName.toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1
);
};

const configHasTag = (config: FormConfigT, searchTerm: string) => {
return (
!!config.tags &&
Expand Down Expand Up @@ -58,7 +65,8 @@ export const configMatchesSearch = (
!exists(searchTerm) ||
configHasId(config, searchTerm) ||
configHasLabel(config, searchTerm) ||
configHasTag(config, searchTerm);
configHasTag(config, searchTerm) ||
configHasOwner(config, searchTerm);

export const selectFormConfigs = (
formConfigs: FormConfigT[],
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/js/model/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
} from "../standard-query-editor/types";
import { PossibleDroppableObject } from "../ui-components/Dropzone";

import { objectHasNonDefaultSelects } from "./select";
import { SelectConfig, objectHasNonDefaultSelects } from "./select";
import {
tablesHaveEmptySettings,
tablesHaveFilterValues,
Expand All @@ -28,6 +28,7 @@ import {

export interface NodeResetConfig {
useDefaults?: boolean;
selectConfig?: SelectConfig;
}

export const nodeIsConceptQueryNode = (
Expand Down
34 changes: 20 additions & 14 deletions frontend/src/js/model/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ export function sortSelects(selects: SelectorT[]) {
.sort((a, b) => (a.label < b.label ? -1 : 1));
}

const resetSelected = (select: SelectorT, config: NodeResetConfig) => ({
...select,
selected: config.useDefaults ? !!select.default : false,
});

export const resetSelects = (
selects: SelectorT[],
config: NodeResetConfig = {},
): SelectedSelectorT[] =>
selects.map((select) => resetSelected(select, config));

function selectTypesMatch(
resultType1: SelectorResultType,
resultType2: SelectorResultType,
Expand All @@ -63,20 +52,37 @@ export function selectIsWithinTypes(
);
}

interface AllowBlocklistedSelects {
export interface SelectConfig {
blocklistedSelects?: SelectorResultType[];
allowlistedSelects?: SelectorResultType[];
}

export const isSelectDisabled = (
select: SelectorT,
{ blocklistedSelects, allowlistedSelects }: AllowBlocklistedSelects,
{ blocklistedSelects, allowlistedSelects }: SelectConfig,
) =>
(!!allowlistedSelects && !selectIsWithinTypes(select, allowlistedSelects)) ||
(!!blocklistedSelects && selectIsWithinTypes(select, blocklistedSelects));

export const isValidSelect =
({ blocklistedSelects, allowlistedSelects }: AllowBlocklistedSelects) =>
({ blocklistedSelects, allowlistedSelects }: SelectConfig) =>
(select: SelectedSelectorT) =>
!!select.selected &&
!isSelectDisabled(select, { blocklistedSelects, allowlistedSelects });

const resetSelected = (select: SelectorT, config: NodeResetConfig) => {
if (config.selectConfig && !isValidSelect(config.selectConfig)(select)) {
return { ...select, selected: false };
}

return {
...select,
selected: config.useDefaults ? !!select.default : false,
};
};

export const resetSelects = (
selects: SelectorT[],
config: NodeResetConfig = {},
): SelectedSelectorT[] =>
selects.map((select) => resetSelected(select, config));
17 changes: 16 additions & 1 deletion frontend/src/js/previous-queries/list/ProjectItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import FormSymbol from "../../symbols/FormSymbol";
import QuerySymbol from "../../symbols/QuerySymbol";
import WithTooltip from "../../tooltip/WithTooltip";

import Highlighter from "react-highlight-words";
import { DeleteProjectItemButton } from "./DeleteProjectItemButton";
import ProjectItemLabel from "./ProjectItemLabel";
import { useUpdateFormConfig, useUpdateQuery } from "./actions";
Expand Down Expand Up @@ -159,6 +160,9 @@ const ProjectItem = forwardRef<
ref,
) {
const { t } = useTranslation();
const highlightedWords = useSelector<StateT, string[]>(
(state) => state.projectItemsSearch.words,
);

const loadedSecondaryIds = useSelector<StateT, SecondaryId[]>(
(state) => state.conceptTrees.secondaryIds,
Expand Down Expand Up @@ -291,10 +295,21 @@ const ProjectItem = forwardRef<
label={label}
selectTextOnMount={true}
onSubmit={onRenameLabel}
highlightedWords={highlightedWords}
isEditing={isEditingLabel}
setIsEditing={setIsEditingLabel}
/>
<OwnerName>{item.ownerName}</OwnerName>
<OwnerName>
{highlightedWords.length > 0 ? (
<Highlighter
searchWords={highlightedWords}
autoEscape
textToHighlight={item.ownerName}
/>
) : (
item.ownerName
)}
</OwnerName>
</LabelRow>
</Content>
</Root>
Expand Down
32 changes: 11 additions & 21 deletions frontend/src/js/previous-queries/list/ProjectItemLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import styled from "@emotion/styled";
import { FC } from "react";
import Highlighter from "react-highlight-words";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";

import type { StateT } from "../../app/reducers";
import EditableText from "../../ui-components/EditableText";

const Text = styled("div")`
Expand All @@ -21,32 +18,25 @@ const SxEditableText = styled(EditableText)`
text-overflow: ellipsis;
`;

const useHighlightedWords = () => {
return useSelector<StateT, string[]>(
(state) => state.projectItemsSearch.words,
);
};

interface PropsT {
mayEdit?: boolean;
label: string;
selectTextOnMount: boolean;
loading?: boolean;
onSubmit: (text: string) => void;
isEditing: boolean;
setIsEditing: (value: boolean) => void;
}

const ProjectItemLabel: FC<PropsT> = ({
const ProjectItemLabel = ({
mayEdit,
loading,
selectTextOnMount,
label,
highlightedWords,
onSubmit,
isEditing,
setIsEditing,
}: {
mayEdit?: boolean;
label: string;
highlightedWords: string[];
selectTextOnMount: boolean;
loading?: boolean;
onSubmit: (text: string) => void;
isEditing: boolean;
setIsEditing: (value: boolean) => void;
}) => {
const highlightedWords = useHighlightedWords();
const { t } = useTranslation();

return mayEdit ? (
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/js/previous-queries/list/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import type { ProjectItemsFilterStateT } from "../filter/reducer";

import type { FormConfigT, PreviousQueryT } from "./reducer";

const queryHasOwner = (query: PreviousQueryT, searchTerm: string) => {
return (
!!query.ownerName &&
query.ownerName.toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1
);
};

const queryHasTag = (query: PreviousQueryT, searchTerm: string) => {
return (
!!query.tags &&
Expand Down Expand Up @@ -66,7 +73,8 @@ export const queryMatchesSearch = (
!exists(searchTerm) ||
queryHasId(query, searchTerm) ||
queryHasLabel(query, searchTerm) ||
queryHasTag(query, searchTerm)
queryHasTag(query, searchTerm) ||
queryHasOwner(query, searchTerm)
);
};

Expand Down
Loading

0 comments on commit c9ee56d

Please sign in to comment.