@performant-software/semantic-components 1.0.10-beta.0 → 1.0.10-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ import _ from 'underscore';
15
15
  import i18n from '../i18n/i18n';
16
16
  import DropdownButton from './DropdownButton';
17
17
  import EditModal from './EditModal';
18
+ import FilterLabels from './FilterLabels';
18
19
  import './List.css';
19
20
 
20
21
  type Action = {
@@ -105,7 +106,8 @@ type Props = {
105
106
  component: Component<{}>,
106
107
  props?: any,
107
108
  state?: any,
108
- onChange: (params: any) => Promise<any>
109
+ onChange: (params: any) => Promise<any>,
110
+ showLabels?: boolean
109
111
  },
110
112
 
111
113
  /**
@@ -383,6 +385,18 @@ const useList = (WrappedComponent: ComponentType<any>) => (
383
385
  this.setState({ modalFilter: true });
384
386
  }
385
387
 
388
+ /**
389
+ * Calls the filter onChange function with the passed filter removed.
390
+ *
391
+ * @param filter
392
+ *
393
+ * @returns {*}
394
+ */
395
+ onRemoveFilter(filter) {
396
+ const { onChange, props: { item } } = this.props.filters;
397
+ return onChange({ filters: _.filter(item.filters, (f) => f.uid !== filter.uid) });
398
+ }
399
+
386
400
  /**
387
401
  * Saves the passed item and closes the add/edit modal.
388
402
  *
@@ -754,6 +768,8 @@ const useList = (WrappedComponent: ComponentType<any>) => (
754
768
  renderHeader = true;
755
769
  }
756
770
 
771
+ const hasLabels = filters && filters.showLabels && !_.isEmpty(filters.props.item.filters);
772
+
757
773
  if (!renderHeader) {
758
774
  return null;
759
775
  }
@@ -763,41 +779,58 @@ const useList = (WrappedComponent: ComponentType<any>) => (
763
779
  className='header'
764
780
  >
765
781
  <Grid
766
- columns={2}
767
- verticalAlign='bottom'
782
+ className={hasLabels ? 'filter-labels' : undefined}
783
+ verticalAlign='top'
768
784
  >
769
- <Grid.Column
770
- textAlign='left'
785
+ <Grid.Row
786
+ columns={2}
771
787
  >
772
- { _.map(buttons, this.renderButton.bind(this)) }
773
- </Grid.Column>
774
- <Grid.Column
775
- textAlign='right'
776
- >
777
- <Menu
778
- compact
779
- borderless
780
- secondary
781
- className='flex-end-menu'
788
+ <Grid.Column
789
+ textAlign='left'
790
+ >
791
+ { _.map(buttons, this.renderButton.bind(this)) }
792
+ </Grid.Column>
793
+ <Grid.Column
794
+ textAlign='right'
782
795
  >
783
- { renderListHeader && (
784
- <Menu.Menu className='list-header-menu'>
785
- { renderListHeader() }
796
+ <Menu
797
+ compact
798
+ borderless
799
+ secondary
800
+ className='flex-end-menu'
801
+ >
802
+ { renderListHeader && (
803
+ <Menu.Menu className='list-header-menu'>
804
+ { renderListHeader() }
805
+ </Menu.Menu>
806
+ )}
807
+ <Menu.Menu>
808
+ { filters && this.renderFilterButton() }
786
809
  </Menu.Menu>
787
- )}
788
- <Menu.Menu>
789
- { filters && this.renderFilterButton() }
790
- </Menu.Menu>
791
- { perPageOptions && (
792
- <Menu.Menu className='per-page-menu'>
793
- { this.renderPerPage() }
810
+ { perPageOptions && (
811
+ <Menu.Menu className='per-page-menu'>
812
+ { this.renderPerPage() }
813
+ </Menu.Menu>
814
+ )}
815
+ <Menu.Menu>
816
+ { renderSearch && renderSearch() }
794
817
  </Menu.Menu>
795
- )}
796
- <Menu.Menu>
797
- { renderSearch && renderSearch() }
798
- </Menu.Menu>
799
- </Menu>
800
- </Grid.Column>
818
+ </Menu>
819
+ </Grid.Column>
820
+ </Grid.Row>
821
+ { hasLabels && (
822
+ <Grid.Row
823
+ columns={1}
824
+ >
825
+ <Grid.Column>
826
+ <FilterLabels
827
+ filters={filters.props.item.filters}
828
+ onClear={() => filters.onChange({ filters: [] })}
829
+ onClick={(filter) => this.onRemoveFilter(filter)}
830
+ />
831
+ </Grid.Column>
832
+ </Grid.Row>
833
+ )}
801
834
  </Grid>
802
835
  </div>
803
836
  );
@@ -75,6 +75,40 @@ const FilterOperators = {
75
75
  lessThan: 'less_than'
76
76
  };
77
77
 
78
+ const FilterOperatorOptions = [{
79
+ key: FilterOperators.equal,
80
+ value: FilterOperators.equal,
81
+ text: i18n.t('ListFilters.operators.equal')
82
+ }, {
83
+ key: FilterOperators.notEqual,
84
+ value: FilterOperators.notEqual,
85
+ text: i18n.t('ListFilters.operators.notEqual')
86
+ }, {
87
+ key: FilterOperators.contain,
88
+ value: FilterOperators.contain,
89
+ text: i18n.t('ListFilters.operators.contain')
90
+ }, {
91
+ key: FilterOperators.notContain,
92
+ value: FilterOperators.notContain,
93
+ text: i18n.t('ListFilters.operators.notContain')
94
+ }, {
95
+ key: FilterOperators.empty,
96
+ value: FilterOperators.empty,
97
+ text: i18n.t('ListFilters.operators.empty')
98
+ }, {
99
+ key: FilterOperators.notEmpty,
100
+ value: FilterOperators.notEmpty,
101
+ text: i18n.t('ListFilters.operators.notEmpty')
102
+ }, {
103
+ key: FilterOperators.greaterThan,
104
+ value: FilterOperators.greaterThan,
105
+ text: i18n.t('ListFilters.operators.greaterThan')
106
+ }, {
107
+ key: FilterOperators.lessThan,
108
+ value: FilterOperators.lessThan,
109
+ text: i18n.t('ListFilters.operators.lessThan')
110
+ }];
111
+
78
112
  const OperatorsByType = {
79
113
  [FilterTypes.boolean]: [
80
114
  FilterOperators.equal
@@ -110,40 +144,6 @@ const OperatorsByType = {
110
144
  ]
111
145
  };
112
146
 
113
- const OperatorOptions = [{
114
- key: FilterOperators.equal,
115
- value: FilterOperators.equal,
116
- text: i18n.t('ListFilters.operators.equal')
117
- }, {
118
- key: FilterOperators.notEqual,
119
- value: FilterOperators.notEqual,
120
- text: i18n.t('ListFilters.operators.notEqual')
121
- }, {
122
- key: FilterOperators.contain,
123
- value: FilterOperators.contain,
124
- text: i18n.t('ListFilters.operators.contain')
125
- }, {
126
- key: FilterOperators.notContain,
127
- value: FilterOperators.notContain,
128
- text: i18n.t('ListFilters.operators.notContain')
129
- }, {
130
- key: FilterOperators.empty,
131
- value: FilterOperators.empty,
132
- text: i18n.t('ListFilters.operators.empty')
133
- }, {
134
- key: FilterOperators.notEmpty,
135
- value: FilterOperators.notEmpty,
136
- text: i18n.t('ListFilters.operators.notEmpty')
137
- }, {
138
- key: FilterOperators.greaterThan,
139
- value: FilterOperators.greaterThan,
140
- text: i18n.t('ListFilters.operators.greaterThan')
141
- }, {
142
- key: FilterOperators.lessThan,
143
- value: FilterOperators.lessThan,
144
- text: i18n.t('ListFilters.operators.lessThan')
145
- }];
146
-
147
147
  const ListFilters = (props: Props) => {
148
148
  /**
149
149
  * Returns the available operators for the passed filter type.
@@ -152,7 +152,7 @@ const ListFilters = (props: Props) => {
152
152
  */
153
153
  const getOperatorsByType = useCallback((type: string) => {
154
154
  const operators = OperatorsByType[type];
155
- return _.filter(OperatorOptions, (option) => !operators || _.contains(operators, option.key));
155
+ return _.filter(FilterOperatorOptions, (option) => !operators || _.contains(operators, option.key));
156
156
  }, []);
157
157
 
158
158
  /**
@@ -400,5 +400,10 @@ export default ListFilters;
400
400
 
401
401
  export {
402
402
  FilterTypes,
403
- FilterOperators
403
+ FilterOperators,
404
+ FilterOperatorOptions
405
+ };
406
+
407
+ export type {
408
+ Filter
404
409
  };
@@ -96,4 +96,4 @@ export type { BatchEditProps } from './hooks/BatchEdit';
96
96
  // Constants
97
97
  export { Views as ItemViews } from './components/ItemsToggle';
98
98
  export { SORT_ASCENDING, SORT_DESCENDING } from './components/DataList';
99
- export { FilterTypes, FilterOperators } from './components/ListFilters';
99
+ export { FilterTypes, FilterOperators, FilterOperatorOptions } from './components/ListFilters';