Initial commit: ZiRA Classification Tool for Zuyderland CMDB
This commit is contained in:
91
frontend/src/stores/navigationStore.ts
Normal file
91
frontend/src/stores/navigationStore.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import type { SearchFilters } from '../types';
|
||||
|
||||
interface NavigationState {
|
||||
applicationIds: string[];
|
||||
currentIndex: number;
|
||||
filters: SearchFilters;
|
||||
setNavigationContext: (ids: string[], filters: SearchFilters, currentIndex?: number) => void;
|
||||
setCurrentIndexById: (id: string) => void;
|
||||
getCurrentId: () => string | null;
|
||||
getNextId: () => string | null;
|
||||
getPreviousId: () => string | null;
|
||||
goToNext: () => void;
|
||||
goToPrevious: () => void;
|
||||
goToIndex: (index: number) => void;
|
||||
clear: () => void;
|
||||
}
|
||||
|
||||
export const useNavigationStore = create<NavigationState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
applicationIds: [],
|
||||
currentIndex: -1,
|
||||
filters: {},
|
||||
|
||||
setNavigationContext: (ids, filters, currentIndex = 0) =>
|
||||
set({
|
||||
applicationIds: ids,
|
||||
filters,
|
||||
currentIndex,
|
||||
}),
|
||||
|
||||
setCurrentIndexById: (id: string) => {
|
||||
const { applicationIds } = get();
|
||||
const index = applicationIds.indexOf(id);
|
||||
if (index !== -1) {
|
||||
set({ currentIndex: index });
|
||||
}
|
||||
},
|
||||
|
||||
getCurrentId: () => {
|
||||
const { applicationIds, currentIndex } = get();
|
||||
return currentIndex >= 0 && currentIndex < applicationIds.length
|
||||
? applicationIds[currentIndex]
|
||||
: null;
|
||||
},
|
||||
|
||||
getNextId: () => {
|
||||
const { applicationIds, currentIndex } = get();
|
||||
return currentIndex + 1 < applicationIds.length
|
||||
? applicationIds[currentIndex + 1]
|
||||
: null;
|
||||
},
|
||||
|
||||
getPreviousId: () => {
|
||||
const { applicationIds, currentIndex } = get();
|
||||
return currentIndex > 0 ? applicationIds[currentIndex - 1] : null;
|
||||
},
|
||||
|
||||
goToNext: () =>
|
||||
set((state) => ({
|
||||
currentIndex:
|
||||
state.currentIndex + 1 < state.applicationIds.length
|
||||
? state.currentIndex + 1
|
||||
: state.currentIndex,
|
||||
})),
|
||||
|
||||
goToPrevious: () =>
|
||||
set((state) => ({
|
||||
currentIndex: state.currentIndex > 0 ? state.currentIndex - 1 : 0,
|
||||
})),
|
||||
|
||||
goToIndex: (index) =>
|
||||
set((state) => ({
|
||||
currentIndex:
|
||||
index >= 0 && index < state.applicationIds.length ? index : state.currentIndex,
|
||||
})),
|
||||
|
||||
clear: () =>
|
||||
set({
|
||||
applicationIds: [],
|
||||
currentIndex: -1,
|
||||
filters: {},
|
||||
}),
|
||||
}),
|
||||
{
|
||||
name: 'zira-navigation-context',
|
||||
}
|
||||
)
|
||||
);
|
||||
130
frontend/src/stores/searchStore.ts
Normal file
130
frontend/src/stores/searchStore.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
import { create } from 'zustand';
|
||||
import type { SearchFilters, ApplicationStatus } from '../types';
|
||||
|
||||
interface SearchState {
|
||||
filters: SearchFilters;
|
||||
currentPage: number;
|
||||
pageSize: number;
|
||||
setSearchText: (text: string) => void;
|
||||
setStatuses: (statuses: ApplicationStatus[]) => void;
|
||||
setApplicationFunction: (value: 'all' | 'filled' | 'empty') => void;
|
||||
setGovernanceModel: (value: 'all' | 'filled' | 'empty') => void;
|
||||
setDynamicsFactor: (value: 'all' | 'filled' | 'empty') => void;
|
||||
setComplexityFactor: (value: 'all' | 'filled' | 'empty') => void;
|
||||
setApplicationCluster: (value: 'all' | 'filled' | 'empty') => void;
|
||||
setApplicationType: (value: 'all' | 'filled' | 'empty') => void;
|
||||
setOrganisation: (value: string | undefined) => void;
|
||||
setHostingType: (value: string | undefined) => void;
|
||||
setBusinessImportance: (value: string | undefined) => void;
|
||||
setCurrentPage: (page: number) => void;
|
||||
setPageSize: (size: number) => void;
|
||||
resetFilters: () => void;
|
||||
}
|
||||
|
||||
// Default statuses: all except "Closed"
|
||||
const defaultStatuses: ApplicationStatus[] = [
|
||||
'In Production',
|
||||
'Implementation',
|
||||
'Proof of Concept',
|
||||
'End of support',
|
||||
'End of life',
|
||||
'Deprecated',
|
||||
'Shadow IT',
|
||||
'Undefined',
|
||||
];
|
||||
|
||||
const defaultFilters: SearchFilters = {
|
||||
searchText: '',
|
||||
statuses: defaultStatuses,
|
||||
applicationFunction: 'all',
|
||||
governanceModel: 'all',
|
||||
dynamicsFactor: 'all',
|
||||
complexityFactor: 'all',
|
||||
applicationCluster: 'all',
|
||||
applicationType: 'all',
|
||||
organisation: undefined,
|
||||
hostingType: undefined,
|
||||
businessImportance: undefined,
|
||||
};
|
||||
|
||||
export const useSearchStore = create<SearchState>((set) => ({
|
||||
filters: { ...defaultFilters },
|
||||
currentPage: 1,
|
||||
pageSize: 25,
|
||||
|
||||
setSearchText: (text) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, searchText: text },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setStatuses: (statuses) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, statuses },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setApplicationFunction: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, applicationFunction: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setGovernanceModel: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, governanceModel: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setDynamicsFactor: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, dynamicsFactor: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setComplexityFactor: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, complexityFactor: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setApplicationCluster: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, applicationCluster: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setApplicationType: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, applicationType: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setOrganisation: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, organisation: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setHostingType: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, hostingType: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setBusinessImportance: (value) =>
|
||||
set((state) => ({
|
||||
filters: { ...state.filters, businessImportance: value },
|
||||
currentPage: 1,
|
||||
})),
|
||||
|
||||
setCurrentPage: (page) => set({ currentPage: page }),
|
||||
|
||||
setPageSize: (size) => set({ pageSize: size, currentPage: 1 }),
|
||||
|
||||
resetFilters: () =>
|
||||
set({
|
||||
filters: { ...defaultFilters },
|
||||
currentPage: 1,
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user