Skip to content

Commit

Permalink
Rerender PillTags when filters change
Browse files Browse the repository at this point in the history
- Look at global store for deletion state
- Rerender when deleted
- Rerender filter added
  • Loading branch information
Bas Leenknegt committed Feb 28, 2023
1 parent 99c0f3c commit c87289b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
32 changes: 17 additions & 15 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,14 @@ export class StudyViewPageStore
chartsBinsGeneratorConfigs = observable.map<string, BinsGeneratorConfig>();

@observable filterSubmitTime: number = performance.now();
@observable filterUpdateTime: number = performance.now();

/**
* Force remount of filters when filters are submitted of submit mode changes
*/
@computed
public get filtersRemountKey() {
return `${this.hesitateUpdate}${this.filterSubmitTime}`;
return `${this.hesitateUpdate}${this.filterSubmitTime}${this.filterUpdateTime}`;
}

private getDataBinFilterSet(uniqueKey: string) {
Expand Down Expand Up @@ -479,6 +480,21 @@ export class StudyViewPageStore
)
);

this.reactionDisposers.push(
reaction(
() => [this.filtersProx, this.hesitateUpdate],
() => {
if (!this.hesitateUpdate) {
this.filters = this.filtersProx;
}
this.filterUpdateTime = performance.now();
},
{
equals: comparer.structural,
}
)
);

/**
* Submit filters when submit mode changes
* or when user clicks submit button
Expand All @@ -505,20 +521,6 @@ export class StudyViewPageStore
)
);

this.reactionDisposers.push(
reaction(
() => [this.filtersProx, this.hesitateUpdate],
() => {
if (!this.hesitateUpdate) {
this.filters = this.filtersProx;
}
},
{
equals: comparer.structural,
}
)
);

this.reactionDisposers.push(
reaction(
() => [
Expand Down
18 changes: 10 additions & 8 deletions src/shared/components/PillTag/PillTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export type PillStore = {
getBrowserWindow().hesitantPillStore = {} as PillStore;
getBrowserWindow().submittedPillStore = {} as PillStore;

@observer
export class PillTag extends React.Component<IPillTagProps, {}> {
@observable isDeleted = false;

constructor(props: IPillTagProps) {
super(props);
makeObservable(this);
Expand Down Expand Up @@ -80,7 +77,6 @@ export class PillTag extends React.Component<IPillTagProps, {}> {
}

private handleDelete() {
this.isDeleted = true;
if (!this.hesitateUpdate) {
// Delete all filters immediately in autocommit mode:
this.deleteNow();
Expand All @@ -97,8 +93,10 @@ export class PillTag extends React.Component<IPillTagProps, {}> {
}
if (this.hesitateUpdate && !this.hesitantPillStoreEntry) {
// Postpone deleting of submitted filters in hesitate mode:
this.addPillToHesitateStore();
const isDeleted = true;
this.addPillToHesitateStore(isDeleted);
}
this.forceUpdate();
}

private deleteNow() {
Expand All @@ -109,8 +107,8 @@ export class PillTag extends React.Component<IPillTagProps, {}> {
}
}

private addPillToHesitateStore() {
const onDeleteCallback = this.isDeleted
private addPillToHesitateStore(isDeleted = false) {
const onDeleteCallback = isDeleted
? () => {
if (this.props.onDelete) {
this.props.onDelete();
Expand Down Expand Up @@ -159,6 +157,10 @@ export class PillTag extends React.Component<IPillTagProps, {}> {
: this.props.content.element;
}

private isDeleted() {
return !!this.hesitantPillStoreEntry?.onDeleteCallback;
}

render() {
const isPending = !!this.hesitantPillStoreEntry;

Expand All @@ -167,7 +169,7 @@ export class PillTag extends React.Component<IPillTagProps, {}> {
className={classnames({
[styles.main]: true,
[styles.pending]: isPending,
[styles.pendingDelete]: this.isDeleted,
[styles.pendingDelete]: this.isDeleted(),
})}
style={{
background: this.props.backgroundColor,
Expand Down

0 comments on commit c87289b

Please sign in to comment.