From 2eaf1c2d16314908dc9c31b50a0203e90d35b30c Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 21 Dec 2020 13:56:53 -0500 Subject: [PATCH] Use undefined featureData by default instead of empty object --- packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx | 4 ++++ packages/core/BaseFeatureWidget/index.ts | 4 ++-- plugins/alignments/src/AlignmentsFeatureDetail/index.js | 4 ++-- plugins/alignments/src/AlignmentsFeatureDetail/index.test.js | 2 +- .../src/BreakpointAlignmentsFeatureDetail/index.js | 4 ++-- plugins/variants/src/VariantFeatureWidget/index.js | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx b/packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx index 23fcc0301e..002a5b0cd1 100644 --- a/packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx +++ b/packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx @@ -433,6 +433,10 @@ const Subfeature = (props: BaseProps) => { export const BaseFeatureDetails = observer((props: BaseInputProps) => { const classes = useStyles() const { model } = props + + if (!model.featureData) { + return null + } const feature = JSON.parse(JSON.stringify(model.featureData)) return ( diff --git a/packages/core/BaseFeatureWidget/index.ts b/packages/core/BaseFeatureWidget/index.ts index 5655ef748a..2fd80bc145 100644 --- a/packages/core/BaseFeatureWidget/index.ts +++ b/packages/core/BaseFeatureWidget/index.ts @@ -8,14 +8,14 @@ const stateModel = types .model('BaseFeatureWidget', { id: ElementId, type: types.literal('BaseFeatureWidget'), - featureData: types.frozen({}), + featureData: types.frozen(), }) .actions(self => ({ setFeatureData(data: Record) { self.featureData = data }, clearFeatureData() { - self.featureData = {} + self.featureData = undefined }, })) diff --git a/plugins/alignments/src/AlignmentsFeatureDetail/index.js b/plugins/alignments/src/AlignmentsFeatureDetail/index.js index 98a60c7079..c01f2e1750 100644 --- a/plugins/alignments/src/AlignmentsFeatureDetail/index.js +++ b/plugins/alignments/src/AlignmentsFeatureDetail/index.js @@ -8,14 +8,14 @@ const stateModel = types .model('AlignmentsFeatureWidget', { id: ElementId, type: types.literal('AlignmentsFeatureWidget'), - featureData: types.frozen({}), + featureData: types.frozen(), }) .actions(self => ({ setFeatureData(data) { self.featureData = data }, clearFeatureData() { - self.featureData = {} + self.featureData = undefined }, })) diff --git a/plugins/alignments/src/AlignmentsFeatureDetail/index.test.js b/plugins/alignments/src/AlignmentsFeatureDetail/index.test.js index d57700f993..e1acc91b20 100644 --- a/plugins/alignments/src/AlignmentsFeatureDetail/index.test.js +++ b/plugins/alignments/src/AlignmentsFeatureDetail/index.test.js @@ -5,7 +5,6 @@ import ReactComponent from './AlignmentsFeatureDetail' test('open up a widget', () => { const model = stateModel.create({ type: 'AlignmentsFeatureWidget' }) - const { container, getByText } = render() model.setFeatureData({ seq: 'TTGTTGCGGAGTTGAACAACGGCATTAGGAACACTTCCGTCTCTCACTTTTATACGATTATGATTGGTTCTTTAGCCTTGGTTTAGATTGGTAGTAGTAG', @@ -29,6 +28,7 @@ test('open up a widget', () => { refName: 'ctgA', type: 'match', }) + const { container, getByText } = render() expect(container.firstChild).toMatchSnapshot() expect(getByText('ctgA:3..102 (+)')).toBeTruthy() }) diff --git a/plugins/breakpoint-split-view/src/BreakpointAlignmentsFeatureDetail/index.js b/plugins/breakpoint-split-view/src/BreakpointAlignmentsFeatureDetail/index.js index bb319973f4..e142e834b3 100644 --- a/plugins/breakpoint-split-view/src/BreakpointAlignmentsFeatureDetail/index.js +++ b/plugins/breakpoint-split-view/src/BreakpointAlignmentsFeatureDetail/index.js @@ -8,14 +8,14 @@ const stateModel = types .model('BreakpointAlignmentsWidget', { id: ElementId, type: types.literal('BreakpointAlignmentsWidget'), - featureData: types.frozen({}), + featureData: types.frozen(), }) .actions(self => ({ setFeatureData(data) { self.featureData = data }, clearFeatureData() { - self.featureData = {} + self.featureData = undefined }, })) diff --git a/plugins/variants/src/VariantFeatureWidget/index.js b/plugins/variants/src/VariantFeatureWidget/index.js index 6993487ef3..5b784051ec 100644 --- a/plugins/variants/src/VariantFeatureWidget/index.js +++ b/plugins/variants/src/VariantFeatureWidget/index.js @@ -7,14 +7,14 @@ export const stateModel = types .model('VariantFeatureWidget', { id: ElementId, type: types.literal('VariantFeatureWidget'), - featureData: types.frozen({}), + featureData: types.frozen(), }) .actions(self => ({ setFeatureData(data) { self.featureData = data }, clearFeatureData() { - self.featureData = {} + self.featureData = undefined }, }))