mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-08-14 04:40:36 +03:00
F: Improve cst filters
This commit is contained in:
parent
7eb7fb09cf
commit
a31558a403
|
@ -1,30 +1,31 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { MiniButton } from '@/components/control';
|
import { MiniButton } from '@/components/control';
|
||||||
import { IconChild } from '@/components/icons';
|
import { IconChild, IconCrucial } from '@/components/icons';
|
||||||
import { SearchBar } from '@/components/input';
|
import { SearchBar } from '@/components/input';
|
||||||
|
import { tripleToggleColor } from '@/utils/utils';
|
||||||
|
|
||||||
import { type IRSForm } from '../../models/rsform';
|
|
||||||
import { useCstSearchStore } from '../../stores/cst-search';
|
import { useCstSearchStore } from '../../stores/cst-search';
|
||||||
|
|
||||||
import { SelectGraphFilter } from './select-graph-filter';
|
import { SelectGraphFilter } from './select-graph-filter';
|
||||||
import { SelectMatchMode } from './select-match-mode';
|
import { SelectMatchMode } from './select-match-mode';
|
||||||
|
|
||||||
interface ConstituentsSearchProps {
|
interface ConstituentsSearchProps {
|
||||||
schema: IRSForm;
|
|
||||||
dense?: boolean;
|
dense?: boolean;
|
||||||
hideGraphFilter?: boolean;
|
hideGraphFilter?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ConstituentsSearch({ schema, dense, hideGraphFilter }: ConstituentsSearchProps) {
|
export function ConstituentsSearch({ dense, hideGraphFilter }: ConstituentsSearchProps) {
|
||||||
const query = useCstSearchStore(state => state.query);
|
const query = useCstSearchStore(state => state.query);
|
||||||
const filterMatch = useCstSearchStore(state => state.match);
|
const filterMatch = useCstSearchStore(state => state.match);
|
||||||
const filterSource = useCstSearchStore(state => state.source);
|
const filterSource = useCstSearchStore(state => state.source);
|
||||||
const includeInherited = useCstSearchStore(state => state.includeInherited);
|
const showInherited = useCstSearchStore(state => state.isInherited);
|
||||||
|
const showCrucial = useCstSearchStore(state => state.isCrucial);
|
||||||
const setQuery = useCstSearchStore(state => state.setQuery);
|
const setQuery = useCstSearchStore(state => state.setQuery);
|
||||||
const setMatch = useCstSearchStore(state => state.setMatch);
|
const setMatch = useCstSearchStore(state => state.setMatch);
|
||||||
const setSource = useCstSearchStore(state => state.setSource);
|
const setSource = useCstSearchStore(state => state.setSource);
|
||||||
const toggleInherited = useCstSearchStore(state => state.toggleInherited);
|
const toggleInherited = useCstSearchStore(state => state.toggleInherited);
|
||||||
|
const toggleCrucial = useCstSearchStore(state => state.toggleCrucial);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex border-b bg-input rounded-t-md'>
|
<div className='flex border-b bg-input rounded-t-md'>
|
||||||
|
@ -37,15 +38,19 @@ export function ConstituentsSearch({ schema, dense, hideGraphFilter }: Constitue
|
||||||
/>
|
/>
|
||||||
<SelectMatchMode value={filterMatch} onChange={setMatch} dense={dense} />
|
<SelectMatchMode value={filterMatch} onChange={setMatch} dense={dense} />
|
||||||
{!hideGraphFilter ? <SelectGraphFilter value={filterSource} onChange={setSource} dense={dense} /> : null}
|
{!hideGraphFilter ? <SelectGraphFilter value={filterSource} onChange={setSource} dense={dense} /> : null}
|
||||||
{schema.stats.count_inherited > 0 ? (
|
|
||||||
<MiniButton
|
<MiniButton
|
||||||
titleHtml={`Наследованные: <b>${includeInherited ? 'отображать' : 'скрывать'}</b>`}
|
title='Отображение наследников'
|
||||||
aria-label={`Отображение наследованных: ${includeInherited ? 'отображать' : 'скрывать'}`}
|
icon={<IconChild size='1rem' className={tripleToggleColor(showInherited)} />}
|
||||||
icon={<IconChild size='1rem' className={includeInherited ? 'icon-primary' : undefined} />}
|
className='h-fit self-center'
|
||||||
className='h-fit self-center'
|
onClick={toggleInherited}
|
||||||
onClick={toggleInherited}
|
/>
|
||||||
/>
|
<MiniButton
|
||||||
) : null}
|
title='Отображение ключевых'
|
||||||
|
icon={<IconCrucial size='1rem' className={tripleToggleColor(showCrucial)} />}
|
||||||
|
className='h-fit self-center'
|
||||||
|
onClick={toggleCrucial}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,13 @@ export function useFilteredItems(schema: IRSForm, activeCst?: IConstituenta | nu
|
||||||
const query = useCstSearchStore(state => state.query);
|
const query = useCstSearchStore(state => state.query);
|
||||||
const filterMatch = useCstSearchStore(state => state.match);
|
const filterMatch = useCstSearchStore(state => state.match);
|
||||||
const filterSource = useCstSearchStore(state => state.source);
|
const filterSource = useCstSearchStore(state => state.source);
|
||||||
const includeInherited = useCstSearchStore(state => state.includeInherited);
|
const showInherited = useCstSearchStore(state => state.isInherited);
|
||||||
|
const showCrucial = useCstSearchStore(state => state.isCrucial);
|
||||||
|
|
||||||
const graphFiltered = activeCst ? applyGraphQuery(schema, activeCst.id, filterSource) : schema.items;
|
const graphFiltered = activeCst ? applyGraphQuery(schema, activeCst.id, filterSource) : schema.items;
|
||||||
const queryFiltered = query ? graphFiltered.filter(cst => matchConstituenta(cst, query, filterMatch)) : graphFiltered;
|
const queryFiltered = query ? graphFiltered.filter(cst => matchConstituenta(cst, query, filterMatch)) : graphFiltered;
|
||||||
const items = !includeInherited ? queryFiltered.filter(cst => !cst.is_inherited) : queryFiltered;
|
let items = showInherited !== null ? queryFiltered.filter(cst => cst.is_inherited === showInherited) : queryFiltered;
|
||||||
|
items = showCrucial !== null ? items.filter(cst => cst.crucial === showCrucial) : items;
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { persist } from 'zustand/middleware';
|
import { persist } from 'zustand/middleware';
|
||||||
|
|
||||||
|
import { toggleTristateFlag } from '@/utils/utils';
|
||||||
|
|
||||||
/** Represents graph dependency mode. */
|
/** Represents graph dependency mode. */
|
||||||
export const DependencyMode = {
|
export const DependencyMode = {
|
||||||
ALL: 0,
|
ALL: 0,
|
||||||
|
@ -31,8 +33,11 @@ interface CstSearchStore {
|
||||||
source: DependencyMode;
|
source: DependencyMode;
|
||||||
setSource: (value: DependencyMode) => void;
|
setSource: (value: DependencyMode) => void;
|
||||||
|
|
||||||
includeInherited: boolean;
|
isInherited: boolean | null;
|
||||||
toggleInherited: () => void;
|
toggleInherited: () => void;
|
||||||
|
|
||||||
|
isCrucial: boolean | null;
|
||||||
|
toggleCrucial: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useCstSearchStore = create<CstSearchStore>()(
|
export const useCstSearchStore = create<CstSearchStore>()(
|
||||||
|
@ -44,15 +49,18 @@ export const useCstSearchStore = create<CstSearchStore>()(
|
||||||
setMatch: value => set({ match: value }),
|
setMatch: value => set({ match: value }),
|
||||||
source: DependencyMode.ALL,
|
source: DependencyMode.ALL,
|
||||||
setSource: value => set({ source: value }),
|
setSource: value => set({ source: value }),
|
||||||
includeInherited: true,
|
isInherited: null,
|
||||||
toggleInherited: () => set(state => ({ includeInherited: !state.includeInherited }))
|
toggleInherited: () => set(state => ({ isInherited: toggleTristateFlag(state.isInherited) })),
|
||||||
|
isCrucial: null,
|
||||||
|
toggleCrucial: () => set(state => ({ isCrucial: toggleTristateFlag(state.isCrucial) }))
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
version: 1,
|
version: 1,
|
||||||
partialize: state => ({
|
partialize: state => ({
|
||||||
match: state.match,
|
match: state.match,
|
||||||
source: state.source,
|
source: state.source,
|
||||||
includeInherited: state.includeInherited
|
isInherited: state.isInherited,
|
||||||
|
isCrucial: state.isCrucial
|
||||||
}),
|
}),
|
||||||
name: 'portal.constituenta.search'
|
name: 'portal.constituenta.search'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user