forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "chore: Removes Saved Query old code (apache#25007)"
This reverts commit b428b06.
- Loading branch information
1 parent
b7ce148
commit da71322
Showing
6 changed files
with
278 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import ReactDom from 'react-dom'; | ||
import Form from 'react-jsonschema-form'; | ||
import { interpolate } from 'src/showSavedQuery/utils'; | ||
import { styled } from '@superset-ui/core'; | ||
import getBootstrapData from 'src/utils/getBootstrapData'; | ||
|
||
const scheduleInfoContainer = document.getElementById('schedule-info'); | ||
const bootstrapData = getBootstrapData(); | ||
const config = bootstrapData.common.conf.SCHEDULED_QUERIES; | ||
const { query } = bootstrapData.common; | ||
const scheduleInfo = query.extra_json.schedule_info; | ||
const linkback = config.linkback ? interpolate(config.linkback, query) : null; | ||
|
||
const StyledSavedQueryContainer = styled.div` | ||
.btn-add { | ||
display: none; | ||
} | ||
`; | ||
|
||
const StyledLinkBack = styled.div` | ||
${({ theme }) => ` | ||
padding-top: 0; | ||
padding-right: ${theme.gridUnit * 2 + 2}px; | ||
padding-bottom: ${theme.gridUnit * 5}px; | ||
padding-left: ${theme.gridUnit / 2}px; | ||
`} | ||
`; | ||
|
||
if (scheduleInfo && config) { | ||
// hide instructions when showing schedule info | ||
config.JSONSCHEMA.description = ''; | ||
|
||
ReactDom.render( | ||
<StyledSavedQueryContainer> | ||
<Form | ||
schema={config.JSONSCHEMA} | ||
uiSchema={config.UISCHEMA} | ||
formData={scheduleInfo} | ||
disabled | ||
> | ||
<br /> | ||
</Form> | ||
{linkback && ( | ||
<StyledLinkBack className="linkback"> | ||
<a href={linkback}> | ||
<i className="fa fa-link" /> | ||
Pipeline status | ||
</a> | ||
</StyledLinkBack> | ||
)} | ||
</StyledSavedQueryContainer>, | ||
scheduleInfoContainer, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export function getNestedValue(obj, id, separator = '.') { | ||
/* | ||
* Given a nested object and an id, return the nested value. | ||
* | ||
* > getNestedValue({a:{b:1}}, 'a.b') | ||
* < 1 | ||
*/ | ||
const index = id.indexOf(separator); | ||
if (index === -1) { | ||
return obj[id]; | ||
} | ||
const name = id.slice(0, index); | ||
const rest = id.slice(index + separator.length); | ||
return getNestedValue(obj[name], rest, separator); | ||
} | ||
|
||
export function interpolate(str, obj) { | ||
/* | ||
* Programmatic template string for interpolation. | ||
* | ||
* > interpolate('foo ${a.b}', {a:{b:1}}) | ||
* < "foo 1" | ||
*/ | ||
return str.replace(/\$\{(.+?)\}/g, (match, id) => getNestedValue(obj, id)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { getNestedValue, interpolate } from 'src/showSavedQuery/utils'; | ||
|
||
describe('getNestedValue', () => { | ||
it('is a function', () => { | ||
expect(typeof getNestedValue).toBe('function'); | ||
}); | ||
|
||
it('works with simple ids', () => { | ||
const obj = { a: '1' }; | ||
const id = 'a'; | ||
expect(getNestedValue(obj, id)).toEqual('1'); | ||
}); | ||
|
||
it('works with complex ids', () => { | ||
const obj = { a: { b: '1' } }; | ||
const id = 'a.b'; | ||
expect(getNestedValue(obj, id)).toEqual('1'); | ||
}); | ||
|
||
it('works with other separators', () => { | ||
const obj = { a: { b: { c: '1' } } }; | ||
const id = 'a__b__c'; | ||
const separator = '__'; | ||
expect(getNestedValue(obj, id, separator)).toEqual('1'); | ||
}); | ||
}); | ||
|
||
describe('interpolate', () => { | ||
it('is a function', () => { | ||
expect(typeof interpolate).toBe('function'); | ||
}); | ||
|
||
it('works with simple ids', () => { | ||
const obj = { a: '1' }; | ||
// eslint-disable-next-line no-template-curly-in-string | ||
const str = 'value: ${a}'; | ||
expect(interpolate(str, obj)).toEqual('value: 1'); | ||
}); | ||
|
||
it('works with complex ids', () => { | ||
const obj = { a: { b: '1' } }; | ||
// eslint-disable-next-line no-template-curly-in-string | ||
const str = 'value: ${a.b}'; | ||
expect(interpolate(str, obj)).toEqual('value: 1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters