//
// SPDX-License-Identifier: AGPL-3.0
+import { PropertyValue } from "~/models/search-bar";
+
export const formatDate = (isoDate?: string) => {
if (isoDate) {
const date = new Date(isoDate);
unit: "B"
}
];
+
+export const formatPropertyValue = (pv: PropertyValue) => {
+ if (pv.key) {
+ return pv.value
+ ? `${pv.key}: ${pv.value}`
+ : pv.key;
+ }
+ return "";
+};
saveQuery: boolean;
queryName: string;
searchValue: string;
- properties: PropertyValues[];
+ properties: PropertyValue[];
};
-export interface PropertyValues {
+export interface PropertyValue {
key: string;
value: string;
}
import { SearchView } from '~/store/search-bar/search-bar-reducer';
import { navigateTo, navigateToSearchResults } from '~/store/navigation/navigation-action';
import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
-import { ClusterObjectType, PropertyValues, SearchBarAdvanceFormData } from '~/models/search-bar';
+import { ClusterObjectType, PropertyValue, SearchBarAdvanceFormData } from '~/models/search-bar';
import { debounce } from 'debounce';
import * as _ from "lodash";
import { getModifiedKeysValues } from "~/common/objects";
const getFirstProp = (sq: ParseSearchQuery, name: string) => sq.properties[name] && sq.properties[name][0];
const getPropValue = (sq: ParseSearchQuery, name: string, value: string) => sq.properties[name] && sq.properties[name].find((v: string) => v === value);
-const getProperties = (sq: ParseSearchQuery): PropertyValues[] => {
+const getProperties = (sq: ParseSearchQuery): PropertyValue[] => {
if (sq.properties.has) {
return sq.properties.has.map((value: string) => {
const v = value.split(':');
dispatch<any>(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID));
};
-export const changeAdvanceFormProperty = (property: string, value: PropertyValues[] | string = '') =>
+export const changeAdvanceFormProperty = (property: string, value: PropertyValue[] | string = '') =>
(dispatch: Dispatch) => {
dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, property, value));
};
-export const updateAdvanceFormProperties = (propertyValues: PropertyValues) =>
+export const updateAdvanceFormProperties = (propertyValues: PropertyValue) =>
(dispatch: Dispatch) => {
dispatch(arrayPush(SEARCH_BAR_ADVANCE_FORM_NAME, 'properties', propertyValues));
};
changeAdvanceFormProperty,
updateAdvanceFormProperties
} from '~/store/search-bar/search-bar-actions';
-import { PropertyValues } from '~/models/search-bar';
+import { PropertyValue } from '~/models/search-bar';
import { ArvadosTheme } from '~/common/custom-theme';
import { SearchBarKeyField, SearchBarValueField } from '~/views-components/form-fields/search-bar-form-fields';
import { Chips } from '~/components/chips/chips';
+import { formatPropertyValue } from "~/common/formatters";
type CssRules = 'label' | 'button';
submitting: boolean;
invalid: boolean;
pristine: boolean;
- propertyValues: PropertyValues;
- fields: PropertyValues[];
+ propertyValues: PropertyValue;
+ fields: PropertyValue[];
}
interface SearchBarAdvancedPropertiesViewActionProps {
setProps: () => void;
- addProp: (propertyValues: PropertyValues) => void;
- getAllFields: (propertyValues: PropertyValues[]) => PropertyValues[] | [];
+ addProp: (propertyValues: PropertyValue) => void;
+ getAllFields: (propertyValues: PropertyValue[]) => PropertyValue[] | [];
}
type SearchBarAdvancedPropertiesViewProps = SearchBarAdvancedPropertiesViewDataProps
};
const mapDispatchToProps = (dispatch: Dispatch) => ({
- setProps: (propertyValues: PropertyValues[]) => {
+ setProps: (propertyValues: PropertyValue[]) => {
dispatch<any>(changeAdvanceFormProperty('properties', propertyValues));
},
- addProp: (propertyValues: PropertyValues) => {
+ addProp: (propertyValues: PropertyValue) => {
dispatch<any>(updateAdvanceFormProperties(propertyValues));
dispatch<any>(changeAdvanceFormProperty('key'));
dispatch<any>(changeAdvanceFormProperty('value'));
<Chips values={getAllFields(fields)}
deletable
onChange={setProps}
- getLabel={(field: PropertyValues) => `${field.key}: ${field.value}`} />
+ getLabel={(field: PropertyValue) => formatPropertyValue(field)} />
</Grid>
</Grid>
)
-);
\ No newline at end of file
+);