diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 3130369143409..3b8bf0a561195 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -64234,6 +64234,7 @@ "jed": "^1.1.1", "lodash": "^4.17.11", "math-expression-evaluator": "^1.3.8", + "moment": "^2.30.1", "pretty-ms": "^7.0.0", "react-error-boundary": "^1.2.5", "react-markdown": "^8.0.7", @@ -76373,6 +76374,7 @@ "jest-mock-console": "^1.0.0", "lodash": "^4.17.11", "math-expression-evaluator": "^1.3.8", + "moment": "^2.30.1", "pretty-ms": "^7.0.0", "react-error-boundary": "^1.2.5", "react-markdown": "^8.0.7", diff --git a/superset-frontend/packages/superset-ui-core/package.json b/superset-frontend/packages/superset-ui-core/package.json index 7f9144cda064e..dc6bb17558df7 100644 --- a/superset-frontend/packages/superset-ui-core/package.json +++ b/superset-frontend/packages/superset-ui-core/package.json @@ -51,6 +51,7 @@ "jed": "^1.1.1", "lodash": "^4.17.11", "math-expression-evaluator": "^1.3.8", + "moment": "^2.30.1", "pretty-ms": "^7.0.0", "react-error-boundary": "^1.2.5", "react-markdown": "^8.0.7", diff --git a/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/constants.ts b/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/constants.ts new file mode 100644 index 0000000000000..f938f2f0f3e1f --- /dev/null +++ b/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/constants.ts @@ -0,0 +1,3 @@ +// DODO created 44211759 +export const MOMENT_FORMAT = 'YYYY-MM-DD[T]HH:mm:ss'; +export const MOMENT_FORMAT_UI_DODO = 'DD-MM-YYYY HH:mm:ss'; diff --git a/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/utils/dttmToMoment.ts b/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/utils/dttmToMoment.ts new file mode 100644 index 0000000000000..e014822022ee2 --- /dev/null +++ b/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/utils/dttmToMoment.ts @@ -0,0 +1,12 @@ +// DODO created 44211759 +import moment, { Moment } from 'moment'; + +export const dttmToMoment = (dttm: string): Moment => { + if (dttm === 'now') { + return moment().utc().startOf('second'); + } + if (dttm === 'today') { + return moment().utc().startOf('day'); + } + return moment(dttm); +}; diff --git a/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/utils/index.ts b/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/utils/index.ts new file mode 100644 index 0000000000000..fff35ae4d4a19 --- /dev/null +++ b/superset-frontend/packages/superset-ui-core/src/DodoExtensions/time-format/utils/index.ts @@ -0,0 +1,2 @@ +// DODO created 44211759 +export * from './dttmToMoment'; diff --git a/superset-frontend/packages/superset-ui-core/src/query/buildQueryObject.ts b/superset-frontend/packages/superset-ui-core/src/query/buildQueryObject.ts index 725c2c87aa53d..0ffbc836f9b40 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/buildQueryObject.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/buildQueryObject.ts @@ -1,21 +1,4 @@ -/* - * 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. - */ +// DODO was here /* eslint-disable camelcase */ import { @@ -69,6 +52,7 @@ export default function buildQueryObject( adhoc_filters: appendAdhocFilters = [], filters: appendFilters = [], custom_form_data = {}, + time_range_end_type, // DODO added 44211759 ...overrides } = extra_form_data || {}; @@ -105,6 +89,7 @@ export default function buildQueryObject( // fallback `null` to `undefined` so they won't be sent to the backend // (JSON.stringify will ignore `undefined`.) time_range: time_range || undefined, + time_range_end_type, // DODO added 44211759 since: since || undefined, until: until || undefined, granularity: granularity || undefined, diff --git a/superset-frontend/packages/superset-ui-core/src/query/constants.ts b/superset-frontend/packages/superset-ui-core/src/query/constants.ts index 7976e87a4a281..da2fbfe459045 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/constants.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/constants.ts @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { ExtraFormDataAppend, ExtraFormDataOverrideExtras, @@ -48,6 +31,7 @@ export const EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS: Record< time_column: 'time_column', time_grain: 'time_grain', time_range: 'time_range', + time_range_end_type: 'time_range_end_type', // DODO added 44211759 }; export const EXTRA_FORM_DATA_OVERRIDE_REGULAR_KEYS = Object.keys( diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Dashboard.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Dashboard.ts index ac4b19cae55ae..165eec044619a 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/Dashboard.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/Dashboard.ts @@ -1,25 +1,11 @@ -/** - * 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. - */ +// DODO was here import { AdhocFilter, DataMask } from '@superset-ui/core'; -export interface NativeFilterColumn { +interface NativeFilterColumnDodoExtended { + id?: string; // DODO added 44211759 +} +export interface NativeFilterColumn extends NativeFilterColumnDodoExtended { name: string; displayName?: string; } @@ -54,6 +40,9 @@ export type DataMaskState = { [id: string]: DataMask }; export type DataMaskWithId = { id: string } & DataMask; export type DataMaskStateWithId = { [filterId: string]: DataMaskWithId }; +type FilterDodoExtended = { + selectTopValue?: number; // DODO added 44211759 +}; export type Filter = { cascadeParentIds: string[]; defaultDataMask: DataMask; @@ -78,7 +67,7 @@ export type Filter = { chartsInScope?: number[]; type: typeof NativeFilterType.NativeFilter; description: string; -}; +} & FilterDodoExtended; export type AppliedFilter = { values: { diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts b/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts index ea2f0d082c46f..8d56082611556 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts @@ -1,22 +1,5 @@ /* eslint-disable camelcase */ -/** - * 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. - */ +// DOD was here /** * Types for the final QueryContext sent to /api/v1/chart/data. @@ -130,7 +113,7 @@ export type ExtraFormDataOverrideRegular = Partial< Pick > & Partial> & - Partial> & + Partial> & // DODO changed 44211759 Partial>; /** These parameters override those already present in the form data/query object */ diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Time.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Time.ts index 56156166feb76..3f3ae6e4fa867 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/Time.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/Time.ts @@ -1,30 +1,23 @@ -/* - * 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. - */ +// DOOD was here import { QueryObject } from './Query'; +// DODO added start 44211759 +export enum TimeRangeEndType { + Included = 'included', + Excluded = 'excluded', +} +type TimeRangeDodoExtended = { + time_range_end_type?: TimeRangeEndType; +}; +// DODO added stop 44211759 + export type TimeRange = { /** Time range of the query [from, to] */ time_range?: string; since?: string; until?: string; -}; +} & TimeRangeDodoExtended; export type TimeColumnConfigKey = | '__time_col' diff --git a/superset-frontend/packages/superset-ui-core/src/time-comparison/customTimeRangeDecode.ts b/superset-frontend/packages/superset-ui-core/src/time-comparison/customTimeRangeDecode.ts index bb5c3d485680a..3e65f5bc9a982 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-comparison/customTimeRangeDecode.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-comparison/customTimeRangeDecode.ts @@ -1,22 +1,5 @@ -/** - * 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. - */ - +// DODO was here +import { dttmToMoment, MOMENT_FORMAT } from '..'; import { SEPARATOR } from './fetchTimeRange'; import { CustomRangeDecodeType, @@ -38,17 +21,24 @@ export const ISO8601_AND_CONSTANT = RegExp( 'i', ); const DATETIME_CONSTANT = ['now', 'today']; -const SEVEN_DAYS_AGO = new Date(); -SEVEN_DAYS_AGO.setHours(0, 0, 0, 0); +// DODO commented out 44211759 +// const SEVEN_DAYS_AGO = new Date(); +// SEVEN_DAYS_AGO.setHours(0, 0, 0, 0); const MIDNIGHT = new Date(); MIDNIGHT.setHours(0, 0, 0, 0); +// DODO added 44211759 +const TODAY = new Date(); +TODAY.setHours(0, 0, 0, 0); + const defaultCustomRange: CustomRangeType = { - sinceDatetime: SEVEN_DAYS_AGO.setDate( - SEVEN_DAYS_AGO.getDate() - 7, - ).toString(), - sinceMode: 'relative', + // sinceDatetime: SEVEN_DAYS_AGO.setDate( + // SEVEN_DAYS_AGO.getDate() - 7, + // ).toString(), + // sinceMode: 'relative', + sinceDatetime: TODAY.toString(), // DODO changed 44211759 + sinceMode: 'specific', // DODO changed 44211759 sinceGrain: 'day', sinceGrainValue: -7, untilDatetime: MIDNIGHT.toString(), @@ -89,10 +79,15 @@ export const customTimeRangeDecode = ( // relative : specific const sinceCapturedGroup = since.match(CUSTOM_RANGE_EXPRESSION); + // DODO added 44211759 + const untilStart = dttmToMoment(until) + .startOf('date') + .format(MOMENT_FORMAT); if ( sinceCapturedGroup && ISO8601_AND_CONSTANT.test(until) && - since.includes(until) + // since.includes(until) + since.includes(untilStart) // DODO changed 44211759 ) { const [dttm, grainValue, grain] = sinceCapturedGroup.slice(1); const untilMode = ( @@ -104,7 +99,8 @@ export const customTimeRangeDecode = ( sinceGrain: grain as DateTimeGrainType, sinceGrainValue: parseInt(grainValue, 10), sinceDatetime: dttm, - untilDatetime: dttm, + // untilDatetime: dttm, + untilDatetime: until, // DODO changed 44211759 sinceMode: 'relative', untilMode, }, diff --git a/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts b/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts index 61c2a2f8ad306..68e4e692df9c4 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts @@ -1,27 +1,13 @@ -/** - * 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. - */ +// DODO was here import rison from 'rison'; import { isEmpty } from 'lodash'; import { SupersetClient, getClientErrorObject, ensureIsArray, + dttmToMoment, // DODO added 44211759 + MOMENT_FORMAT_UI_DODO, // DODO added 44211759 + TimeRangeEndType, // DODO added 44211759 } from '@superset-ui/core'; export const SEPARATOR = ' : '; @@ -34,14 +20,21 @@ const formatDateEndpoint = (dttm: string, isStart?: boolean): string => export const formatTimeRange = ( timeRange: string, + timeRangeEndType: TimeRangeEndType, // DODO added 44211759 columnPlaceholder = 'col', ) => { const splitDateRange = timeRange.split(SEPARATOR); if (splitDateRange.length === 1) return timeRange; + // DODO added 44211759 + const endInclusion = + timeRangeEndType === TimeRangeEndType.Included ? '≤' : '<'; return `${formatDateEndpoint( splitDateRange[0], true, - )} ≤ ${columnPlaceholder} < ${formatDateEndpoint(splitDateRange[1])}`; + // DODO changed 44211759 + )} ≤ ${columnPlaceholder} ${endInclusion} ${formatDateEndpoint( + splitDateRange[1], + )}`; }; export const formatTimeRangeComparison = ( @@ -62,6 +55,7 @@ export const formatTimeRangeComparison = ( export const fetchTimeRange = async ( timeRange: string, + timeRangeEndType: TimeRangeEndType, // DODO added 44211759 columnPlaceholder = 'col', shifts?: string[], ) => { @@ -81,12 +75,24 @@ export const fetchTimeRange = async ( try { const response = await SupersetClient.get({ endpoint }); if (isEmpty(shifts)) { - const timeRangeString = buildTimeRangeString( - response?.json?.result[0]?.since || '', - response?.json?.result[0]?.until || '', + // DODO added start 44211759 + const since = dttmToMoment(response?.json?.result?.since || '').format( + MOMENT_FORMAT_UI_DODO, + ); + const until = dttmToMoment(response?.json?.result?.until || '').format( + MOMENT_FORMAT_UI_DODO, ); + // DODO added stop 44211759 + const timeRangeString = buildTimeRangeString(since, until); // DODO changed 44211759 + // response?.json?.result[0]?.since || '', + // response?.json?.result[0]?.until || '', + // ); return { - value: formatTimeRange(timeRangeString, columnPlaceholder), + value: formatTimeRange( + timeRangeString, + timeRangeEndType, // DODO added 44211759 + columnPlaceholder, + ), }; } const timeRanges = response?.json?.result.map((result: any) => diff --git a/superset-frontend/packages/superset-ui-core/src/time-format/index.ts b/superset-frontend/packages/superset-ui-core/src/time-format/index.ts index 5b01bbca77ba3..04d15a99f6f59 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-format/index.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-format/index.ts @@ -1,21 +1,4 @@ -/* - * 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. - */ +// DODO was here export { default as TimeFormats, LOCAL_PREFIX } from './TimeFormats'; export { default as TimeFormatter, PREVIEW_TIME } from './TimeFormatter'; @@ -51,3 +34,5 @@ export { default as normalizeTimestamp } from './utils/normalizeTimestamp'; export { default as denormalizeTimestamp } from './utils/denormalizeTimestamp'; export * from './types'; +export * from '../DodoExtensions/time-format/utils'; // DODO added 44211759 +export * from '../DodoExtensions/time-format/constants'; // DODO added 44211759 diff --git a/superset-frontend/packages/superset-ui-core/test/time-comparison/fetchTimeRange.test.ts b/superset-frontend/packages/superset-ui-core/test/time-comparison/fetchTimeRange.test.ts index df1e2bc7d9b0d..702fda403c5ec 100644 --- a/superset-frontend/packages/superset-ui-core/test/time-comparison/fetchTimeRange.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/time-comparison/fetchTimeRange.test.ts @@ -1,24 +1,8 @@ -/** - * 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. - */ +// DODO was here +// DODO changed 44211759 import fetchMock from 'fetch-mock'; -import { fetchTimeRange } from '@superset-ui/core'; +import { fetchTimeRange, TimeRangeEndType } from '@superset-ui/core'; import { buildTimeRangeString, formatTimeRange, @@ -38,21 +22,28 @@ test('generates proper time range string', () => { }); test('generates a readable time range', () => { - expect(formatTimeRange('Last 7 days')).toBe('Last 7 days'); - expect(formatTimeRange('No filter')).toBe('No filter'); - expect(formatTimeRange('Yesterday : Tomorrow')).toBe( - 'Yesterday ≤ col < Tomorrow', + expect(formatTimeRange('Last 7 days', TimeRangeEndType.Excluded)).toBe( + 'Last 7 days', ); - expect(formatTimeRange('2010-07-30T00:00:00 : 2020-07-30T00:00:00')).toBe( - '2010-07-30 ≤ col < 2020-07-30', + expect(formatTimeRange('No filter', TimeRangeEndType.Excluded)).toBe( + 'No filter', ); - expect(formatTimeRange('2010-07-30T01:00:00 : ')).toBe( - '2010-07-30T01:00:00 ≤ col < ∞', - ); - expect(formatTimeRange(' : 2020-07-30T00:00:00')).toBe( - '-∞ ≤ col < 2020-07-30', - ); - expect(formatTimeRange('')).toBe(''); + expect( + formatTimeRange('Yesterday : Tomorrow', TimeRangeEndType.Excluded), + ).toBe('Yesterday ≤ col < Tomorrow'); + expect( + formatTimeRange( + '2010-07-30T00:00:00 : 2020-07-30T00:00:00', + TimeRangeEndType.Excluded, + ), + ).toBe('2010-07-30 ≤ col < 2020-07-30'); + expect( + formatTimeRange('2010-07-30T01:00:00 : ', TimeRangeEndType.Excluded), + ).toBe('2010-07-30T01:00:00 ≤ col < ∞'); + expect( + formatTimeRange(' : 2020-07-30T00:00:00', TimeRangeEndType.Excluded), + ).toBe('-∞ ≤ col < 2020-07-30'); + expect(formatTimeRange('', TimeRangeEndType.Excluded)).toBe(''); }); test('returns a formatted time range from response', async () => { @@ -66,7 +57,11 @@ test('returns a formatted time range from response', async () => { ], }); - const timeRange = await fetchTimeRange('Last day', 'temporal_col'); + const timeRange = await fetchTimeRange( + 'Last day', + TimeRangeEndType.Excluded, + 'temporal_col', + ); expect(timeRange).toEqual({ value: '2021-04-13 ≤ temporal_col < 2021-04-14', }); @@ -77,7 +72,7 @@ test('returns a formatted time range from empty response', async () => { result: [], }); - const timeRange = await fetchTimeRange('Last day'); + const timeRange = await fetchTimeRange('Last day', TimeRangeEndType.Excluded); expect(timeRange).toEqual({ value: '-∞ ≤ col < ∞', }); @@ -87,7 +82,7 @@ test('returns a formatted error message from response', async () => { fetchMock.getOnce("glob:*/api/v1/time_range/?q='Last+day'", { throws: new Response(JSON.stringify({ message: 'Network error' })), }); - let timeRange = await fetchTimeRange('Last day'); + let timeRange = await fetchTimeRange('Last day', TimeRangeEndType.Excluded); expect(timeRange).toEqual({ error: 'Network error', }); @@ -99,7 +94,7 @@ test('returns a formatted error message from response', async () => { }, { overwriteRoutes: true }, ); - timeRange = await fetchTimeRange('Last day'); + timeRange = await fetchTimeRange('Last day', TimeRangeEndType.Excluded); expect(timeRange).toEqual({ error: 'Internal Server Error', }); @@ -113,7 +108,7 @@ test('returns a formatted error message from response', async () => { }, { overwriteRoutes: true }, ); - timeRange = await fetchTimeRange('Last day'); + timeRange = await fetchTimeRange('Last day', TimeRangeEndType.Excluded); expect(timeRange).toEqual({ error: 'Network error', }); @@ -140,9 +135,12 @@ test('fetchTimeRange with shift', async () => { }, ); - const timeRange = await fetchTimeRange('Last day', 'temporal_col', [ - 'last month', - ]); + const timeRange = await fetchTimeRange( + 'Last day', + TimeRangeEndType.Excluded, + 'temporal_col', + ['last month'], + ); expect(timeRange).toEqual({ value: [ diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx index 7107ddff1802a..764a693220ecb 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { useEffect, useMemo, useState } from 'react'; import { css, @@ -82,6 +65,7 @@ export default function PopKPI(props: PopKPIProps) { startDateOffset, shift, dashboardTimeRange, + dashboardTimeRangeEndType, // DODO added 44211759 } = props; const [comparisonRange, setComparisonRange] = useState(''); @@ -101,6 +85,7 @@ export default function PopKPI(props: PopKPIProps) { }); const promise: any = fetchTimeRange( dashboardTimeRange ?? (currentTimeRangeFilter as any).comparator, + dashboardTimeRangeEndType, // DODO added 44211759 currentTimeRangeFilter.subject, newShift || [], ); @@ -113,7 +98,13 @@ export default function PopKPI(props: PopKPIProps) { ); }); } - }, [currentTimeRangeFilter, shift, startDateOffset, dashboardTimeRange]); + }, [ + currentTimeRangeFilter, + shift, + startDateOffset, + dashboardTimeRange, + dashboardTimeRangeEndType, // DODO added 44211759 + ]); const theme = useTheme(); const flexGap = theme.gridUnit * 5; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts index fbac5f43035aa..5c25acde14bfb 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import moment from 'moment'; import { ChartProps, @@ -213,5 +196,6 @@ export default function transformProps(chartProps: ChartProps) { startDateOffset, shift: timeComparison, dashboardTimeRange: formData?.extraFormData?.time_range, + dashboardTimeRangeEndType: formData?.extraFormData?.time_range_end_type, // DODO added 44211759 }; } diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts index e0ece4d8777ad..de0cfdf7d05f6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts @@ -1,27 +1,11 @@ -/** - * 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. - */ +// DODO was here import { QueryFormData, supersetTheme, TimeseriesDataRecord, Metric, SimpleAdhocFilter, + TimeRangeEndType, // DODO added 44211759 } from '@superset-ui/core'; export interface PopKPIStylesProps { @@ -50,6 +34,9 @@ export type PopKPIQueryFormData = QueryFormData & PopKPIStylesProps & PopKPICustomizeProps; +type PopKPIPropsDodoExtended = { + dashboardTimeRangeEndType: TimeRangeEndType; // DODO added 44211759 +}; export type PopKPIProps = PopKPIStylesProps & PopKPICustomizeProps & { data: TimeseriesDataRecord[]; @@ -66,7 +53,7 @@ export type PopKPIProps = PopKPIStylesProps & startDateOffset?: string; shift: string; dashboardTimeRange?: string; - }; + } & PopKPIPropsDodoExtended; export enum ColorSchemeEnum { Green = 'Green', diff --git a/superset-frontend/src/components/Chart/chartAction.js b/superset-frontend/src/components/Chart/chartAction.js index 8a9124818424f..88cd5c37fd246 100644 --- a/superset-frontend/src/components/Chart/chartAction.js +++ b/superset-frontend/src/components/Chart/chartAction.js @@ -172,6 +172,27 @@ const v1ChartDataRequest = async ( ownState, }); + // DODO added start 44211759 + // Maybe this piece of code is no more necessary? + const timeGrainSqla = payload?.form_data?.time_grain_sqla; + payload.queries?.forEach(query => { + const timeFilter = query?.filters + ?.reverse() + .find(filter => filter.op === 'TEMPORAL_RANGE'); + if (query.time_range === undefined && timeFilter) { + // set time range to enforce jinja work + query.time_range = timeFilter.val; + } + if (query.extras?.time_grain_sqla === undefined && timeGrainSqla) { + // to enforce jinja work + query.extras = { + ...(query?.extras ?? {}), + ...{ time_grain_sqla: timeGrainSqla }, + }; + } + }); + // DODO added stop 44211759 + // The dashboard id is added to query params for tracking purposes const { slice_id: sliceId } = formData; const { dashboard_id: dashboardId } = requestParams; diff --git a/superset-frontend/src/constants.ts b/superset-frontend/src/constants.ts index b7d34ad738694..0aa1a078014a5 100644 --- a/superset-frontend/src/constants.ts +++ b/superset-frontend/src/constants.ts @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { t, DEFAULT_D3_FORMAT, @@ -201,4 +184,5 @@ export enum FilterPlugins { Time = 'filter_time', TimeColumn = 'filter_timecolumn', TimeGrain = 'filter_timegrain', + SelectById = 'filter_select_by_id', // DODO added 44211759 } diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx index 2d85f413c355a..0c3f23a1af921 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { FC, memo, @@ -117,8 +100,10 @@ const FilterValue: FC = ({ const { datasetId, column = {}, - }: Partial<{ datasetId: number; column: { name?: string } }> = target; - const { name: groupby } = column; + }: Partial<{ datasetId: number; column: { name?: string; id?: string } }> = // DODO changed 44211759 + target; + // const { name: groupby } = column; + const { name: groupby, id: groupbyid } = column; // DODO changed 44211759 const hasDataSource = !!datasetId; const [isLoading, setIsLoading] = useState(hasDataSource); const [isRefreshing, setIsRefreshing] = useState(false); @@ -149,6 +134,7 @@ const FilterValue: FC = ({ datasetId, dependencies, groupby, + groupbyid, // DODO added 44211759 adhoc_filters, time_range, dashboardId, diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx index 7e151eec42a31..b1e3ae62ef175 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here /* eslint-disable react-hooks/rules-of-hooks */ import { ColumnMeta, @@ -83,6 +66,7 @@ import { mergeExtraFormData, } from 'src/dashboard/components/nativeFilters/utils'; import { DatasetSelectLabel } from 'src/features/datasets/DatasetSelectLabel'; +import TextControl from 'src/explore/components/controls/TextControl'; // DODO added 44211759 import { ALLOW_DEPENDENCIES as TYPES_SUPPORT_DEPENDENCIES, getFiltersConfigModalTestId, @@ -111,23 +95,34 @@ const TabPane = styled(Tabs.TabPane)` padding: ${({ theme }) => theme.gridUnit * 4}px 0px; `; -const StyledContainer = styled.div` - ${({ theme }) => ` - display: flex; - flex-direction: row-reverse; - justify-content: space-between; - padding: 0px ${theme.gridUnit * 4}px; - `} -`; - -const StyledRowContainer = styled.div` - display: flex; - flex-direction: row; - justify-content: space-between; - width: 100%; +// DODO commented out 44211759 +// const StyledContainer = styled.div` +// ${({ theme }) => ` +// display: flex; +// flex-direction: row-reverse; +// justify-content: space-between; +// padding: 0px ${theme.gridUnit * 4}px; +// `} +// `; + +// DODO added 44211759 +const StyledGridContainer = styled.div` padding: 0px ${({ theme }) => theme.gridUnit * 4}px; + display: grid; + grid-template-columns: repeat(2, 1fr); + justify-content: space-between; + column-gap: 1rem; `; +// DODO commented out 44211759 +// const StyledRowContainer = styled.div` +// display: flex; +// flex-direction: row; +// justify-content: space-between; +// width: 100%; +// padding: 0px ${({ theme }) => theme.gridUnit * 4}px; +// `; + type ControlKey = keyof PluginFilterSelectCustomizeProps; const controlsOrder: ControlKey[] = [ @@ -139,7 +134,7 @@ const controlsOrder: ControlKey[] = [ ]; export const StyledFormItem = styled(FormItem)<{ expanded: boolean }>` - width: ${({ expanded }) => (expanded ? '49%' : `${FORM_ITEM_WIDTH}px`)}; + // width: ${({ expanded }) => (expanded ? '49%' : `${FORM_ITEM_WIDTH}px`)}; margin-bottom: ${({ theme }) => theme.gridUnit * 4}px; & .ant-form-item-label { @@ -319,7 +314,12 @@ export interface FiltersConfigFormProps { getDependencySuggestion: (filterId: string) => string; } -const FILTERS_WITH_ADHOC_FILTERS = ['filter_select', 'filter_range']; +// const FILTERS_WITH_ADHOC_FILTERS = ['filter_select', 'filter_range']; +const FILTERS_WITH_ADHOC_FILTERS = [ + 'filter_select', + 'filter_range', + 'filter_select_by_id', // DODO added 44211759 +]; // TODO: Rename the filter plugins and remove this mapping const FILTER_TYPE_NAME_MAPPING = { @@ -329,6 +329,7 @@ const FILTER_TYPE_NAME_MAPPING = { [t('Time column')]: t('Time column'), [t('Time grain')]: t('Time grain'), [t('Group By')]: t('Group by'), + [t('Select by id filter')]: t('Filter by ID'), // DODO added 44211759 }; /** @@ -487,6 +488,7 @@ const FiltersConfigForm = ( datasetId: formFilter?.dataset?.value, dashboardId, groupby: formFilter?.column, + groupbyid: formFilter?.columnId, // DODO added 44211759 ...formFilter, }); @@ -548,6 +550,7 @@ const FiltersConfigForm = ( const newFormData = getFormData({ datasetId, groupby: hasColumn ? formFilter?.column : undefined, + groupbyid: formFilter?.columnId, // DODO added 44211759 ...formFilter, }); newFormData.extra_form_data = dependenciesDefaultValues; @@ -811,7 +814,8 @@ const FiltersConfigForm = ( key={FilterTabs.configuration.key} forceRender > - + + {/* DODO changed 44211759 */} - {t('Filter name')}} - initialValue={filterToEdit?.name} - rules={[{ required: !isRemoved, message: t('Name is required') }]} - > - - - + {t('Filter name')}} + initialValue={filterToEdit?.name} + rules={[{ required: !isRemoved, message: t('Name is required') }]} + > + + + {formFilter?.filterType === 'filter_time' && ( {t(`Dashboard time range filters apply to temporal columns defined in @@ -883,7 +887,8 @@ const FiltersConfigForm = ( )} {hasDataset && ( - + // DODO changed 44211759 + {showDataset ? ( mainControlItems[key].element, )} - + {/* DODO added 44211759 */} + {formFilter.filterType === 'filter_select_by_id' && ( + + Select Top Value{' '} + + + } + initialValue={filterToEdit?.selectTopValue} + rules={[ + { + validator: (_, value) => { + if (!value) return Promise.resolve(); + if (!Number.isInteger(Number(value))) { + return Promise.reject( + new Error(t('Not a valid integer')), + ); + } + return Promise.resolve(); + }, + }, + ]} + > + + + )} + )} - mainControlItem?.name === 'groupby', + mainControlItem?.name === 'groupby' || + mainControlItem?.name === 'groupbyid', // DODO added 44211759 ) .forEach(mainControlItem => { + const isGroupby = mainControlItem?.name === 'groupby'; // DODO added 44211759 const initialValue = filterToEdit?.controlValues?.[mainControlItem.name] ?? mainControlItem?.config?.default; - const initColumn = filterToEdit?.targets[0]?.column?.name; + // const initColumn = filterToEdit?.targets[0]?.column?.name; + + // DODO added start 44211759 + let initColumn: string | undefined; + let formField: string; + let label: string; + + if (isGroupby) { + initColumn = filterToEdit?.targets[0]?.column?.name; + formField = 'column'; + label = `${t('Column')} EN`; + } else { + initColumn = filterToEdit?.targets[0]?.column?.id; + formField = 'columnId'; + label = t('ColumnId'); + } + // DODO added stop 44211759 const element = ( <> @@ -108,11 +109,14 @@ export default function getControlItemsMap({ - {mainControlItem.config?.label || t('Column')} + {/* {mainControlItem.config?.label || t('Column')} */} + {/* DODO changed 44211759 */} + {mainControlItem.config?.label || label} } rules={[ @@ -128,6 +132,7 @@ export default function getControlItemsMap({ form={form} filterId={filterId} datasetId={datasetId} + formField={formField} // DODO added 44211759 filterValues={column => doesColumnMatchFilterType(formFilter?.filterType || '', column) } diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx index 5e53919521483..b5187fc951dd9 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { Divider, Filter, @@ -121,6 +104,7 @@ export const ALLOW_DEPENDENCIES = [ 'filter_range', 'filter_select', 'filter_time', + 'filter_select_by_id', // DODO added 44211759 ]; const DEFAULT_EMPTY_FILTERS: string[] = []; diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/types.ts b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/types.ts index 6f40ea6542947..ce84a5f134e0f 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/types.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/types.ts @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { AdhocFilter, DataMask, @@ -23,7 +6,12 @@ import { NativeFilterScope, } from '@superset-ui/core'; -export interface NativeFiltersFormItem { +interface NativeFiltersFormItemDodoExtended { + columnId?: string; // DODO added 44211759 + selectTopValue?: string; // DODO added 44211759 +} +export interface NativeFiltersFormItem + extends NativeFiltersFormItemDodoExtended { scope: NativeFilterScope; name: string; filterType: string; diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/utils.ts b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/utils.ts index fa15d2e638849..c17c525b7f86c 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/utils.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/utils.ts @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { Divider, Filter, @@ -124,7 +107,18 @@ export const createHandleSave = } if (formInputs.dataset && formInputs.column) { target.column = { name: formInputs.column }; + // DODO added 44211759 + if (formInputs.columnId) { + target.column.id = formInputs.columnId; + } } + + // DODO added 44211759 + const selectTopValue = + formInputs.columnId && formInputs.selectTopValue + ? Number(formInputs.selectTopValue) + : undefined; + return { id, adhoc_filters: formInputs.adhoc_filters, @@ -144,6 +138,7 @@ export const createHandleSave = sortMetric: formInputs.sortMetric, type: formInputs.type, description: (formInputs.description || '').trim(), + selectTopValue, // DODO added 44211759 }; }); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/utils.ts b/superset-frontend/src/dashboard/components/nativeFilters/utils.ts index 0ba28d0a3a3f9..18677843e6374 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/utils.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/utils.ts @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { AdhocFilter, Behavior, @@ -47,6 +30,8 @@ export const getFormData = ({ datasetId, dependencies = {}, groupby, + groupbyid, // DODO added 44211759 + selectTopValue, // DODO added 44211759 defaultDataMask, controlValues, filterType, @@ -62,6 +47,7 @@ export const getFormData = ({ datasetId?: number; dependencies?: object; groupby?: string; + groupbyid?: string; // DODO added 44211759 adhoc_filters?: AdhocFilter[]; time_range?: string; }): Partial => { @@ -76,6 +62,10 @@ export const getFormData = ({ if (groupby) { otherProps.groupby = [groupby]; } + // DODO added 44211759 + if (groupbyid) { + otherProps.groupby?.push(groupbyid); + } if (sortMetric) { otherProps.sortMetric = sortMetric; } @@ -87,7 +77,8 @@ export const getFormData = ({ extra_form_data: dependencies, granularity_sqla, metrics: ['count'], - row_limit: getDefaultRowLimit(), + // row_limit: getDefaultRowLimit(), + row_limit: selectTopValue || getDefaultRowLimit(), // DODO changed 44211759 showSearch: true, defaultValue: defaultDataMask?.filterState?.value, time_range, diff --git a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx index 5df43256ad012..d0a87a6e5acb7 100644 --- a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx +++ b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; @@ -30,6 +13,7 @@ import { parseDttmToDate, SimpleAdhocFilter, t, + TimeRangeEndType, // DODO added 44211759 } from '@superset-ui/core'; import ControlHeader, { ControlHeaderProps, @@ -118,6 +102,7 @@ export const ComparisonRangeLabel = ({ if (!isEmpty(newShifts)) { return fetchTimeRange( filter.comparator, + TimeRangeEndType.Excluded, // DODO added 44211759 filter.subject, ensureIsArray(newShifts), ); diff --git a/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx b/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx index e5ef553267969..0bf08a2f96104 100644 --- a/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx +++ b/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx @@ -1,21 +1,4 @@ -/** - * 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. - */ +// DODO was here import { ReactNode, useState, useEffect, useMemo } from 'react'; import { css, @@ -26,6 +9,7 @@ import { SupersetTheme, useCSSTextTruncation, fetchTimeRange, + TimeRangeEndType, // DODO added 44211759 } from '@superset-ui/core'; import Button from 'src/components/Button'; import ControlHeader from 'src/explore/components/ControlHeader'; @@ -82,7 +66,7 @@ const ContentStyleWrapper = styled.div` .control-label { font-size: 11px; font-weight: ${theme.typography.weights.medium}; - color: ${theme.colors.grayscale.light2}; + color: ${theme.colors.grayscale.base}; // DODO changed 44211759 line-height: 16px; text-transform: uppercase; margin: 8px 0; @@ -174,6 +158,11 @@ export default function DateFilterLabel(props: DateFilterControlProps) { const [tooltipTitle, setTooltipTitle] = useState(value); const theme = useTheme(); const [labelRef, labelIsTruncated] = useCSSTextTruncation(); + // DODO added 44211759 + const timeRangeEndType = + frame === 'CustomUntilInclude' + ? TimeRangeEndType.Included + : TimeRangeEndType.Excluded; useEffect(() => { if (value === NO_TIME_RANGE) { @@ -182,13 +171,15 @@ export default function DateFilterLabel(props: DateFilterControlProps) { setValidTimeRange(true); return; } - fetchTimeRange(value).then(({ value: actualRange, error }) => { - if (error) { - setEvalResponse(error || ''); - setValidTimeRange(false); - setTooltipTitle(value || null); - } else { - /* + // DODO changed 44211759 + fetchTimeRange(value, timeRangeEndType).then( + ({ value: actualRange, error }) => { + if (error) { + setEvalResponse(error || ''); + setValidTimeRange(false); + setTooltipTitle(value || null); + } else { + /* HRT == human readable text ADR == actual datetime range +--------------+------+----------+--------+----------+-----------+ @@ -199,28 +190,29 @@ export default function DateFilterLabel(props: DateFilterControlProps) { | tooltip | ADR | ADR | HRT | HRT | ADR | +--------------+------+----------+--------+----------+-----------+ */ - if ( - guessedFrame === 'Common' || - guessedFrame === 'Calendar' || - guessedFrame === 'Current' || - guessedFrame === 'No filter' - ) { - setActualTimeRange(value); - setTooltipTitle( - getTooltipTitle(labelIsTruncated, value, actualRange), - ); - } else { - setActualTimeRange(actualRange || ''); - setTooltipTitle( - getTooltipTitle(labelIsTruncated, actualRange, value), - ); + if ( + guessedFrame === 'Common' || + guessedFrame === 'Calendar' || + guessedFrame === 'Current' || + guessedFrame === 'No filter' + ) { + setActualTimeRange(value); + setTooltipTitle( + getTooltipTitle(labelIsTruncated, value, actualRange), + ); + } else { + setActualTimeRange(actualRange || ''); + setTooltipTitle( + getTooltipTitle(labelIsTruncated, actualRange, value), + ); + } + setValidTimeRange(true); } - setValidTimeRange(true); - } - setLastFetchedTimeRange(value); - setEvalResponse(actualRange || value); - }); - }, [guessedFrame, labelIsTruncated, labelRef, value]); + setLastFetchedTimeRange(value); + setEvalResponse(actualRange || value); + }, + ); + }, [guessedFrame, labelIsTruncated, labelRef, timeRangeEndType, value]); useDebouncedEffect( () => { @@ -231,16 +223,19 @@ export default function DateFilterLabel(props: DateFilterControlProps) { return; } if (lastFetchedTimeRange !== timeRangeValue) { - fetchTimeRange(timeRangeValue).then(({ value: actualRange, error }) => { - if (error) { - setEvalResponse(error || ''); - setValidTimeRange(false); - } else { - setEvalResponse(actualRange || ''); - setValidTimeRange(true); - } - setLastFetchedTimeRange(timeRangeValue); - }); + // DODO changed 44211759 + fetchTimeRange(timeRangeValue, timeRangeEndType).then( + ({ value: actualRange, error }) => { + if (error) { + setEvalResponse(error || ''); + setValidTimeRange(false); + } else { + setEvalResponse(actualRange || ''); + setValidTimeRange(true); + } + setLastFetchedTimeRange(timeRangeValue); + }, + ); } }, SLOW_DEBOUNCE, @@ -248,7 +243,7 @@ export default function DateFilterLabel(props: DateFilterControlProps) { ); function onSave() { - onChange(timeRangeValue); + onChange(timeRangeValue, timeRangeEndType); // DODO changed 44211759 setShow(false); onClosePopover(); } @@ -310,6 +305,15 @@ export default function DateFilterLabel(props: DateFilterControlProps) { {frame === 'Custom' && ( )} + {/* DODO added 44211759 */} + {frame === 'CustomUntilInclude' && ( + + )} {frame === 'No filter' &&
}
diff --git a/superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx b/superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx index d3448d2a56f8b..d155568e7c78a 100644 --- a/superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx +++ b/superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx @@ -1,23 +1,6 @@ -/** - * 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. - */ +// DODO was here import { useSelector } from 'react-redux'; -import { t, customTimeRangeDecode } from '@superset-ui/core'; +import { t, customTimeRangeDecode, dttmToMoment } from '@superset-ui/core'; import { Moment } from 'moment'; import { isInteger } from 'lodash'; // @ts-ignore @@ -36,7 +19,7 @@ import { MOMENT_FORMAT, MIDNIGHT, customTimeRangeEncode, - dttmToMoment, + // dttmToMoment, LOCALE_MAPPING, } from 'src/explore/components/controls/DateFilterControl/utils'; import { @@ -44,9 +27,32 @@ import { FrameComponentProps, } from 'src/explore/components/controls/DateFilterControl/types'; import { ExplorePageState } from 'src/explore/types'; +import { MOMENT_FORMAT_UI_DODO } from 'src/explore/constants'; // DODO added 44211759 export function CustomFrame(props: FrameComponentProps) { + const { withTime = true, untilInclude = false } = props; // DODO added 44211759 const { customRange, matchedFlag } = customTimeRangeDecode(props.value); + + // DODO added 44211759 + if (customRange.untilMode === 'specific' && customRange.untilDatetime) { + if (untilInclude) { + customRange.untilDatetime = dttmToMoment(customRange.untilDatetime) + .endOf('date') + .format(MOMENT_FORMAT); + } else if (!untilInclude) { + customRange.untilDatetime = dttmToMoment(customRange.untilDatetime) + .startOf('date') + .format(MOMENT_FORMAT); + } + + props.onChange( + customTimeRangeEncode({ + ...customRange, + untilDatetime: customRange.untilDatetime, + }), + ); + } + if (!matchedFlag) { props.onChange(customTimeRangeEncode(customRange)); } @@ -139,7 +145,9 @@ export function CustomFrame(props: FrameComponentProps) { {sinceMode === 'specific' && ( onChange('sinceDatetime', datetime.format(MOMENT_FORMAT)) @@ -177,11 +185,25 @@ export function CustomFrame(props: FrameComponentProps) {
- {t('END (EXCLUSIVE)')}{' '} - + {/* DODO changed start 44211759 */} + {untilInclude ? ( + <> + {t('END (INCLUSIVE)')}{' '} + + + ) : ( + <> + {t('END (EXCLUSIVE)')}{' '} + + + )} + {/* DODO changed stop 44211759 */}