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/preserve page in url #4912

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion frontend/common/code-help/create-user/create-user-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = (
) => `use Flagsmith\\Flagsmith;

$flagsmith = new Flagsmith('${envId}'${
Constants.isCustomFlagsmithUrl() && `,\n '${Constants.getFlagsmithSDKUrl()}'\n`
Constants.isCustomFlagsmithUrl() &&
`,\n '${Constants.getFlagsmithSDKUrl()}'\n`
});

// Identify the user
Expand Down
4 changes: 3 additions & 1 deletion frontend/common/code-help/init/init-dotnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module.exports = (
static FlagsmithClient _flagsmithClient;

_flagsmithClient = new("${envId}"${
Constants.isCustomFlagsmithUrl() ? `, apiUrl: "${Constants.getFlagsmithSDKUrl()}"` : ''
Constants.isCustomFlagsmithUrl()
? `, apiUrl: "${Constants.getFlagsmithSDKUrl()}"`
: ''
});

var flags = await _flagsmithClient.GetEnvironmentFlags(); # This method triggers a network request
Expand Down
6 changes: 5 additions & 1 deletion frontend/common/code-help/init/init-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module.exports = (
) => `import ${LIB_NAME} from "${NPM_CLIENT}"; // Add this line if you're using ${LIB_NAME} via npm

${LIB_NAME}.init({
environmentID: "${envId}",${Constants.isCustomFlagsmithUrl() ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : ''}
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl()
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
onChange: (oldFlags, params) => { // Occurs whenever flags are changed
// Determines if the update came from the server or local cached storage
const { isFromServer } = params;
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Constants from 'common/constants'

module.exports = (
envId,
{ FEATURE_NAME, TRAIT_NAME, LIB_NAME, NPM_NODE_CLIENT, USER_ID },
{ FEATURE_NAME, LIB_NAME, NPM_NODE_CLIENT, TRAIT_NAME, USER_ID },
userId,
) => `import Flagsmith from "${NPM_NODE_CLIENT}"; // Add this line if you're using ${LIB_NAME} via npm

Expand Down
3 changes: 2 additions & 1 deletion frontend/common/code-help/traits/traits-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Constants from 'common/constants'
module.exports = (envId, { TRAIT_NAME }, userId) => `use Flagsmith\\Flagsmith;

$flagsmith = new Flagsmith('${envId}'${
Constants.isCustomFlagsmithUrl() && `,\n '${Constants.getFlagsmithSDKUrl()}'\n`
Constants.isCustomFlagsmithUrl() &&
`,\n '${Constants.getFlagsmithSDKUrl()}'\n`
});

$traits = (object) [ '${TRAIT_NAME}' => 42 ];
Expand Down
4 changes: 2 additions & 2 deletions frontend/common/providers/Permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useGetPermissionQuery } from 'common/services/usePermission'
import { PermissionLevel } from 'common/types/requests'
import AccountStore from 'common/stores/account-store'
import intersection from 'lodash/intersection'
import { add } from 'ionicons/icons';
import { cloneDeep } from 'lodash'; // we need this to make JSX compile
import { add } from 'ionicons/icons'
import { cloneDeep } from 'lodash' // we need this to make JSX compile

type PermissionType = {
id: any
Expand Down
5 changes: 3 additions & 2 deletions frontend/common/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export const baseApiOptions = (queryArgs?: Partial<FetchBaseQueryArgs>) => {
| 'extractRehydrationInfo'
> = {
baseQuery: fetchBaseQuery({
credentials: Project.cookieAuthEnabled ? 'include' : 'omit', // 'include' for cookies, 'omit' if not
// 'include' for cookies, 'omit' if not
baseUrl: Project.api,
credentials: Project.cookieAuthEnabled ? 'include' : 'omit',
prepareHeaders: async (headers, { endpoint, getState }) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const state = getState() as StoreStateType
Expand All @@ -33,7 +34,7 @@ export const baseApiOptions = (queryArgs?: Partial<FetchBaseQueryArgs>) => {
if (token && !Project.cookieAuthEnabled) {
headers.set('Authorization', `Token ${token}`)
}
} catch (e) { }
} catch (e) {}
}

return headers
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/stores/account-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dataRelay from 'data-relay'
import { sortBy } from 'lodash'
import Project from 'common/project'
import { getStore } from 'common/store'
import { service } from "common/service";
import { service } from 'common/service'

const controller = {
acceptInvite: (id) => {
Expand Down
34 changes: 18 additions & 16 deletions frontend/common/stores/feature-list-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
} from 'common/services/useProjectFlag'
import OrganisationStore from './organisation-store'
import {
ChangeRequest,
Environment,
FeatureState,
PagedResponse,
ProjectFlag, TypedFeatureState,
} from 'common/types/responses';
ChangeRequest,
Environment,
FeatureState,
PagedResponse,
ProjectFlag,
TypedFeatureState,
} from 'common/types/responses'
import Utils from 'common/utils/utils'
import Actions from 'common/dispatcher/action-constants'
import Project from 'common/project'
Expand Down Expand Up @@ -472,16 +473,17 @@ const controller = {
API.trackEvent(Constants.events.EDIT_FEATURE)
const env: Environment = ProjectStore.getEnvironment(environmentId) as any
// Detect differences between change request and existing feature states
const res: { data: PagedResponse<TypedFeatureState> } = await getFeatureStates(
getStore(),
{
environment: environmentFlag.environment,
feature: projectFlag.id,
},
{
forceRefetch: true,
},
)
const res: { data: PagedResponse<TypedFeatureState> } =
await getFeatureStates(
getStore(),
{
environment: environmentFlag.environment,
feature: projectFlag.id,
},
{
forceRefetch: true,
},
)
const segmentResult = await getSegments(getStore(), {
include_feature_specific: true,
page_size: 1000,
Expand Down
3 changes: 2 additions & 1 deletion frontend/env/project_prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ module.exports = global.Project = {
flagsmithClientEdgeAPI: 'https://edge.api.flagsmith.com/api/v1/',

hubspot: '//js-eu1.hs-scripts.com/143451822.js',

linkedinConversionId: 16798338,
// This is used for Sentry tracking
maintenance: false,
linkedinConversionId: 16798338,
plans: {
scaleUp: { annual: 'scale-up-12-months-v2', monthly: 'scale-up-v2' },
startup: { annual: 'start-up-12-months-v2', monthly: 'startup-v2' },
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ const App = class extends Component {
<NavSubLink
icon={<SettingsIcon />}
id='org-settings-link'
data-test='org-settings-link'
data-test='org-settings-link'
to={`/organisation/${
AccountStore.getOrganisation().id
}/settings`}
Expand Down
18 changes: 13 additions & 5 deletions frontend/web/components/AuditLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type AuditLogType = {
projectId: string
pageSize: number
onSearchChange?: (search: string) => void
onPageChange?: (page: number) => void
searchPanel?: ReactNode
onErrorChange?: (err: boolean) => void
match: {
Expand All @@ -33,11 +34,15 @@ type AuditLogType = {

const widths = [210, 310, 150]
const AuditLog: FC<AuditLogType> = (props) => {
const [page, setPage] = useState(1)
const [page, setPage] = useState(Utils.fromParam().page ?? 1)
const { search, searchInput, setSearchInput } = useSearchThrottle(
Utils.fromParam().search,
() => {
setPage(1)
if (searchInput !== search) {
return setPage(1)
}

setPage(Utils.fromParam().page)
},
)
const { data: subscriptionMeta } = useGetSubscriptionMetadataQuery({
Expand All @@ -58,6 +63,11 @@ const AuditLog: FC<AuditLogType> = (props) => {
//eslint-disable-next-line
}, [search])

useEffect(() => {
props.onPageChange?.(page)
//eslint-disable-next-line
}, [page])

const hasHadResults = useRef(false)

const {
Expand Down Expand Up @@ -163,9 +173,7 @@ const AuditLog: FC<AuditLogType> = (props) => {
<div>
{author?.first_name} {author?.last_name}
</div>
<div className="list-item-subtitle">
{author?.email}
</div>
<div className='list-item-subtitle'>{author?.email}</div>
</div>
{environment?.name ? (
<Link
Expand Down
8 changes: 4 additions & 4 deletions frontend/web/components/BreadcrumbSeparator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ const BreadcrumbSeparator: FC<BreadcrumbSeparatorType> = ({
}, [])

useEffect(() => {
if(!open) {
if(projectSearch) {
if (!open) {
if (projectSearch) {
setProjectSearch('')
}
if(organisationSearch) {
if (organisationSearch) {
setOrganisationSearch('')
}
}
}, [open]);
}, [open])

const { data: projects } = useGetProjectsQuery(
{
Expand Down
88 changes: 45 additions & 43 deletions frontend/web/components/EditIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Identity } from 'common/types/responses'
import { useUpdateIdentityMutation } from 'common/services/useIdentity'
import Button from './base/forms/Button'
import ErrorMessage from './ErrorMessage'
import classNames from 'classnames';
import classNames from 'classnames'

type EditIdentityType = {
data: Identity
Expand All @@ -24,9 +24,9 @@ const EditIdentity: FC<EditIdentityType> = ({ data, environmentId }) => {
const handleBlur = () => {
if (aliasRef.current) {
const updatedAlias = (aliasRef.current.textContent || '')
.replace(/\n/g, ' ')
.trim()
.toLowerCase()
.replace(/\n/g, ' ')
.trim()
.toLowerCase()

aliasRef.current.textContent = alias
setAlias(updatedAlias)
Expand All @@ -45,27 +45,26 @@ const EditIdentity: FC<EditIdentityType> = ({ data, environmentId }) => {

const handleFocus = () => {
if (!alias) {
aliasRef.current.textContent = ''; // Clear the content
aliasRef.current.textContent = '' // Clear the content
}

// Ensure that aliasRef.current has at least one child node (a text node)
if (aliasRef.current && aliasRef.current.childNodes.length === 0) {
aliasRef.current.appendChild(document.createTextNode(''));
aliasRef.current.appendChild(document.createTextNode(''))
}

if (aliasRef.current) {
const selection = window.getSelection();
const range = document.createRange();
const selection = window.getSelection()
const range = document.createRange()

const textLength = aliasRef.current.textContent?.length || 0;
range.setStart(aliasRef.current.childNodes[0], textLength);
range.collapse(true);
const textLength = aliasRef.current.textContent?.length || 0
range.setStart(aliasRef.current.childNodes[0], textLength)
range.collapse(true)

selection?.removeAllRanges();
selection?.addRange(range);
selection?.removeAllRanges()
selection?.addRange(range)
}
};

}

const handleKeyDown = (e: React.KeyboardEvent<HTMLSpanElement>) => {
if (e.key === 'Enter') {
Expand All @@ -85,7 +84,10 @@ const EditIdentity: FC<EditIdentityType> = ({ data, environmentId }) => {

// Restore cursor position
const newRange = document.createRange()
newRange.setStart(aliasRef.current.childNodes[0], Math.min(cursorPosition, lowerCaseText.length))
newRange.setStart(
aliasRef.current.childNodes[0],
Math.min(cursorPosition, lowerCaseText.length),
)
newRange.collapse(true)

selection?.removeAllRanges()
Expand All @@ -94,33 +96,33 @@ const EditIdentity: FC<EditIdentityType> = ({ data, environmentId }) => {
}

return (
<>
<span
ref={aliasRef}
className={classNames('fw-normal',{'text-muted':!alias})}
contentEditable={true}
suppressContentEditableWarning={true}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
onInput={handleInput}
role='textbox'
aria-label='Alias'
>
{alias || 'None'}
</span>
<Button
disabled={!data}
iconSize={18}
theme='text'
className='ms-2 text-primary'
iconRightColour='primary'
iconRight={'edit'}
onClick={handleFocus}
>
Edit
</Button>
<ErrorMessage>{error}</ErrorMessage>
</>
<>
<span
ref={aliasRef}
className={classNames('fw-normal', { 'text-muted': !alias })}
contentEditable={true}
suppressContentEditableWarning={true}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
onInput={handleInput}
role='textbox'
aria-label='Alias'
>
{alias || 'None'}
</span>
<Button
disabled={!data}
iconSize={18}
theme='text'
className='ms-2 text-primary'
iconRightColour='primary'
iconRight={'edit'}
onClick={handleFocus}
>
Edit
</Button>
<ErrorMessage>{error}</ErrorMessage>
</>
)
}

Expand Down
Loading
Loading