Skip to content

Commit

Permalink
Merge pull request #126 from M3nin0/dev
Browse files Browse the repository at this point in the history
form: update filter to use new type field
  • Loading branch information
M3nin0 committed Jun 5, 2024
2 parents 1663756 + 0603876 commit 574db22
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [18]

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions docker/builder/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ docker compose -f docker/builder/docker-compose.yml up -d
#

# installing utility tool to auth
npm install -g npm-cli-adduser
npm install -g npm-cli-login

# authenticating
npm-cli-adduser \
npm-cli-login \
-u $VERDACCIO_USERNAME \
-p $VERDACCIO_PASSWORD \
-e $VERDACCIO_EMAIL \
Expand Down
68 changes: 68 additions & 0 deletions src/lib/components/form/base/fields/RecordTypeField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of GEO-Components-React.
* Copyright (C) 2022 GEO Secretariat.
*
* GEO-Components-React is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import React from 'react';

import PropTypes from 'prop-types';
import { SelectField } from 'react-invenio-forms';

import { i18next } from '@translations/i18next';
import { Icon } from 'semantic-ui-react';

/**
* Record Type field for the GEO Knowledge Hub.
* @constructor
*
* @param {String} fieldPath Path where the field data will be stored in the
* Formik context.
* @param {Object} fieldProps (Spread) Extra parameters for the `SelectField`.
*/
export const RecordTypeField = ({ fieldPath, ...fieldProps }) => {
return (
<SelectField
fieldPath={fieldPath}
options={[
{
id: 'package',
key: 'package',
text: 'Knowledge Package',
value: 'package',
},
{
id: 'resource',
key: 'resource',
text: 'Knowledge Resource',
value: 'resource',
},
{
id: 'marketplace-item',
key: 'marketplace-item',
text: 'Commercial Item',
value: 'marketplace-item',
},
]}
{...fieldProps}
/>
);
};

RecordTypeField.propTypes = {
fieldPath: PropTypes.string.isRequired,
};

RecordTypeField.defaultProps = {
fieldPath: 'metadata.record_type',
label: (
<>
<Icon name={'shopping bag'} /> {i18next.t('Record type')}
</>
),
placeholder: i18next.t('Select a Record Type'),
noQueryMessage: i18next.t('Start typing to search for a Record Type'),
multiple: true,
};
2 changes: 2 additions & 0 deletions src/lib/components/form/base/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export { TargetAudienceField } from './TargetAudienceField';
export { EngagementPriorityField } from './EngagementPriorityField';
export { WorkProgrammeActivityField } from './WorkProgrammeActivityField';

export { RecordTypeField } from './RecordTypeField';
export { ResourceTypeField } from './ResourceTypeField';

export { AuthorsField } from './AuthorsField';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TargetAudienceField,
WorkProgrammeActivityField,
ResourceTypeField,
RecordTypeField,
AuthorsField,
} from '../../../../../base';

Expand All @@ -42,6 +43,17 @@ export const BasicFilterForm = ({ fieldPathPrefix, ...fieldConfig }) => {
return (
<>
<Grid verticalAlign="middle" centered>
<Grid.Row>
<Grid.Column width={16}>
<RecordTypeField
fluid
multiple={true}
clearable={true}
required={false}
fieldPath={generateFieldPathWithPrefix('recordTypes')}
/>
</Grid.Column>
</Grid.Row>
<Grid.Row>
<Grid.Column width={16}>
<ResourceTypeField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export class StaticQueryStringSerializer extends QueryStringSerializer {
'OR',
'value'
),
recordTypes: new ValueField(
'form.recordTypes',
'parent.type',
'OR'
),
resourceTypes: new ValueField(
'form.resourceTypes',
'metadata.resource_type.id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ValueField extends ArgField {
// extracting the values
if (Array.isArray(fieldValue)) {
fieldValue = fieldValue
.map((obj) => obj.value)
.map((obj) => obj.value || obj)
.join(` ${this.operator} `);
}

Expand Down

0 comments on commit 574db22

Please sign in to comment.