Skip to content

Commit

Permalink
ISSUE #5257 - move type declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Amantini1997 committed Nov 28, 2024
1 parent 1ae57ce commit 28fa7a6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions frontend/src/v5/store/tickets/card/ticketsCard.redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createActions, createReducer } from 'reduxsauce';
import { Constants } from '@/v5/helpers/actions.helper';
import { EditableTicket, OverridesDicts, FilterPropertiesByModule } from '../tickets.types';
import { TeamspaceProjectAndModel } from '../../store.types';
import { TicketCardFilter, TicketFilterDescription } from '@components/viewer/cards/cardFilters/cardFilters.types';
import { TicketCardFilter, TicketCardFilterDescription } from '@components/viewer/cards/cardFilters/cardFilters.types';
import { get, isEmpty, set, unset } from 'lodash';

export const { Types: TicketsCardTypes, Creators: TicketsCardActions } = createActions({
Expand Down Expand Up @@ -166,7 +166,7 @@ export type SetSelectedTemplateAction = Action<'SET_SELECTED_TEMPLATE'> & { temp
export type SetSelectedTicketPinAction = Action<'SET_SELECTED_TICKET_PIN'> & { pinId: string };
export type SetPinToDropAction = Action<'SET_PIN_TO_DROP'> & { pinToDrop: string };
export type UpsertFilterAction = Action<'UPSERT_FILTER'> & { filter: TicketCardFilter };
export type DeleteFilterAction = Action<'DELETE_FILTER'> & { filter: TicketFilterDescription };
export type DeleteFilterAction = Action<'DELETE_FILTER'> & { filter: TicketCardFilterDescription };
export type ResetFiltersAction = Action<'RESET_FILTERS'>;
export type FetchTicketsListAction = Action<'FETCH_TICKETS_LIST'> & TeamspaceProjectAndModel & { isFederation: boolean };
export type SetCardViewAction = Action<'SET_CARD_VIEW'> & { view: TicketsCardViews, props?:any };
Expand All @@ -185,7 +185,7 @@ export interface ITicketsCardActionCreators {
setSelectedTicketPin: (pinId: string) => SetSelectedTicketPinAction,
setPinToDrop: (pinToDrop: string) => SetPinToDropAction,
upsertFilter: (filter: TicketCardFilter) => UpsertFilterAction,
deleteFilter: (filter: TicketFilterDescription) => DeleteFilterAction,
deleteFilter: (filter: TicketCardFilterDescription) => DeleteFilterAction,
resetFilters: () => ResetFiltersAction,
fetchTicketsList: (
teamspace: string,
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/v5/store/tickets/tickets.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { RgbArray } from '@/v5/helpers/colors.helper';
import { FilterTypesByProperty } from '@components/viewer/cards/cardFilters/cardFilters.types';
import { BaseFilter, CardFilterType } from '@components/viewer/cards/cardFilters/cardFilters.types';
import { TicketStatusTypes } from '@controls/chip/chip.types';

export type PropertyTypeDefinition = 'text' | 'longText' | 'boolean' | 'number' | 'date' | 'view' | 'manyOf' | 'oneOf' | 'image' | 'imageList' | 'coords' | 'measurements';
Expand Down Expand Up @@ -213,6 +213,11 @@ export type OverridesDicts = {
transparencies: MeshIdTransparencyDict,
};

export type FilterTypesByProperty = {
[property in string]: {
[type in CardFilterType]?: BaseFilter;
};
};
export type FilterPropertiesByModule = {
[module in string]?: FilterTypesByProperty;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ export type CardFilterOperator = 'ex' | 'nex' | 'eq' | 'neq' | 'ss' | 'nss' | 'r
export type CardFilterType = 'text' | 'longText' | 'date' | 'pastDate' | 'sequencing' | 'oneOf' | 'manyOf' | 'boolean' | 'number' | 'ticketTitle' | 'ticketId' | 'template';
export type CardFilterValue = string | number | Date;
export type BaseFilter = { operator: CardFilterOperator, values: CardFilterValue[] };
export type FilterTypesByProperty = {
[property in string]: {
[type in CardFilterType]?: BaseFilter;
};
};

export type CardFilter = {
property: string,
type: CardFilterType,
filter: BaseFilter,
};
export type TicketCardFilter = CardFilter & { module: string };
export type TicketFilterDescription = Omit<TicketCardFilter, 'filter'>;
export type TicketCardFilterDescription = Omit<TicketCardFilter, 'filter'>;
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { TicketFilterDescription } from '@components/viewer/cards/cardFilters/cardFilters.types';
import { TicketCardFilterDescription } from '@components/viewer/cards/cardFilters/cardFilters.types';
import { TYPE_TO_ICON } from '../../ticketFilters.helpers';
import { ExpandIconContainer, FilterIconContainer, MenuItem } from './ticketFiltersSelectionItem.styles';
import ChevronIcon from '@assets/icons/outlined/thin_chevron-outlined.svg';
import { Highlight } from '@controls/highlight';
import { useContext } from 'react';
import { SearchContext } from '@controls/search/searchContext';

type TicketFiltersSelectionItemProps = TicketFilterDescription & {
type TicketFiltersSelectionItemProps = TicketCardFilterDescription & {
onClick: () => void;
};
export const TicketFiltersSelectionItem = ({ module, property, type, onClick }: TicketFiltersSelectionItemProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { useContext } from 'react';
import { TicketFiltersSelectionItem } from './item/ticketFiltersSelectionItem.component';
import { FormattedMessage } from 'react-intl';
import { MenuList, EmptyListMessage } from './ticketFiltersSelectionList.styles';
import { TicketFilterDescription } from '../../../cardFilters.types';
import { TicketCardFilterDescription } from '../../../cardFilters.types';

type TicketFiltersSelectionListProps = {
onFilterClick: (filter) => void;
};
export const TicketFiltersSelectionList = ({ onFilterClick }: TicketFiltersSelectionListProps) => {
const { filteredItems, query } = useContext<SearchContextType<TicketFilterDescription>>(SearchContext);
const { filteredItems, query } = useContext<SearchContextType<TicketCardFilterDescription>>(SearchContext);

if (!filteredItems.length) return (
<EmptyListMessage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/

import { formatMessage } from '@/v5/services/intl';
import { ITemplate, FilterPropertiesByModule } from '@/v5/store/tickets/tickets.types';
import { ITemplate, FilterPropertiesByModule, FilterTypesByProperty } from '@/v5/store/tickets/tickets.types';
import BooleanIcon from '@assets/icons/filters/boolean.svg';
import ListIcon from '@assets/icons/filters/list.svg';
import NumberIcon from '@assets/icons/filters/number.svg';
import TemplateIcon from '@assets/icons/filters/template.svg';
import TextIcon from '@assets/icons/filters/text.svg';
import CalendarIcon from '@assets/icons/outlined/calendar-outlined.svg';
import { sortBy, uniqBy } from 'lodash';
import { CardFilter, CardFilterType, FilterTypesByProperty, BaseFilter, TicketFilterDescription } from '../../cardFilters.types';
import { CardFilter, CardFilterType, BaseFilter, TicketCardFilterDescription } from '../../cardFilters.types';

export const TYPE_TO_ICON: Record<CardFilterType, any> = {
'template': TemplateIcon,
Expand All @@ -43,27 +43,27 @@ export const TYPE_TO_ICON: Record<CardFilterType, any> = {

const VALID_FILTERING_PROPERTY_TYPES = Object.keys(TYPE_TO_ICON);

const DEFAULT_FILTERS: TicketFilterDescription[] = [
const DEFAULT_FILTERS: TicketCardFilterDescription[] = [
{ module: '', type: 'ticketTitle', property: formatMessage({ defaultMessage: 'Ticket title', id: 'viewer.card.filters.element.ticketTitle' }) },
{ module: '', type: 'ticketId', property: formatMessage({ defaultMessage: 'Ticket ID', id: 'viewer.card.filters.element.ticketId' }) },
{ module: '', type: 'template', property: formatMessage({ defaultMessage: 'Ticket template', id: 'viewer.card.filters.element.ticketTemplate' }) },
];

const propertiesToValidFilters = (properties: { name: string, type: string }[], module: string = ''): TicketFilterDescription[] => properties
const propertiesToValidFilters = (properties: { name: string, type: string }[], module: string = ''): TicketCardFilterDescription[] => properties
.filter(({ type }) => VALID_FILTERING_PROPERTY_TYPES.includes(type))
.map(({ name, type }) => ({
module,
property: name,
type,
}) as TicketFilterDescription);
}) as TicketCardFilterDescription);

const templateToFilters = (template: ITemplate): TicketFilterDescription[] => [
const templateToFilters = (template: ITemplate): TicketCardFilterDescription[] => [
...propertiesToValidFilters(template.properties, ''),
...template.modules.flatMap(({ properties, name, type }) => propertiesToValidFilters(properties, name || type)),
];

export const templatesToFilters = (templates: ITemplate[]): TicketFilterDescription[] => {
let filters: TicketFilterDescription[] = [...templates.flatMap(templateToFilters)];
export const templatesToFilters = (templates: ITemplate[]): TicketCardFilterDescription[] => {
let filters: TicketCardFilterDescription[] = [...templates.flatMap(templateToFilters)];
filters = uniqBy(filters, (f) => f.module + f.property + f.type);
filters = sortBy(filters, 'module');
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import FennelIcon from '@assets/icons/filters/fennel.svg';
import { Tooltip } from '@mui/material';
import { TicketFiltersSelectionList } from './list/ticketFiltersSelectionList.component';
import { SearchInput, DrillDownList, DrillDownItem } from './ticketFiltersSelection.styles';
import { TicketFilterDescription } from '../../cardFilters.types';
import { TicketCardFilterDescription } from '../../cardFilters.types';
import { FilterForm } from '../../filterForm/filterForm.component';
import { CardFilterActionMenu } from '../../filterForm/filterForm.styles';
import { TicketsCardActionsDispatchers } from '@/v5/services/actionsDispatchers';

export const FilterSelection = () => {
const [open, setOpen] = useState(false);
const [selectedFilter, setSelectedFilter] = useState<TicketFilterDescription>(null);
const [selectedFilter, setSelectedFilter] = useState<TicketCardFilterDescription>(null);
const tickets = TicketsCardHooksSelectors.selectCurrentTickets();
const unusedFilters = TicketsCardHooksSelectors.selectAvailableTemplatesFilters();
const showFiltersList = !selectedFilter?.property;
Expand Down

0 comments on commit 28fa7a6

Please sign in to comment.