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

feat(44211759): filters move from 3.0 #193

Open
wants to merge 4 commits into
base: 4.1.1-dodo
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// DODO created 44211759
export * from './dttmToMoment';
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -69,6 +52,7 @@ export default function buildQueryObject<T extends QueryFormData>(
adhoc_filters: appendAdhocFilters = [],
filters: appendFilters = [],
custom_form_data = {},
time_range_end_type, // DODO added 44211759
...overrides
} = extra_form_data || {};

Expand Down Expand Up @@ -105,6 +89,7 @@ export default function buildQueryObject<T extends QueryFormData>(
// 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,
Expand Down
20 changes: 2 additions & 18 deletions superset-frontend/packages/superset-ui-core/src/query/constants.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -78,7 +67,7 @@ export type Filter = {
chartsInScope?: number[];
type: typeof NativeFilterType.NativeFilter;
description: string;
};
} & FilterDodoExtended;

export type AppliedFilter = {
values: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -130,7 +113,7 @@ export type ExtraFormDataOverrideRegular = Partial<
Pick<SqlaFormData, 'granularity_sqla'>
> &
Partial<Pick<SqlaFormData, 'granularity'>> &
Partial<Pick<BaseFormData, 'time_range'>> &
Partial<Pick<BaseFormData, 'time_range' | 'time_range_end_type'>> & // DODO changed 44211759
Partial<Pick<QueryObject, 'time_column' | 'time_grain'>>;

/** These parameters override those already present in the form data/query object */
Expand Down
31 changes: 12 additions & 19 deletions superset-frontend/packages/superset-ui-core/src/query/types/Time.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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 = (
Expand All @@ -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,
},
Expand Down
Loading