Skip to content

Commit

Permalink
Update store to set status on click to pending.
Browse files Browse the repository at this point in the history
  • Loading branch information
srpiatt committed Nov 29, 2023
1 parent f7dfa16 commit 42e684e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,27 @@ const ScEnvironmentsStore = BaseStore.named('ScEnvironmentsStore')
},

async terminateScEnvironment(id) {
const env = self.getScEnvironment(id);
if (!env) return;
env.setStatus('TERMINATING');
if (enableEgressStore) {
await deleteEgressStore(id);
}
await deleteScEnvironment(id);
const env = self.getScEnvironment(id);
if (!env) return;
env.setStatus('TERMINATING');
},

async startScEnvironment(id) {
await startScEnvironment(id);
const env = self.getScEnvironment(id);
if (!env) return;
env.setStatus('STARTING');
await startScEnvironment(id);
},

async stopScEnvironment(id) {
await stopScEnvironment(id);
const env = self.getScEnvironment(id);
if (!env) return;
env.setStatus('STOPPING');
await stopScEnvironment(id);
},

getScEnvironmentStore(envId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

import React, { useState } from 'react';
import React from 'react';
import { Button, Modal } from 'semantic-ui-react';

// expected props
Expand All @@ -22,27 +22,22 @@ import { Button, Modal } from 'semantic-ui-react';
// - enabled, as { [action]: boolean }
// - onAction(action, id)
export default function ActionButtons({ id, pending = false, terminationLocked, can, onAction }) {
const [loading, setLoading] = useState(pending);

function handleAction(action, value) {
return async () => {
setLoading(true);
await onAction(action, value);
setLoading(false);
};
return () => onAction(action, value);
}

return (
<Button.Group size="mini" className="m1">
<Button icon="eye" onClick={handleAction('view', `/workspaces/id/${id}`)} />
{can.start && <Button icon="play circle" color="green" loading={loading} onClick={handleAction('start', id)} />}
{can.stop && <Button icon="stop circle" color="orange" loading={loading} onClick={handleAction('stop', id)} />}
{can.start && <Button icon="play circle" color="green" loading={pending} onClick={handleAction('start', id)} />}
{can.stop && <Button icon="stop circle" color="orange" loading={pending} onClick={handleAction('stop', id)} />}
{can.terminate &&
(terminationLocked ? (
<Button disabled icon="trash" color="red" loading={loading} />
<Button disabled icon="trash" color="red" loading={pending} />
) : (
<Modal
trigger={<Button icon="trash" color="red" loading={loading} />}
trigger={<Button icon="trash" color="red" loading={pending} />}
header="Are you sure?"
content="This action can not be reverted."
actions={[
Expand All @@ -61,7 +56,7 @@ export default function ActionButtons({ id, pending = false, terminationLocked,
<Button
icon={terminationLocked ? 'unlock' : 'lock'}
color="teal"
loading={loading}
loading={pending}
onClick={handleAction('toggleLock', id)}
/>
)}
Expand Down

0 comments on commit 42e684e

Please sign in to comment.