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

update limited results without refreshing #173

Merged
merged 1 commit into from
Oct 11, 2023
Merged
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
16 changes: 10 additions & 6 deletions src/components/ResultsLimited/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const options = [
{ value: '100', label: '100' },
{ value: '-1', label: 'all' },
];
const handleChange = values => {
// window.location.href = window.location.href.split('?')[0] + '?limit=' + values.value;

history.pushState(null,"", window.location.href.split('?')[0] + '?limit=' + values.value);
};
const customStyles = {
menu: (provided, state) => ({
...provided,
Expand All @@ -29,7 +24,15 @@ const customStyles = {
/**
* Button that deploys the latest environment.
*/
const ResultsLimited = ({ limit, message, disableHandler}) => {
const ResultsLimited = ({ limit, changeLimit, message, disableHandler }) => {
const handleChange = values => {
const limitValueParsed = parseInt(values.value);
if (!Number.isNaN(limitValueParsed) && changeLimit) {
history.pushState(null, '', window.location.href.split('?')[0] + '?limit=' + values.value);
changeLimit(limitValueParsed === -1 ? null : limitValueParsed);
}
};

return (
// if the number of results = the limit, then display a message that the results are limited
// if the number of results is less than the limit, the message won't be displayed
Expand All @@ -54,6 +57,7 @@ const ResultsLimited = ({ limit, message, disableHandler}) => {
onChange={!disableHandler ? handleChange : () => {}}
options={options}
required
menuPlacement="top"
/>
}
</div>
Expand Down
33 changes: 19 additions & 14 deletions src/pages/backups.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';

import getConfig from 'next/config';
import Head from 'next/head';
Expand Down Expand Up @@ -27,23 +27,12 @@ const { publicRuntimeConfig } = getConfig();
const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_BACKUPS_LIMIT, 10);
const customMessage = publicRuntimeConfig.LAGOON_UI_BACKUPS_LIMIT_MESSAGE;

let urlResultLimit = envLimit;
if (typeof window !== 'undefined') {
let search = window.location.search;
let params = new URLSearchParams(search);
let limit = params.get('limit');
if (limit) {
if (parseInt(limit.trim(), 10)) {
urlResultLimit = parseInt(limit.trim(), 10);
}
}
}
const resultLimit = urlResultLimit === -1 ? null : urlResultLimit;

/**
* Displays the backups page, given the name of an openshift project.
*/
export const PageBackups = ({ router }) => {
const [resultLimit, setResultLimit] = useState(null);

const { continueTour } = useTourContext();
const { data, error, loading, subscribeToMore } = useQuery(EnvironmentWithBackupsQuery, {
variables: {
Expand All @@ -52,6 +41,21 @@ export const PageBackups = ({ router }) => {
},
});

useEffect(() => {
let urlResultLimit = envLimit;
if (typeof window !== 'undefined') {
let search = window.location.search;
let params = new URLSearchParams(search);
let limit = params.get('limit');
if (limit) {
if (parseInt(limit.trim(), 10)) {
urlResultLimit = parseInt(limit.trim(), 10);
}
}
}
setResultLimit(urlResultLimit === -1 ? null : urlResultLimit);
}, []);

useEffect(() => {
if (!loading && data?.environment?.backups?.length) {
continueTour();
Expand Down Expand Up @@ -181,6 +185,7 @@ export const PageBackups = ({ router }) => {
<Backups backups={environment.backups} />
<ResultsLimited
limit={resultLimit}
changeLimit={setResultLimit}
results={environment.backups.length}
message={(!customMessage && '') || (customMessage && customMessage.replace(/['"]+/g, ''))}
/>
Expand Down
37 changes: 22 additions & 15 deletions src/pages/deployments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import Skeleton from 'react-loading-skeleton';

import getConfig from 'next/config';
Expand Down Expand Up @@ -28,32 +28,38 @@ const { publicRuntimeConfig } = getConfig();
const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_DEPLOYMENTS_LIMIT, 10);
const customMessage = publicRuntimeConfig.LAGOON_UI_DEPLOYMENTS_LIMIT_MESSAGE;

let urlResultLimit = envLimit;
if (typeof window !== 'undefined') {
let search = window.location.search;
let params = new URLSearchParams(search);
let limit = params.get('limit');
if (limit) {
if (parseInt(limit.trim(), 10)) {
urlResultLimit = parseInt(limit.trim(), 10);
}
}
}
const resultLimit = urlResultLimit === -1 ? null : urlResultLimit;

/**
* Displays the deployments page, given the openshift project name.
*/
export const PageDeployments = ({ router }) => {
const { continueTour } = useTourContext();

const [resultLimit, setResultLimit] = useState(null);

const { data, error, loading, subscribeToMore, refetch } = useQuery(EnvironmentWithDeploymentsQuery, {
variables: {
openshiftProjectName: router.query.openshiftProjectName,
limit: resultLimit,
},
});

const handleRefetch = async () => await refetch({ openshiftProjectName: router.query.openshiftProjectName, limit: resultLimit, });
const handleRefetch = async () =>
await refetch({ openshiftProjectName: router.query.openshiftProjectName, limit: resultLimit });

useEffect(() => {
let urlResultLimit = envLimit;
if (typeof window !== 'undefined') {
let search = window.location.search;
let params = new URLSearchParams(search);
let limit = params.get('limit');
if (limit) {
if (parseInt(limit.trim(), 10)) {
urlResultLimit = parseInt(limit.trim(), 10);
}
}
}
setResultLimit(urlResultLimit === -1 ? null : urlResultLimit);
}, []);

useEffect(() => {
if (!loading && data?.environment) {
Expand Down Expand Up @@ -170,6 +176,7 @@ export const PageDeployments = ({ router }) => {
/>
<ResultsLimited
limit={resultLimit}
changeLimit={setResultLimit}
results={environment.deployments.length}
message={(!customMessage && '') || (customMessage && customMessage.replace(/['"]+/g, ''))}
/>
Expand Down
79 changes: 41 additions & 38 deletions src/pages/tasks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import Skeleton from 'react-loading-skeleton';

import getConfig from 'next/config';
Expand Down Expand Up @@ -28,25 +28,12 @@ const { publicRuntimeConfig } = getConfig();
const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_TASKS_LIMIT, 10);
const customMessage = publicRuntimeConfig.AGOON_UI_TASKS_LIMIT_MESSAGE;

let urlResultLimit = envLimit;
if (typeof window !== 'undefined') {
let search = window.location.search;
let params = new URLSearchParams(search);
let limit = params.get('limit');
if (limit) {
if (parseInt(limit.trim(), 10)) {
urlResultLimit = parseInt(limit.trim(), 10);
}
if (limit == 'all') {
urlResultLimit = -1;
}
}
}
const resultLimit = urlResultLimit === -1 ? null : urlResultLimit;
/**
* Displays the tasks page, given the openshift project name.
*/
export const PageTasks = ({ router, renderAddTasks }) => {
const [resultLimit, setResultLimit] = useState(null);

const { continueTour } = useTourContext();
const { data, error, loading, subscribeToMore, refetch } = useQuery(EnvironmentWithTasksQuery, {
variables: {
Expand All @@ -55,7 +42,26 @@ export const PageTasks = ({ router, renderAddTasks }) => {
},
});

const handleRefetch = async () => await refetch({ openshiftProjectName: router.query.openshiftProjectName, limit: resultLimit, });
const handleRefetch = async () =>
await refetch({ openshiftProjectName: router.query.openshiftProjectName, limit: resultLimit });

useEffect(() => {
let urlResultLimit = envLimit;
if (typeof window !== 'undefined') {
let search = window.location.search;
let params = new URLSearchParams(search);
let limit = params.get('limit');
if (limit) {
if (parseInt(limit.trim(), 10)) {
urlResultLimit = parseInt(limit.trim(), 10);
}
if (limit == 'all') {
urlResultLimit = -1;
}
}
}
setResultLimit(urlResultLimit === -1 ? null : urlResultLimit);
}, []);

useEffect(() => {
if (!loading && data?.environment?.tasks.length) {
Expand All @@ -76,27 +82,23 @@ export const PageTasks = ({ router, renderAddTasks }) => {
</Head>

<MainLayout>
<Breadcrumbs>
<ProjectBreadcrumb projectSlug={projectSlug} />
<EnvironmentBreadcrumb environmentSlug={openshiftProjectName} projectSlug={projectSlug} />
</Breadcrumbs>
<TasksWrapper>
<NavTabsSkeleton
activeTab="tasks"
projectName={projectSlug}
openshiftProjectName={openshiftProjectName}
<Breadcrumbs>
<ProjectBreadcrumb projectSlug={projectSlug} />
<EnvironmentBreadcrumb environmentSlug={openshiftProjectName} projectSlug={projectSlug} />
</Breadcrumbs>
<TasksWrapper>
<NavTabsSkeleton activeTab="tasks" projectName={projectSlug} openshiftProjectName={openshiftProjectName} />

<div className="content">
<Skeleton height={'60px'} />
<TasksSkeleton />

<ResultsLimited
limit={resultLimit}
message={(!customMessage && '') || (customMessage && customMessage.replace(/['"]+/g, ''))}
/>

<div className="content">
<Skeleton height={'60px'} />
<TasksSkeleton />

<ResultsLimited
limit={resultLimit}
message={(!customMessage && '') || (customMessage && customMessage.replace(/['"]+/g, ''))}
/>
</div>
</TasksWrapper>
</div>
</TasksWrapper>
</MainLayout>
</>
);
Expand All @@ -117,7 +119,7 @@ export const PageTasks = ({ router, renderAddTasks }) => {
/>
);
}

subscribeToMore({
document: TasksSubscription,
variables: { environment: environment.id },
Expand Down Expand Up @@ -177,6 +179,7 @@ export const PageTasks = ({ router, renderAddTasks }) => {
/>
<ResultsLimited
limit={resultLimit}
changeLimit={setResultLimit}
results={environment.tasks.length}
message={(!customMessage && '') || (customMessage && customMessage.replace(/['"]+/g, ''))}
/>
Expand Down