Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use string not object in LemonSelect #17774

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FEATURE_FLAGS } from 'lib/constants'

export function DatabaseTablesContainer(): JSX.Element {
const { filteredTables, databaseLoading } = useValues(databaseSceneLogic)
const { toggleFieldModal, selectTable } = useActions(viewLinkLogic)
const { toggleFieldModal, selectTableName } = useActions(viewLinkLogic)
const { featureFlags } = useValues(featureFlagLogic)

return (
Expand All @@ -33,7 +33,7 @@ export function DatabaseTablesContainer(): JSX.Element {
className="mt-2"
type="primary"
onClick={() => {
selectTable(row)
selectTableName(row.name)
toggleFieldModal()
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const databaseSceneLogic = kea<databaseSceneLogicType>([
(s) => [s.filteredTables],
(filteredTables: DatabaseSceneRow[]) =>
filteredTables.map((row) => ({
value: row,
value: row.name,
label: row.name,
})),
],
Expand Down
16 changes: 7 additions & 9 deletions frontend/src/scenes/data-warehouse/ViewLinkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { viewLinkLogic } from 'scenes/data-warehouse/viewLinkLogic'
import { Form, Field } from 'kea-forms'
import { useActions, useValues } from 'kea'
import { DatabaseSchemaQueryResponseField } from '~/queries/schema'
import { databaseSceneLogic } from 'scenes/data-management/database/databaseSceneLogic'

export function ViewLinkModal({ tableSelectable }: { tableSelectable: boolean }): JSX.Element {
const { isFieldModalOpen } = useValues(viewLinkLogic)
Expand Down Expand Up @@ -35,9 +34,9 @@ interface ViewLinkFormProps {
}

export function ViewLinkForm({ tableSelectable }: ViewLinkFormProps): JSX.Element {
const { viewOptions, toJoinKeyOptions, selectedView, selectedTable, fromJoinKeyOptions } = useValues(viewLinkLogic)
const { selectView, toggleFieldModal, selectTable } = useActions(viewLinkLogic)
const { tableOptions } = useValues(databaseSceneLogic)
const { viewOptions, tableOptions, toJoinKeyOptions, selectedView, selectedTableName, fromJoinKeyOptions } =
useValues(viewLinkLogic)
const { selectView, toggleFieldModal, selectTableName } = useActions(viewLinkLogic)

return (
<Form logic={viewLinkLogic} formKey="viewLink" enableFormOnSubmit>
Expand All @@ -47,16 +46,15 @@ export function ViewLinkForm({ tableSelectable }: ViewLinkFormProps): JSX.Elemen
<span className="l4">Table</span>
{tableSelectable ? (
<LemonSelect
value={selectedTable}
value={selectedTableName}
fullWidth
allowClear
options={tableOptions}
onSelect={selectTable}
onSelect={selectTableName}
placeholder="Select a table"
/>
) : selectedTable ? (
selectedTable.name
) : (
''
selectedTableName ?? ''
)}
</div>
<div className="w-50">
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/scenes/data-warehouse/viewLinkLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export interface KeySelectOption {
export const viewLinkLogic = kea<viewLinkLogicType>([
path(['scenes', 'data-warehouse', 'viewLinkLogic']),
connect({
values: [dataWarehouseSavedQueriesLogic, ['savedQueries']],
values: [dataWarehouseSavedQueriesLogic, ['savedQueries'], databaseSceneLogic, ['tableOptions']],
actions: [databaseSceneLogic, ['loadDatabase']],
}),
actions({
selectView: (selectedView) => ({ selectedView }),
setView: (view) => ({ view }),
selectTable: (selectedTable) => ({ selectedTable }),
selectTableName: (selectedTableName: string) => ({ selectedTableName }),
toggleFieldModal: true,
saveViewLink: (viewLink) => ({ viewLink }),
deleteViewLink: (table, column) => ({ table, column }),
Expand All @@ -53,10 +53,10 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
setView: (_, { view }) => view,
},
],
selectedTable: [
null as DataWarehouseSceneRow | null,
selectedTableName: [
null as string | null,
{
selectTable: (_, { selectedTable }) => selectedTable,
selectTableName: (_, { selectedTableName }) => selectedTableName,
},
],
isFieldModalOpen: [
Expand Down Expand Up @@ -132,6 +132,11 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
},
})),
selectors({
selectedTable: [
(s) => [s.selectedTableName, s.tableOptions],
(selectedTableName: string, tableOptions: DataWarehouseSceneRow[]) =>
tableOptions.find((row) => row.name === selectedTableName),
],
viewOptions: [
(s) => [s.savedQueries],
(savedQueries: DataWarehouseSceneRow[]) =>
Expand Down
Loading