2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-07 04:12:11 +00:00

Fix for status table filters

This commit is contained in:
Oliver Walters
2024-11-21 13:21:26 +00:00
parent 80d6a97e1f
commit d1e045017a
2 changed files with 11 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ import type { ModelType } from '../enums/ModelType';
import { apiUrl } from './ApiState';
import { useUserState } from './UserState';
type StatusLookup = Record<ModelType | string, StatusCodeListInterface>;
export type StatusLookup = Record<ModelType | string, StatusCodeListInterface>;
interface ServerStateProps {
status?: StatusLookup;

View File

@@ -1,7 +1,11 @@
import { t } from '@lingui/macro';
import type {
StatusCodeInterface,
StatusCodeListInterface
} from '../components/render/StatusRenderer';
import type { ModelType } from '../enums/ModelType';
import { useGlobalStatusState } from '../states/StatusState';
import { type StatusLookup, useGlobalStatusState } from '../states/StatusState';
/**
* Interface for the table filter choice
@@ -70,17 +74,18 @@ export function StatusFilterOptions(
model: ModelType
): () => TableFilterChoice[] {
return () => {
const statusCodeList = useGlobalStatusState.getState().status;
const statusCodeList: StatusLookup | undefined =
useGlobalStatusState.getState().status;
if (!statusCodeList) {
return [];
}
const codes = statusCodeList[model];
const codes: StatusCodeListInterface | undefined = statusCodeList[model];
if (codes) {
return Object.keys(codes).map((key) => {
const entry = codes[key];
return Object.keys(codes.values).map((key) => {
const entry: StatusCodeInterface = codes.values[key];
return {
value: entry.key.toString(),
label: entry.label?.toString() ?? entry.key.toString()