From 7f6cd6bdc1cf5dd70491ef36496f549a195a2009 Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Thu, 29 Sep 2022 19:32:19 +0200 Subject: [PATCH 1/3] feat: allow hiding custom clade columns --- .../nextclade-web/src/state/results.state.ts | 18 ++++++++++++++++-- .../nextclade-web/src/types/auspice/index.d.ts | 1 + packages_rs/nextclade/src/tree/tree.rs | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages_rs/nextclade-web/src/state/results.state.ts b/packages_rs/nextclade-web/src/state/results.state.ts index 1c0760272..29c2211a0 100644 --- a/packages_rs/nextclade-web/src/state/results.state.ts +++ b/packages_rs/nextclade-web/src/state/results.state.ts @@ -215,11 +215,25 @@ export const hasTreeAtom = selector({ }, }) -export const cladeNodeAttrDescsAtom = atom({ - key: 'cladeNodeAttrDescs', +const cladeNodeAttrDescsStorageAtom = atom({ + key: 'cladeNodeAttrDescsStorage', default: [], }) +export const cladeNodeAttrDescsAtom = selector({ + key: 'cladeNodeAttrDescs', + get({ get }): CladeNodeAttrDesc[] { + return get(cladeNodeAttrDescsStorageAtom).filter(({ showInWeb }) => showInWeb) + }, + + set({ set, reset }, descs: CladeNodeAttrDesc[] | DefaultValue) { + set(cladeNodeAttrDescsStorageAtom, descs) + if (!isDefaultValue(descs)) { + reset(cladeNodeAttrDescsStorageAtom) + } + }, +}) + export const cladeNodeAttrKeysAtom = selector({ key: 'cladeNodeAttrKeys', get: ({ get }) => get(cladeNodeAttrDescsAtom).map((desc) => desc.name), diff --git a/packages_rs/nextclade-web/src/types/auspice/index.d.ts b/packages_rs/nextclade-web/src/types/auspice/index.d.ts index 5caad5c8f..205050f21 100644 --- a/packages_rs/nextclade-web/src/types/auspice/index.d.ts +++ b/packages_rs/nextclade-web/src/types/auspice/index.d.ts @@ -203,6 +203,7 @@ declare module 'auspice' { name: string displayName: string description: string + showInWeb: boolean } export declare interface AuspiceMetadata { diff --git a/packages_rs/nextclade/src/tree/tree.rs b/packages_rs/nextclade/src/tree/tree.rs index de0b9c45e..c0bc9a665 100644 --- a/packages_rs/nextclade/src/tree/tree.rs +++ b/packages_rs/nextclade/src/tree/tree.rs @@ -167,6 +167,8 @@ pub struct CladeNodeAttrKeyDesc { pub name: String, pub display_name: String, pub description: String, + #[serde(default)] + pub show_in_web: bool, } #[derive(Clone, Serialize, Deserialize, Validate, Debug)] From 8e7eb6468099a40ebba11f190cc7c4083f70b6de Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Thu, 29 Sep 2022 19:54:33 +0200 Subject: [PATCH 2/3] fix: show custom clade columns by default Let's flip the boolean, so that it's natural default is `false` --- packages_rs/nextclade-web/src/state/results.state.ts | 2 +- packages_rs/nextclade-web/src/types/auspice/index.d.ts | 2 +- packages_rs/nextclade/src/tree/tree.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages_rs/nextclade-web/src/state/results.state.ts b/packages_rs/nextclade-web/src/state/results.state.ts index 29c2211a0..49802ccc4 100644 --- a/packages_rs/nextclade-web/src/state/results.state.ts +++ b/packages_rs/nextclade-web/src/state/results.state.ts @@ -223,7 +223,7 @@ const cladeNodeAttrDescsStorageAtom = atom({ export const cladeNodeAttrDescsAtom = selector({ key: 'cladeNodeAttrDescs', get({ get }): CladeNodeAttrDesc[] { - return get(cladeNodeAttrDescsStorageAtom).filter(({ showInWeb }) => showInWeb) + return get(cladeNodeAttrDescsStorageAtom).filter(({ hideInWeb }) => !hideInWeb) }, set({ set, reset }, descs: CladeNodeAttrDesc[] | DefaultValue) { diff --git a/packages_rs/nextclade-web/src/types/auspice/index.d.ts b/packages_rs/nextclade-web/src/types/auspice/index.d.ts index 205050f21..52d79e2ee 100644 --- a/packages_rs/nextclade-web/src/types/auspice/index.d.ts +++ b/packages_rs/nextclade-web/src/types/auspice/index.d.ts @@ -203,7 +203,7 @@ declare module 'auspice' { name: string displayName: string description: string - showInWeb: boolean + hideInWeb: boolean } export declare interface AuspiceMetadata { diff --git a/packages_rs/nextclade/src/tree/tree.rs b/packages_rs/nextclade/src/tree/tree.rs index c0bc9a665..1a4ad872f 100644 --- a/packages_rs/nextclade/src/tree/tree.rs +++ b/packages_rs/nextclade/src/tree/tree.rs @@ -168,7 +168,7 @@ pub struct CladeNodeAttrKeyDesc { pub display_name: String, pub description: String, #[serde(default)] - pub show_in_web: bool, + pub hide_in_web: bool, } #[derive(Clone, Serialize, Deserialize, Validate, Debug)] From d30d60885f8a68d382b04570f388cdeb094503aa Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Tue, 4 Oct 2022 00:37:01 +0200 Subject: [PATCH 3/3] fix: reset node attr state correctly across runs --- packages_rs/nextclade-web/src/state/results.state.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages_rs/nextclade-web/src/state/results.state.ts b/packages_rs/nextclade-web/src/state/results.state.ts index 49802ccc4..5a807e378 100644 --- a/packages_rs/nextclade-web/src/state/results.state.ts +++ b/packages_rs/nextclade-web/src/state/results.state.ts @@ -228,7 +228,7 @@ export const cladeNodeAttrDescsAtom = selector({ set({ set, reset }, descs: CladeNodeAttrDesc[] | DefaultValue) { set(cladeNodeAttrDescsStorageAtom, descs) - if (!isDefaultValue(descs)) { + if (isDefaultValue(descs)) { reset(cladeNodeAttrDescsStorageAtom) } },