Skip to content
Snippets Groups Projects
Commit f7824b65 authored by Atte Keinänen's avatar Atte Keinänen Committed by GitHub
Browse files

Merge pull request #5557 from metabase/issue-5535

Omit schema name in FK target field list if DB has no schemas / all target fields are from same schema
parents 854345ce 0055a018
Branches
Tags
No related merge requests found
......@@ -171,6 +171,10 @@ export class SpecialTypeAndTargetPicker extends Component {
const showFKTargetSelect = isFK(field.special_type);
// If all FK target fields are in the same schema (like `PUBLIC` for sample dataset)
// or if there are no schemas at all, omit the schema name
const includeSchemaName = _.uniq(idfields.map((idField) => idField.table.schema)).length > 1
return (
<div>
<Select
......@@ -188,7 +192,11 @@ export class SpecialTypeAndTargetPicker extends Component {
placeholder="Select a target"
value={field.fk_target_field_id && _.find(idfields, (idField) => idField.id === field.fk_target_field_id)}
options={idfields}
optionNameFn={(idField) => idField.table.schema && idField.table.schema !== "public" ? titleize(humanize(idField.table.schema)) + "." + idField.displayName : idField.displayName}
optionNameFn={
(idField) => includeSchemaName
? titleize(humanize(idField.table.schema)) + "." + idField.displayName
: idField.displayName
}
onChange={this.onTargetChange}
/> }
</div>
......
......@@ -153,7 +153,7 @@ describe("FieldApp", () => {
it("shows the correct default special type for a foreign key", async () => {
const { fieldApp } = await initFieldApp({ fieldId: PRODUCT_ID_FK_ID });
const picker = fieldApp.find(SpecialTypeAndTargetPicker).text()
expect(picker).toMatch(/Foreign KeyPublic.Products → ID/);
expect(picker).toMatch(/Foreign KeyProducts → ID/);
})
it("lets you change the type to 'No special type'", async () => {
......@@ -208,7 +208,7 @@ describe("FieldApp", () => {
productIdField.simulate('click')
await store.waitForActions([UPDATE_FIELD])
expect(picker.text()).toMatch(/Foreign KeyPublic.Products → ID/);
expect(picker.text()).toMatch(/Foreign KeyProducts → ID/);
})
afterAll(async () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment