Skip to content

Commit

Permalink
Persist tag filters (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Jul 5, 2021
1 parent 4dd3325 commit 76a0700
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
30 changes: 21 additions & 9 deletions frontend/web/components/TagSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@ class TagSelect extends PureComponent {

render() {
const projectTags = (this.props.tags && this.props.tags[this.props.projectId]) || [];
const showUntagged = this.props.showUntagged && { color: '#666', label: 'Untagged', id:"" };
return (
<Row className="tag-filter mx-2 mt-3">
<div className="ml-1">
<Row>
{showUntagged && (
<div className="mr-1 mb-2">
<Tag
key={showUntagged.id}
selected={this.isSelected(showUntagged)}
onClick={this.onSelect}
className="px-2 py-2 mr-2"
tag={showUntagged}
/>
</div>
)}
{projectTags.map(tag => (
<div className="mr-1 mb-2">
<Tag
key={tag.id}
selected={this.isSelected(tag)}
onClick={this.onSelect}
className="px-2 py-2 mr-2"
tag={tag}
/>
</div>
<div className="mr-1 mb-2">
<Tag
key={tag.id}
selected={this.isSelected(tag)}
onClick={this.onSelect}
className="px-2 py-2 mr-2"
tag={tag}
/>
</div>

))}
</Row>
Expand Down
37 changes: 30 additions & 7 deletions frontend/web/components/pages/FeaturesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const FeaturesPage = class extends Component {
};
ES6Component(this);
this.listenTo(TagStore, 'loaded', () => {
// const tags = TagStore.model && TagStore.model[parseInt(this.props.match.params.projectId)];
// if (this.state.tags.length === 0 && tags && tags.length > 0) {
// this.setState({ tags: tags.map(v => v.id) });
// }
const tags = TagStore.model && TagStore.model[parseInt(this.props.match.params.projectId)];
if (this.state.tags.length === 0 && tags && tags.length > 0) {
this.setState({ tags: tags.map(v => v.id).concat('') });
}
});
AppActions.getFeatures(this.props.match.params.projectId, this.props.match.params.environmentId);
}
Expand All @@ -36,14 +36,15 @@ const FeaturesPage = class extends Component {
const { match: { params } } = newProps;
const { match: { params: oldParams } } = this.props;
if (params.environmentId != oldParams.environmentId || params.projectId != oldParams.projectId) {
this.getTags(params.projectId);
AppActions.getFeatures(params.projectId, params.environmentId);
}
}

componentDidMount = () => {
API.trackPage(Constants.pages.FEATURES);
const { match: { params } } = this.props;
AppActions.getTags(params.projectId);
this.getTags(params.projectId);
AsyncStorage.setItem('lastEnv', JSON.stringify({
orgId: AccountStore.getOrganisation().id,
projectId: params.projectId,
Expand All @@ -60,6 +61,17 @@ const FeaturesPage = class extends Component {
};


getTags = (projectId) => {
AppActions.getTags(projectId);
AsyncStorage.getItem(`${projectId}tags`).then((res) => {
if (res) {
this.setState({
tags: JSON.parse(res),
});
}
});
}

editFlag = (projectFlag, environmentFlag) => {
API.trackEvent(Constants.events.VIEW_FEATURE);
openModal(`Edit Feature: ${projectFlag.name}`, <CreateFlagModal
Expand Down Expand Up @@ -138,7 +150,12 @@ const FeaturesPage = class extends Component {

filter = (flags) => {
if (this.state.tags.length) {
return _.filter(flags, flag => _.intersection(flag.tags || [], this.state.tags).length) || [];
return _.filter(flags, (flag) => {
if (this.state.tags.includes('') && (!flag.tags || !flag.tags.length)) {
return true;
}
return _.intersection(flag.tags || [], this.state.tags).length;
}) || [];
}
return flags;
}
Expand Down Expand Up @@ -212,7 +229,13 @@ const FeaturesPage = class extends Component {
]}
items={this.filter(projectFlags, this.state.tags)}
header={(
<TagSelect projectId={projectId} value={this.state.tags} onChange={tags => this.setState({ tags })}/>
<TagSelect
showUntagged
projectId={projectId} value={this.state.tags} onChange={(tags) => {
this.setState({ tags });
AsyncStorage.setItem(`${projectId}tags`, JSON.stringify(tags));
}}
/>
)}
renderRow={(projectFlag, i) => {
const { name, id, enabled, created_date, description, type } = projectFlag;
Expand Down

0 comments on commit 76a0700

Please sign in to comment.